Skip to content

Output functions are called twice or more times in streaming mode #3624

@Danipulok

Description

@Danipulok

Initial Checks

Description

Summary

Output tools are called zero, twice or more times in streaming mode (but only once in sync mode)
(I'm not sure about the zero case for sync mode)

What happens

The first call happens at _agent_graph.py:861 during tool call processing in the graph execution, and the second call happens at result.py:179 when validating the response in get_output().

Details

Output tool processors are invoked:

  • 2 times when using get_output() alone
  • 2 times when using stream_output() alone
  • 4 times when using both stream_output() + get_output()
  • 0 times when the stream isn't consumed at all (IMHO think the expected behavior is to get called anyway)

MRE:

Note: written by an LLM, but shows the current behavior with streaming

https://gist.github.com/Danipulok/f27bedddfc2b7fc476b1836bbf3af14d

Python, Pydantic AI & LLM client version

Python 3.13.4
pydantic==2.12.4
pydantic-ai==1.25.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions