pub struct SubAgentTool<State: Send + Sync, Ctx: Send + Sync = ()> { /* private fields */ }Expand description
A Tool adapter that exposes a SubAgent to a parent agent — the
surface that turns “agents calling agents” into an ordinary tool call.
When the parent model calls this tool, SubAgentTool runs the wrapped
sub-agent as a child run at the configured parent_depth and returns the
child’s final assistant text as the crate::harness::tool::ToolResult
content. This makes an entire agent composable as a single tool call, so a
model orchestrating tools is, transparently, a model orchestrating models.
Because the Tool trait gives call no access to the live parent
crate::harness::context::RunContext, the depth the child runs at is fixed
at construction (parent_depth, default 0). Nesting deeper sub-agents is
expressed by constructing the inner tool with a larger parent_depth. For
fully context-threaded invocation (reading the live parent depth) call
SubAgent::invoke_in_parent directly instead of going through the tool.
Implementations§
Source§impl<State: Send + Sync, Ctx: Send + Sync> SubAgentTool<State, Ctx>
impl<State: Send + Sync, Ctx: Send + Sync> SubAgentTool<State, Ctx>
Sourcepub fn new(subagent: Arc<SubAgent<State, Ctx>>) -> Self
pub fn new(subagent: Arc<SubAgent<State, Ctx>>) -> Self
Wraps subagent as a tool invoked at parent_depth = 0 (child runs at
depth 1). The tool name defaults to the sub-agent name.
Sourcepub fn with_tool_name(self, name: impl Into<String>) -> Self
pub fn with_tool_name(self, name: impl Into<String>) -> Self
Overrides the model-visible tool name.
Sourcepub fn with_parent_depth(self, parent_depth: usize) -> Self
pub fn with_parent_depth(self, parent_depth: usize) -> Self
Sets the caller depth this tool invokes the child at; the child runs at
parent_depth + 1. Use this to express deeper nesting through the tool
path (where the live parent depth is not available).
Sourcepub fn with_parameters(self, parameters: Value) -> Self
pub fn with_parameters(self, parameters: Value) -> Self
Overrides the model-visible JSON Schema for the tool arguments.