@@ -51,10 +51,21 @@ AI SDK for Python supports tools that are async-generators. You might want to
5151use those when your tools need to return partial output, e.g. when wrapping
5252subagents.
5353
54- Streaming tools require a special return type in order to get correctly
55- handled by the SDK, since partial outputs need to be accumulated, passed through,
56- and the LLM needs to receive an accumulated result. That return type must be
57- a subtype of ` ai.Aggregator ` .
54+ Streaming tools use aggregators. An aggregator solves two problems: the tool can
55+ yield many values over time, but the agent still needs one final tool result;
56+ and your app may want a rich stored result while the model needs a simpler value
57+ on the next turn.
58+
59+ The core interface is:
60+
61+ ``` python
62+ class Aggregator[Item, Result, ModelInput]:
63+ def feed (self , item : Item) -> None : ...
64+ def snapshot (self ) -> Result: ...
65+
66+ @ classmethod
67+ def to_model_input (cls , snapshot : Result) -> ModelInput: ...
68+ ```
5869
5970Use ` ai.StreamingTextTool ` when yielded strings should concatenate into the
6071tool result:
@@ -71,6 +82,9 @@ async def draft_reply(topic: str) -> ai.StreamingTextTool:
7182Use ` ai.StreamingStatusTool[T] ` when intermediate yields are progress updates
7283and the last yielded value is the final result.
7384
85+ Use ` ai.SubAgentTool ` when a tool streams events from a nested agent. The stored
86+ result is a message bundle, and the model sees the final assistant text.
87+
7488The agent emits ` PartialToolCallResult ` events for those values, then sends
7589the aggregated result back to the model on the next turn.
7690
0 commit comments