Structured Output
class AgentResponse(BaseModel):
answer: str = Field(
description="The agent's answer to the query",
)
magic_numbers: list[int] = Field(
default_factory=list,
description="A short list with random numbers",
)
agent = create_agent(
model="ollama:llama3.2",
tools=[get_weather],
system_prompt="You are a helpful assistant",
response_format=AgentResponse,
)
- There are 2 strategies
Tool Strategy: you use a local tool to structure the answer
Provider Strategy: you use the LLM to structure the answer natively