What this thread does
Do first: Enter agent.run_stream(user_input) with async with, then use async for over the appropriate output stream.
Short answer
Render each accumulated snapshot as a replacement. Append chunks only when you explicitly request text deltas.
What to do
With an existing configured agent and user_input, inside an async function:
async with agent.run_stream(user_input) as result:
async for message in result.stream_text():
print(message)
| Need | Value / action |
|---|---|
| Cumulative text | result.stream_text(); delta=False applies output validators to each accumulated snapshot |
| New text only | result.stream_text(delta=True); raw deltas skip output validators and omit the final output message from result messages |
| Text batching | debounce_by defaults to 0.1 seconds; None yields as chunks arrive |
| Structured values | Set output_type; iterate result.stream_output(). Each yield is an accumulated snapshot with partial validation; the final output gets full validation |
| Text conversion functions | stream_text() skips TextOutput functions; use stream_output() for their resulting values |
| Side effects in output functions/validators | Check RunContext.partial_output: True for partial output, False for final output |
| Full graph and tool events | agent.run_stream_events() or agent.iter(); run_stream() stops at the first output matching output_type |
| Optional empty output | stream_output() can yield nothing for a final None; use get_output() |
| Stop current response | await result.cancel(); result.cancelled records cancellation and the response has state='interrupted' |
Limits and open questions
stream_text() rejects non-text responses. Partial structured fields/items may be absent until valid; do not append every snapshot. Default Tool Output needs a model that streams tool arguments. Otherwise use Native Output or Prompted Output; the page specifies Native Output for Gemini 3 and Prompted Output for earlier Gemini models also using function tools. Leaving async with cleans up the stream. Immediate remote cancellation depends on the provider integration; Google, xAI and Hugging Face SDKs do not guarantee it.
Not for: PydanticAI run_stream_sync() consumers.
Sources
Checked
2026-11-17; read Pydantic AI Output, including Streamed Results, partial-output handling, optional output and stream cancellation; no command was run.
Started from a post by @pydantic, packaged by the editor. Original post