You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/output.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ If the output type schema is not of type `"object"` (e.g. it's `int` or `list[in
43
43
Structured outputs (like tools) use Pydantic to build the JSON schema used for the tool, and to validate the data returned by the model.
44
44
45
45
!!! note "Type checking considerations"
46
-
The Agent class is generic in its output type, and this type is carried through to `AgentRunResult.output` and `StreamedRunResult.output` so that your IDE or static type checker can warn you when your code doesn't properly take into account all the possible values those outputs could have.
46
+
The Agent class is generic in its output type, and this type is carried through to `AgentRunResult.output` and `StreamedRunResult.output` so that your IDE or static type checker can warn you when your code doesn't properly take into account all the possible values those outputs could have.
47
47
48
48
Static type checkers like pyright and mypy will do their best to infer the agent's output type from the `output_type` you've specified, but they're not always able to do so correctly when you provide functions or multiple types in a union or list, even though Pydantic AI will behave correctly. When this happens, your type checker will complain even when you're confident you've passed a valid `output_type`, and you'll need to help the type checker by explicitly specifying the generic parameters on the `Agent` constructor. This is shown in the second example below and the output functions example further down.
49
49
@@ -544,8 +544,8 @@ There two main challenges with streamed results:
544
544
2. When receiving a response, we don't know if it's the final response without starting to stream it and peeking at the content. Pydantic AI streams just enough of the response to sniff out if it's a tool call or an output, then streams the whole thing and calls tools, or returns the stream as a [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult].
545
545
546
546
!!! note
547
-
As the `run_stream()` method will consider the first output matching the `output_type` to be the final output,
548
-
it will stop running the agent graph and will not execute any tool calls made by the model after this "final" output.
547
+
As the `run_stream()` method will consider the first output matching the `output_type` to be the final output,
548
+
it will stop running the agent graph and will not execute any tool calls made by the model after this "final" output.
549
549
550
550
If you want to always run the agent graph to completion and stream all events from the model's streaming response and the agent's execution of tools,
551
551
use [`agent.run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events] ([docs](agents.md#streaming-all-events)) or [`agent.iter()`][pydantic_ai.agent.AbstractAgent.iter] ([docs](agents.md#streaming-all-events-and-output)) instead.
@@ -603,8 +603,8 @@ async def main():
603
603
_(This example is complete, it can be run "as is" — you'll need to add `asyncio.run(main())` to run `main`)_
604
604
605
605
!!! warning "Output message not included in `messages`"
606
-
The final output message will **NOT** be added to result messages if you use `.stream_text(delta=True)`,
607
-
see [Messages and chat history](message-history.md) for more information.
606
+
The final output message will **NOT** be added to result messages if you use `.stream_text(delta=True)`,
607
+
see [Messages and chat history](message-history.md) for more information.
0 commit comments