Skip to main content

AgentTool

Struct AgentTool 

Source
pub struct AgentTool { /* private fields */ }
Expand description

AgentTool wraps an Agent to make it callable as a Tool.

When the parent LLM generates a function call targeting this tool, the framework executes the wrapped agent, captures its final response, and returns it as the tool’s result.

Implementations§

Source§

impl AgentTool

Source

pub fn new(agent: Arc<dyn Agent>) -> Self

Create a new AgentTool wrapping the given agent.

Source

pub fn with_config(agent: Arc<dyn Agent>, config: AgentToolConfig) -> Self

Create a new AgentTool with custom configuration.

Source

pub fn skip_summarization(self, skip: bool) -> Self

Set whether to skip summarization.

Source

pub fn forward_artifacts(self, forward: bool) -> Self

Set whether to forward artifacts.

Source

pub fn timeout(self, timeout: Duration) -> Self

Set timeout for sub-agent execution.

Source

pub fn input_schema(self, schema: Value) -> Self

Set custom input schema.

Source

pub fn output_schema(self, schema: Value) -> Self

Set custom output schema.

Source

pub fn session_snapshot(self, snapshot: AgentToolSessionSnapshot) -> Self

Choose which parent session data is snapshotted into the isolated child session.

Source

pub fn forward_memory(self, forward: bool) -> Self

Set whether the wrapped agent can access the parent’s memory service.

Source

pub fn forward_shared_state(self, forward: bool) -> Self

Set whether the wrapped agent can access the parent’s parallel shared state.

This defaults to true to preserve the historical AgentTool behavior.

Source

pub fn forward_events(self, forward: bool) -> Self

Set whether child events are emitted through the parent tool context.

The default is false for backward compatibility. State and artifact deltas are merged regardless of this setting.

Source

pub fn failure_mode(self, mode: AgentToolFailureMode) -> Self

Choose whether delegated failures are returned as JSON or propagated.

Source

pub fn propagate_failures(self, propagate: bool) -> Self

Set whether delegated failures should be propagated as tool errors.

Source

pub fn max_delegation_depth(self, max_depth: u32) -> Self

Bound the number of nested agent-as-tool delegations.

Source

pub fn reject_child_handoffs(self, reject: bool) -> Self

Reject child handoff events that cannot be executed by AgentTool itself.

Source

pub fn execute_child_handoffs( self, agents: impl IntoIterator<Item = Arc<dyn Agent>>, ) -> Self

Executes child handoffs using the supplied exact target registry.

Disabled by default for backward compatibility. When enabled, a child transfer remains inside the nested invocation until the terminal member returns, after which its result is returned to the original caller.

Source

pub fn history_max_events(self, max_events: usize) -> Self

Limits the parent history copied into a delegated session.

A value of zero copies no history while still allowing a filtered state snapshot when parent-session forwarding is enabled.

Source

pub fn state_keys( self, keys: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Copies only these exact state keys into a delegated session.

Source

pub fn output_state_keys( self, keys: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Allows delegated state writes only to these exact keys.

Source

pub fn state_merge_policy(self, policy: AgentToolStateMergePolicy) -> Self

Selects how child state writes merge with concurrent parent updates.

Source

pub fn state_merge_exempt_keys( self, keys: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Exempts trusted framework-owned keys from concurrent merge checks.

Output allowlists still apply. This is intended for runtime bookkeeping that is deliberately updated by both the parent and delegated context.

Source

pub fn artifact_prefixes( self, prefixes: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Allows artifact writes only when their names start with one of these prefixes.

Trait Implementations§

Source§

impl Tool for AgentTool

Source§

fn name(&self) -> &str

Returns the unique name of this tool.
Source§

fn description(&self) -> &str

Returns a human-readable description of what this tool does.
Source§

fn parameters_schema(&self) -> Option<Value>

Returns the JSON Schema for this tool’s parameters, if any.
Source§

fn response_schema(&self) -> Option<Value>

Returns the JSON Schema for this tool’s response, if any.
Source§

fn is_long_running(&self) -> bool

Indicates whether the tool is a long-running operation. Long-running tools typically return a task ID immediately and complete the operation asynchronously.
Source§

fn execute<'life0, 'async_trait>( &'life0 self, ctx: Arc<dyn ToolContext>, args: Value, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes the tool with the given context and arguments.
Source§

fn declaration(&self) -> Value

Returns the tool declaration that should be exposed to model providers. Read more
Source§

fn enhanced_description(&self) -> String

Returns an enhanced description that may include additional notes. For long-running tools, this includes a warning not to call the tool again if it has already returned a pending status. Default implementation returns the base description.
Source§

fn is_builtin(&self) -> bool

Indicates whether this tool is a built-in server-side tool (e.g., google_search, url_context). Read more
Source§

fn required_scopes(&self) -> &[&str]

Returns the scopes required to execute this tool. Read more
Source§

fn is_read_only(&self) -> bool

Indicates whether this tool performs no side effects. Read more
Source§

fn is_concurrency_safe(&self) -> bool

Indicates whether this tool is safe for concurrent execution. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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