Skip to main content
agent.stream returns an async iterable that emits tokens while exposing promises to retrieve the final state.

Key properties

  • textStreamAsyncIterable<string> with generated tokens.
  • fullStream – complete stream (text, reasoning, tool calls, errors).
  • text, response, usage, steps – promises that resolve once the stream completes.
  • loopTool – boolean flag set when the tool loop runs.
  • toAIStreamResponse() / toDataStreamResponse() – pipe the stream into HTTP responses (Next.js, Remix, …).

Conversational streaming

Structured outputs while streaming

Combine agent.stream with structuredOutput to receive partial fragments during the stream and the validated object at the end.
experimental_partialOutputStream emits schema-compliant fragments. Cache the last one for a provisional UI, then call parseOutput to obtain the final typed object.
Structured streaming is experimental—plan retries when parsing fails.