Skip to main content
Agent.stream() returns a reactive Flux<Event> that lets callers observe every reasoning step, tool-call result, and final reply in real time, rather than waiting for call() to return a single Msg.

Basic Usage

With RuntimeContext (HarnessAgent):
StreamOptions.defaults() enables all event types in incremental mode.

Event Types (EventType)

Subscribe to specific types only

Distinguish chunks from final results

For the same REASONING message the model first streams several incremental chunks, then emits a final event with the complete text. Use Event.isLast():

Incremental vs. Full-text Mode


Reasoning / Summary Content Filtering

Some models emit both intermediate delta chunks and a final consolidated result inside the same REASONING event group. Control them independently:
Similarly for summaries:

Error Handling

stream() follows standard Reactor error semantics; use onErrorResume to handle:
When a tool execution fails, the framework converts the exception to a TOOL_RESULT error string. The onError signal is not propagated to the parent stream, so the overall stream is not terminated prematurely.

Integration with Spring WebFlux / SSE

Flux<Event> bridges directly into Server-Sent Events:
When using HarnessAgent and you need to forward child-agent source metadata to the frontend, serialize event.getSource() as well — see Harness Subagent Streaming.

StreamOptions Reference


  • Hook — Insert custom logic at reasoning / tool-call lifecycle points
  • Model — Underlying streaming model configuration
  • Harness Subagent Streaming — Child-agent event forwarding and EventSource fields when using HarnessAgent