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/ag-ui.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ There are three ways to run a Pydantic AI agent based on AG-UI run input with st
35
35
36
36
1.[`run_ag_ui()`][pydantic_ai.ag_ui.run_ag_ui] takes an agent and an AG-UI [`RunAgentInput`](https://docs.ag-ui.com/sdk/python/core/types#runagentinput) object, and returns a stream of AG-UI events encoded as strings. It also takes optional [`Agent.iter()`][pydantic_ai.Agent.iter] arguments including `deps`. Use this if you're using a web framework not based on Starlette (e.g. Django or Flask) or want to modify the input or output some way.
37
37
2.[`handle_ag_ui_request()`][pydantic_ai.ag_ui.handle_ag_ui_request] takes an agent and a Starlette request (e.g. from FastAPI) coming from an AG-UI frontend, and returns a streaming Starlette response of AG-UI events that you can return directly from your endpoint. It also takes optional [`Agent.iter()`][pydantic_ai.Agent.iter] arguments including `deps`, that you can vary for each request (e.g. based on the authenticated user).
38
-
3.[`Agent.to_ag_ui()`][pydantic_ai.Agent.to_ag_ui] returns an ASGI application that handles every AG-UI request by running the agent. It also takes optional [`Agent.iter()`][pydantic_ai.Agent.iter] arguments including `deps`, but these will be the same for each request, with the exception of the AG-UI state that's injected as described under [state management](#state-management). This ASGI app can be [mounted](https://fastapi.tiangolo.com/advanced/sub-applications/) at a given path in an existing FastAPI app.
38
+
3.[`Agent.to_ag_ui()`][pydantic_ai.agent.AbstractAgent.to_ag_ui] returns an ASGI application that handles every AG-UI request by running the agent. It also takes optional [`Agent.iter()`][pydantic_ai.Agent.iter] arguments including `deps`, but these will be the same for each request, with the exception of the AG-UI state that's injected as described under [state management](#state-management). This ASGI app can be [mounted](https://fastapi.tiangolo.com/advanced/sub-applications/) at a given path in an existing FastAPI app.
39
39
40
40
### Handle run input and output directly
41
41
@@ -117,7 +117,7 @@ This will expose the agent as an AG-UI server, and your frontend can start sendi
117
117
118
118
### Stand-alone ASGI app
119
119
120
-
This example uses [`Agent.to_ag_ui()`][pydantic_ai.Agent.to_ag_ui] to turn the agent into a stand-alone ASGI application:
120
+
This example uses [`Agent.to_ag_ui()`][pydantic_ai.agent.AbstractAgent.to_ag_ui] to turn the agent into a stand-alone ASGI application:
Copy file name to clipboardExpand all lines: docs/changelog.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,14 @@ Pydantic AI is still pre-version 1, so breaking changes will occur, however:
12
12
!!! note
13
13
Here's a filtered list of the breaking changes for each version to help you upgrade Pydantic AI.
14
14
15
+
### v0.7.0 (2025-08-08)
16
+
17
+
See [#2458](https://github.com/pydantic/pydantic-ai/pull/2458) - `pydantic_ai.models.StreamedResponse` now yields a `FinalResultEvent` along with the existing `PartStartEvent` and `PartDeltaEvent`. If you're using `pydantic_ai.direct.model_request_stream` or `pydantic_ai.direct.model_request_stream_sync`, you may need to update your code to account for this.
18
+
19
+
See [#2458](https://github.com/pydantic/pydantic-ai/pull/2458) - `pydantic_ai.models.Model.request_stream` now receives a `run_context` argument. If you've implemented a custom `Model` subclass, you will need to account for this.
20
+
21
+
See [#2458](https://github.com/pydantic/pydantic-ai/pull/2458) - `pydantic_ai.models.StreamedResponse` now requires a `model_request_parameters` field and constructor argument. If you've implemented a custom `Model` subclass and implemented `request_stream`, you will need to account for this.
22
+
15
23
### v0.6.0 (2025-08-06)
16
24
17
25
This release was meant to clean some old deprecated code, so we can get a step closer to V1.
Copy file name to clipboardExpand all lines: docs/logfire.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,7 @@ We can also query data with SQL in Logfire to monitor the performance of an appl
119
119
agent = Agent('openai:gpt-4o')
120
120
result = agent.run_sync('What is the capital of France?')
121
121
print(result.output)
122
-
#> Paris
122
+
#> The capital of France is Paris.
123
123
```
124
124
125
125
1. See the [`logfire.instrument_httpx` docs][logfire.Logfire.instrument_httpx] more details, `capture_all=True` means both headers and body are captured for both the request and response.
@@ -139,7 +139,7 @@ We can also query data with SQL in Logfire to monitor the performance of an appl
139
139
agent = Agent('openai:gpt-4o')
140
140
result = agent.run_sync('What is the capital of France?')
141
141
print(result.output)
142
-
#> Paris
142
+
#> The capital of France is Paris.
143
143
```
144
144
145
145

Copy file name to clipboardExpand all lines: docs/message-history.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ Pydantic AI provides access to messages exchanged during an agent run. These mes
7
7
After running an agent, you can access the messages exchanged during that run from the `result` object.
8
8
9
9
Both [`RunResult`][pydantic_ai.agent.AgentRunResult]
10
-
(returned by [`Agent.run`][pydantic_ai.Agent.run], [`Agent.run_sync`][pydantic_ai.Agent.run_sync])
11
-
and [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] (returned by [`Agent.run_stream`][pydantic_ai.Agent.run_stream]) have the following methods:
10
+
(returned by [`Agent.run`][pydantic_ai.agent.AbstractAgent.run], [`Agent.run_sync`][pydantic_ai.agent.AbstractAgent.run_sync])
11
+
and [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] (returned by [`Agent.run_stream`][pydantic_ai.agent.AbstractAgent.run_stream]) have the following methods:
12
12
13
13
-[`all_messages()`][pydantic_ai.agent.AgentRunResult.all_messages]: returns all messages, including messages from prior runs. There's also a variant that returns JSON bytes, [`all_messages_json()`][pydantic_ai.agent.AgentRunResult.all_messages_json].
14
14
-[`new_messages()`][pydantic_ai.agent.AgentRunResult.new_messages]: returns only the messages from the current run. There's also a variant that returns JSON bytes, [`new_messages_json()`][pydantic_ai.agent.AgentRunResult.new_messages_json].
@@ -141,8 +141,8 @@ _(This example is complete, it can be run "as is" — you'll need to add `asynci
141
141
The primary use of message histories in Pydantic AI is to maintain context across multiple agent runs.
142
142
143
143
To use existing messages in a run, pass them to the `message_history` parameter of
144
-
[`Agent.run`][pydantic_ai.Agent.run], [`Agent.run_sync`][pydantic_ai.Agent.run_sync] or
Copy file name to clipboardExpand all lines: docs/multi-agent-applications.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ If you want to hand off control to another agent completely, without coming back
16
16
17
17
Since agents are stateless and designed to be global, you do not need to include the agent itself in agent [dependencies](dependencies.md).
18
18
19
-
You'll generally want to pass [`ctx.usage`][pydantic_ai.RunContext.usage] to the [`usage`][pydantic_ai.Agent.run] keyword argument of the delegate agent run so usage within that run counts towards the total usage of the parent agent run.
19
+
You'll generally want to pass [`ctx.usage`][pydantic_ai.RunContext.usage] to the [`usage`][pydantic_ai.agent.AbstractAgent.run] keyword argument of the delegate agent run so usage within that run counts towards the total usage of the parent agent run.
20
20
21
21
!!! note "Multiple models"
22
22
Agent delegation doesn't need to use the same model for each agent. If you choose to use different models within a run, calculating the monetary cost from the final [`result.usage()`][pydantic_ai.agent.AgentRunResult.usage] of the run will not be possible, but you can still use [`UsageLimits`][pydantic_ai.usage.UsageLimits] to avoid unexpected costs.
Copy file name to clipboardExpand all lines: docs/output.md
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -482,6 +482,13 @@ There two main challenges with streamed results:
482
482
1. Validating structured responses before they're complete, this is achieved by "partial validation" which was recently added to Pydantic in [pydantic/pydantic#10748](https://github.com/pydantic/pydantic/pull/10748).
483
483
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].
484
484
485
+
!!! note
486
+
As the `run_stream()` method will consider the first output matching the `output_type` to be the final output,
487
+
it will stop running the agent graph and will not execute any tool calls made by the model after this "final" output.
488
+
489
+
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,
490
+
use [`agent.run()`][pydantic_ai.agent.AbstractAgent.run] with an `event_stream_handler` ([docs](agents.md#streaming-all-events)) or [`agent.iter()`][pydantic_ai.agent.AbstractAgent.iter] ([docs](agents.md#streaming-all-events-and-output)) instead.
491
+
485
492
### Streaming Text
486
493
487
494
Example of streamed text output:
@@ -505,7 +512,7 @@ async def main():
505
512
```
506
513
507
514
1. Streaming works with the standard [`Agent`][pydantic_ai.Agent] class, and doesn't require any special setup, just a model that supports streaming (currently all models support streaming).
508
-
2. The [`Agent.run_stream()`][pydantic_ai.Agent.run_stream] method is used to start a streamed run, this method returns a context manager so the connection can be closed when the stream completes.
515
+
2. The [`Agent.run_stream()`][pydantic_ai.agent.AbstractAgent.run_stream] method is used to start a streamed run, this method returns a context manager so the connection can be closed when the stream completes.
509
516
3. Each item yield by [`StreamedRunResult.stream_text()`][pydantic_ai.result.StreamedRunResult.stream_text] is the complete text response, extended as new data is received.
510
517
511
518
_(This example is complete, it can be run "as is" — you'll need to add `asyncio.run(main())` to run `main`)_
@@ -540,22 +547,20 @@ _(This example is complete, it can be run "as is" — you'll need to add `asynci
540
547
541
548
### Streaming Structured Output
542
549
543
-
Not all types are supported with partial validation in Pydantic, see [pydantic/pydantic#10748](https://github.com/pydantic/pydantic/pull/10748), generally for model-like structures it's currently best to use `TypeDict`.
544
-
545
-
Here's an example of streaming a use profile as it's built:
550
+
Here's an example of streaming a user profile as it's built:
from typing_extensions import TypedDict, NotRequired
551
556
552
557
from pydantic_ai import Agent
553
558
554
559
555
-
classUserProfile(TypedDict, total=False):
560
+
classUserProfile(TypedDict):
556
561
name: str
557
-
dob: date
558
-
bio: str
562
+
dob: NotRequired[date]
563
+
bio: NotRequired[str]
559
564
560
565
561
566
agent = Agent(
@@ -581,7 +586,7 @@ async def main():
581
586
582
587
_(This example is complete, it can be run "as is" — you'll need to add `asyncio.run(main())` to run `main`)_
583
588
584
-
If you want fine-grained control of validation, particularly catching validation errors, you can use the following pattern:
589
+
If you want fine-grained control of validation, you can use the following pattern to get the entire partial [`ModelResponse`][pydantic_ai.messages.ModelResponse]:
0 commit comments