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

ParamField Agent

No description available.

ParamField Type[T]

No description available.

ParamField Optional[str]

No description available.

ParamField Optional[str]

No description available.

ParamField Optional[Callable]

No description available.

ParamField Optional

No description available.

ParamField Optional[HandoffConfig]

No description available.

Methods

Usage

python
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 error

Source

View on GitHub

praisonaiagents/agent/handoff.py at line 1514


Related Documentation