Skip to content

agentix.streaming

streaming

Streaming types.

Two layers of events:

  • Model stream — what a streaming model yields: zero or more :class:TextDelta chunks, then exactly one :class:ResponseComplete carrying the full :class:ModelResponse (text + tool calls + tokens).
  • Agent stream — what :meth:Agent.stream yields to you: :class:AnswerDelta (incremental answer text), :class:ToolStarted / :class:ToolFinished around each tool call, and a terminal :class:Done carrying the full :class:AgentOutcome.

A model that supports streaming implements :class:StreamingModelFn (an async stream method). The loop falls back to non-streaming if it doesn't.

StreamingModelFn

Bases: Protocol

A model that can stream. stream yields TextDelta chunks then one ResponseComplete with the assembled response.

AnswerDelta dataclass

AnswerDelta(text: str)

Incremental text of the model's response for the current turn.

chunk_text

chunk_text(text: str) -> list[str]

Split text into word-ish chunks for a realistic fake stream.