Skip to main content

SubAgentTool

Struct SubAgentTool 

Source
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>

Source

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.

Source

pub fn with_tool_name(self, name: impl Into<String>) -> Self

Overrides the model-visible tool name.

Source

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).

Source

pub fn with_parameters(self, parameters: Value) -> Self

Overrides the model-visible JSON Schema for the tool arguments.

Trait Implementations§

Source§

impl<State, Ctx> Tool<State> for SubAgentTool<State, Ctx>
where State: Send + Sync, Ctx: Send + Sync + Default,

Source§

fn name(&self) -> &str

Canonical tool name.
Source§

fn description(&self) -> &str

Human/model readable description.
Source§

fn schema(&self) -> ToolSchema

Returns the model-visible schema for this tool.
Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, state: &'life1 State, call: ToolCall, ) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Executes the tool against application state and a validated call.
Source§

fn call_with_context<'life0, 'life1, 'async_trait>( &'life0 self, state: &'life1 State, call: ToolCall, context: ToolExecutionContext, ) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Executes the tool with access to caller run context. Read more
Source§

fn policy(&self) -> ToolPolicy

Returns the SDK-owned safety/runtime policy for this tool. Read more
Source§

fn display_label(&self, _call: &ToolCall) -> Option<String>

Returns the human-facing label for this specific call. Read more
Source§

fn display_detail(&self, call: &ToolCall) -> Option<String>

Returns the human-facing detail for this specific call. Read more
Source§

fn timeout_policy(&self, _call: &ToolCall) -> ToolTimeout

Returns the invocation timeout behavior for this specific call. Read more

Auto Trait Implementations§

§

impl<State, Ctx = ()> !RefUnwindSafe for SubAgentTool<State, Ctx>

§

impl<State, Ctx = ()> !UnwindSafe for SubAgentTool<State, Ctx>

§

impl<State, Ctx> Freeze for SubAgentTool<State, Ctx>

§

impl<State, Ctx> Send for SubAgentTool<State, Ctx>

§

impl<State, Ctx> Sync for SubAgentTool<State, Ctx>

§

impl<State, Ctx> Unpin for SubAgentTool<State, Ctx>

§

impl<State, Ctx> UnsafeUnpin for SubAgentTool<State, Ctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more