Prerequisite: Streaming basics —When a parentstream()API,EventType,StreamOptions, SSE integration. This page focuses onHarnessAgent’s child-agent event forwarding mechanism.
HarnessAgent.stream() triggers agent_spawn or agent_send, all intermediate events from the child agent are injected into the parent Flux<Event> in real time, tagged with an EventSource that identifies their origin — no extra configuration needed.
How It Works
stream() mode. When using call(), no bus is present and agent_spawn falls back to the blocking invokeAgent path with no behaviour change.
Event Timeline
source == null; child events have source != null.
Identifying the Source with EventSource
EventSource Field Reference
Path convention:
<parentSessionId>/<agentId>. For deeper nesting it extends naturally: sess-001/planner/executor.
Multi-level Nesting (Grandchild Agents)
A childHarnessAgent injects its own bus at its stream() entry point. Grandchild events are first captured by the child bus (depth+1), then flow out through the child Flux<Event>, where AgentSpawnTool in the grandparent forwards them again to the grandparent bus. The path field accumulates depth automatically.
Common Consumption Patterns
1. Real-time UI Rendering per Agent
Route events to separate UI panels based on source:2. Await Child Agent’s Final Reply
If you only care about the child’s result text (not intermediate events):3. Collect and Group by Agent
4. SSE with Source Metadata
Forward child-agent origin to the browser:Error Handling
When a child agent throws internally, the framework catches the exception and writes it as aTOOL_RESULT error string. The onError signal is not propagated to the parent Flux, so the parent stream continues normally.
For fatal errors in the parent stream itself, standard Reactor semantics apply:
Scope Boundaries
Related Documents
- Streaming Basics —
stream()API,EventType, fullStreamOptionsreference - Subagent — Subagent declarations,
agent_spawn/agent_sendparameters - Architecture —
SubagentEventBus, Reactor Context injection, andStreamingHooklifecycle