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
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 sameREASONING 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 sameREASONING event group. Control them independently:
Error Handling
stream() follows standard Reactor error semantics; use onErrorResume to handle:
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:
HarnessAgent and you need to forward child-agent source metadata to the frontend,
serialize event.getSource() as well — see Harness Subagent Streaming.
StreamOptions Reference
Related Documents
- Hook — Insert custom logic at reasoning / tool-call lifecycle points
- Model — Underlying streaming model configuration
- Harness Subagent Streaming — Child-agent event forwarding and
EventSourcefields when usingHarnessAgent