Typed Handoff • AI Agent SDK
TypedHandoff: Typed handoff with schema validation using Pydantic models.
TypedHandoff
Defined in the handoff module.
AI Agent
Typed handoff with schema validation using Pydantic models.
This class extends the base Handoff to add type safety through Pydantic schema validation. The sender declares an output schema, the receiver expects that schema, and the framework validates the payload at the boundary, raising HandoffValidationError if validation fails.
The receiving agent’s prompt is constructed from validated JSON rather than raw string concatenation, enabling proper deserialization of structured data.
Constructor
AgentNo description available.
Type[T]No description available.
Optional[str]No description available.
Optional[str]No description available.
Optional[Callable]No description available.
OptionalNo description available.
Optional[HandoffConfig]No description available.
Methods
Execute typed handoff programmatically with schema validation.
execute_async()Execute typed handoff asynchronously with schema validation.
Usage
from pydantic import BaseModel
from praisonaiagents.agent.handoff import TypedHandoff, HandoffValidationError
class ResearchResult(BaseModel):
summary: str
citations: list[str]
confidence: float
# Create typed handoff
typed_handoff = TypedHandoff(
agent=writer_agent,
input_schema=ResearchResult
)
# Valid payload
result = ResearchResult(
summary="AI research findings",
citations=["ref1", "ref2"],
confidence=0.92
)
response = typed_handoff.execute_programmatic(source_agent, result)
# Invalid payload raises HandoffValidationError
bad_payload = {"summary": "...", "citations": "not-a-list"}
typed_handoff.execute_programmatic(source_agent, bad_payload) # Raises errorSource
View on GitHubpraisonaiagents/agent/handoff.py at line 1514