pub struct SubagentBridge {
pub parent_events: Arc<EventEmitter>,
pub parent_tool_call_id: ToolCallId,
}Expand description
A handle for bridging sub-turn events (spawned internally by a tool) back into the parent session’s event stream.
Holds the parent session’s EventEmitter and the ToolCallId that initiated this
tool invocation. Clone is cheap (internally Arc + small string).
§Recursive bridging: each layer only prepends its own id
The full ancestor chain is not stored here — it is accumulated incrementally as events
bubble upward through each layer’s bridge. The bridge subscriber (e.g.,
spawn_agent’s bridge_task) at each layer:
- Receives a leaf event from the sub-turn → wraps it as
Subagent{ ancestor_path: [parent_tool_call_id], agent_type: <this layer's profile>, inner: leaf }; - Receives an already
Subagent(from a deeper layer, already carrying a partial chain) → prependsparent_tool_call_idto the head of itsancestor_path, leavinginnerleaf and deeperagent_typeunchanged.
Thus after passing through N layers of bridging, ancestor_path is exactly the
complete id chain from the top layer down to the leaf. Each layer only needs to know
its own hop — this lets frontend, backend, and arbitrary depths share the same logic.
The recursive depth gate is not here — it is functional and must always apply
(including in non-observability / test scenarios), so it lives in the separate
ToolContext::subagent_depth field rather than in this optional bridge.
Fields§
§parent_events: Arc<EventEmitter>Event bus of the parent session. Wrapped crate::event::AgentEvent::Subagent
events are emitted here.
parent_tool_call_id: ToolCallIdThe tool call ID that spawned this subagent (the corresponding tool span in the parent trace). The bridge prepends this ID, serving as the mount point of this subagent within the parent trace.
Trait Implementations§
Source§impl Clone for SubagentBridge
impl Clone for SubagentBridge
Source§fn clone(&self) -> SubagentBridge
fn clone(&self) -> SubagentBridge
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more