Skip to main content

Typed output

Pass a type as output_model_schema. Read the instance from result.structured_output.
Any type Pydantic can validate works: a model, list[Model], Literal['yes', 'no']. For a JSON-schema dict, wrap it in pydantic_ai.StructuredDict(schema). Anything else raises a TypeError in Agent(...).

The result

run() returns an AgentHistoryList.
Methods kept from 0.x: final_result(), structured_output, is_done(), is_successful(), errors(), has_errors(), number_of_steps(), total_duration_seconds(). print(result) omits messages, which can be large.

Status and success

A run that reaches max_steps or the timeout gets one forced delivery turn. If the agent delivers, status is still 'completed', and success is False when it reports the task unfinished. 'max_steps' and 'timeout' mean nothing was delivered; read result.partial.
  • is_done() is True when status == 'completed'.
  • is_successful() is the agent’s verdict: True, False, or None when it gave none. It is the agent’s own claim; verify important actions independently.
  • errors() lists only the error that ended the run. Cell errors the agent recovered from are in messages.
For the 0.x default (no verdict counts as success), use result.is_done() and result.success is not False.

Removed from 0.x

There are no per-step actions in 1.0, so history, urls(), screenshots(), action_names(), model_thoughts(), extracted_content(), save_to_file(), load_from_file(), judgement() and similar raise an AttributeError that points to the replacement. Use final_result(), structured_output, messages, partial and the files in agent.workspace.