代理框架
Pydantic AI 2.31 Moves AG-UI Run Identification into the Event Stream, Enabling Streaming Before Delayed Input Arrives
The new release allows a `UIEventStream` to be created before `run_input` is available and lets `AGUIEventStream` hold its own thread and run IDs. It also fixes Temporal sandbox compatibility and tracing attribution for fallback models, reducing diagnostic blind spots in long-running agent workflows.

Pydantic AI 2.31.0 changes the lifecycle between agent backends and frontend event protocols. `UIEventStream` no longer needs to receive `run_input` immediately upon construction. For systems where input is delivered later by a queue, scheduler, or external workflow, the server can configure the stream and its subscribers first, then attach the input when the agent actually runs—without creating a fake initial request or rebuilding the connection.
More importantly, `AGUIEventStream` now stores its own `thread_id` and `run_id`. These identify an ongoing conversation and an individual run, respectively. When they were derived solely from caller input, reconnects, background continuation, or concurrent runs within the same thread could easily lose stable associations. Placing these identifiers on the event-stream object allows every token, tool call, and state event to retain consistent context even before the original input is available. However, the release notes do not claim exactly-once delivery or persistence guarantees, so engineering teams must still handle replay and deduplication themselves.
Version 2.31.0 also fixes two operational issues. First, when a `FallbackModel` fails, the tracing span is now attributed to the model that actually raised the error rather than being generically assigned to the `fallback:` wrapper. This directly improves the interpretability of alerts for provider failure rates, latency, and costs. Second, the package adds the `openai` module to the pass-through list for the Temporal workflow sandbox, preventing agent workflows from failing because of the restricted import environment. PyPI shows that both the wheel and source distribution were uploaded through Trusted Publishing on August 15. Before upgrading, teams should still use their existing AG-UI reconnection, concurrent-run, and Temporal replay tests to validate the behavior.