What's Changed
Core Improvements
- Introduced type-safe context validation with generic
AgentContext[ContextParams, AgentOutput]
- Added new tool registration system with
@tool
and@tool_plain
decorators - Implemented type validation for SwarmStream and Swarm public API
- Added explicit agent switching via
ToolResult.switch_to
method
Developer Experience
- Unified chat components with new
ChatContext
for simpler state management - Reorganized examples into basics and advanced categories
- Added new examples for structured outputs and agent teams
- Enhanced documentation with type-safe API usage examples
Breaking Changes
- Core API now requires type parameters for context and output validation
- Agent switching requires explicit
ToolResult.switch_to
calls - Chat components use unified
ChatContext
instead of separate managers - Removed experimental SwarmTeam prototype module
Migration Notes
# Before - Generic agent context
agent = Agent(id="math", instructions="You are a math assistant.")
context = AgentContext(agent=agent, messages=messages)
# After - Type-safe context
class MathParams(BaseModel):
precision: int
class MathResult(BaseModel):
result: int
explanation: str
agent = Agent[MathParams, MathResult](
id="math",
instructions="You are a math assistant.",
params_type=MathParams,
result_type=MathResult,
)
context = AgentContext(
agent=agent,
messages=messages,
params=MathParams(precision=2),
)
# Before - Implicit agent switching
def switch_to_expert(context: AgentContext) -> Agent:
return Agent(id="expert", instructions="You are an expert.")
# After - Explicit agent switching
@tool_plain
def switch_to_expert(domain: str) -> ToolResult:
expert = Agent[ExpertParams, None](
id=f"{domain}-expert",
instructions=f"You are a {domain} expert.",
params_type=ExpertParams,
)
return ToolResult.switch_to(
content=f"Switching to {domain} expert",
agent=expert,
params=ExpertParams(domain=domain),
)
Removed
- Experimental SwarmTeam prototype module
- Generic message types in favor of type-safe alternatives
- Swarm team types and exceptions
Contributors
Thanks to:
Full Changelog: 0.5.1...0.6.0