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.

The wrapped agent runs as a delegate of its caller. It shares the caller’s budget, governance, tool policy, approvals, ledgers, audit trail and session scope, and acts for the caller’s subject. It does not inherit the caller’s handoff targets, context cache, invocation toolsets or call-ID decisions; its own topology comes from Agent::configure_run and Agent::transfer_targets_for.

Every call the delegate holds for confirmation holds this call too: the tool surfaces each of the delegate’s requests under the caller’s call ID — the last through EventActions::tool_confirmation, the others before it through ToolContext::emit_event — and records the delegate’s session in the caller’s session state. When the caller resumes the call, the delegate resumes each held call that has a decision from that session; a call still undecided keeps this call held (spec 3.1 §10 F4).

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.

The parent agent applies this instead of its own tool timeout. Without one, the delegation runs until it finishes or the run is cancelled.

A delegation that runs past it is a failed call with an ErrorCategory::Timeout error in every AgentToolFailureMode: tool.timeout from a calling agent that enforces the limit, or tool.agent.timeout when the tool is executed directly.

§Example
ⓘ
use adk_tool::AgentTool;
use std::time::Duration;

let research = AgentTool::new(researcher).timeout(Duration::from_secs(20 * 60));
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.

Forwarded events carry the tool’s branch, {caller branch}.{tool}@{call id} (adk_core::history::tool_branch), so observers can follow the delegate’s progress while the caller’s history leaves it out: the caller’s model gets the delegate’s answer once, as the tool’s response.

Source

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

Choose whether delegated failures are returned as JSON or propagated.

Source

pub fn expose_error_messages(self, expose: bool) -> Self

Set whether a delegate’s error message is included in the result it fails with.

By default (AgentToolFailureMode::ReturnErrorObject) a failed delegation returns {"error": "agent execution failed: <component>.<category> (<code>)", "agent": ...} (AdkError::redacted), because the message can quote credentials, internal hosts, or upstream bodies, and the result is sent to the calling agent’s model provider and stored in its session. An error with code TOOL_INVALID_ARGUMENTS_CODE keeps its message. This matches LlmAgentBuilder::expose_tool_error_messages. In AgentToolFailureMode::Propagate the calling agent applies its own setting.

Enable this only when every error the delegate can fail with is safe to send to the provider.

§Example
use std::sync::Arc;

use adk_core::Agent;
use adk_tool::AgentTool;

fn billing_tool(billing_agent: Arc<dyn Agent>) -> AgentTool {
    AgentTool::new(billing_agent).expose_error_messages(true)
}
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 agent_principal(self, principal: AgentPrincipal) -> Self

Sets the principal the wrapped agent acts as when it is delegated to.

Without one, the delegate acts as AgentPrincipal::derived from the app name and the wrapped agent’s name, in the caller’s tenant. Either way it acts for the caller’s subject, and the caller is appended to its delegation chain.

§Example
ⓘ
use adk_core::{AgentId, AgentPrincipal};
use adk_tool::AgentTool;

let tool = AgentTool::new(researcher)
    .agent_principal(AgentPrincipal::new(AgentId::new("spiffe://acme/agent/researcher")?));
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 is_agent_delegation(&self) -> bool

Indicates whether this tool delegates work to another agent. Read more
Source§

fn egress(&self, _args: &Value) -> ToolEgress

The network destinations a call with args reaches. Read more
Source§

fn timeout_override(&self) -> Option<Option<Duration>>

Overrides the per-call timeout the agent applies to this tool. Read more
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 annotations(&self) -> Option<&Value>

Returns the behaviour annotations the tool’s publisher declared, if any. Read more
Source§

fn origin(&self) -> &str

Returns who publishes this tool: the toolset or server it comes from. 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 effect(&self) -> ToolEffect

Returns the side-effect class of this tool. Read more
Source§

fn is_concurrency_safe(&self) -> bool

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

fn batch_group(&self) -> Option<BatchGroup>

The ordered batch this tool’s calls belong to, if any. Read more
Source§

fn approval_evidence(&self, _args: &Value) -> Vec<Evidence>

What an approver sees with a call with args when it is held, such as the exact image it would send (Evidence). Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for AgentTool

§

impl !UnwindSafe for AgentTool

§

impl Forget for AgentTool

§

impl Freeze for AgentTool
where *const ArcInner<dyn Agent> is !null: Freeze, PhantomData<ArcInner<dyn Agent>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Value>: Freeze, *const LeafNode<String, Value> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Value)>>: Freeze, *const ArcInner<HashMap<String, Arc<dyn Agent>>> is !null: Freeze, PhantomData<ArcInner<HashMap<String, Arc<dyn Agent>>>>: Freeze, *const ArcInner<HashSet<String>> is !null: Freeze, PhantomData<ArcInner<HashSet<String>>>: Freeze, *const ArcInner<Vec<String>> is !null: Freeze, PhantomData<ArcInner<Vec<String>>>: Freeze, *const LeafNode<String, String> is !null: Freeze, PhantomData<Box<(String, String)>>: Freeze,

§

impl Move for AgentTool

§

impl Send for AgentTool
where Arc<dyn Agent>: Send, RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, Arc<HashMap<String, Arc<dyn Agent>>>: Send, Arc<HashSet<String>>: Send, Arc<Vec<String>>: Send, NodeRef<Owned, String, String, LeafOrInternal>: Send, BoxRaw<(String, String)>: Send,

§

impl Sync for AgentTool
where Arc<dyn Agent>: Sync, RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, Arc<HashMap<String, Arc<dyn Agent>>>: Sync, Arc<HashSet<String>>: Sync, Arc<Vec<String>>: Sync, NodeRef<Owned, String, String, LeafOrInternal>: Sync, BoxRaw<(String, String)>: Sync,

§

impl Unpin for AgentTool
where Arc<dyn Agent>: Unpin, *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Arc<HashMap<String, Arc<dyn Agent>>>: Unpin, Arc<HashSet<String>>: Unpin, Arc<Vec<String>>: Unpin, *const LeafNode<String, String> is !null: Unpin, Box<(String, String)>: Unpin,

§

impl UnsafeUnpin for AgentTool
where *const ArcInner<dyn Agent> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Agent>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<Value>: UnsafeUnpin, *const LeafNode<String, Value> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, Value)>>: UnsafeUnpin, *const ArcInner<HashMap<String, Arc<dyn Agent>>> is !null: UnsafeUnpin, PhantomData<ArcInner<HashMap<String, Arc<dyn Agent>>>>: UnsafeUnpin, *const ArcInner<HashSet<String>> is !null: UnsafeUnpin, PhantomData<ArcInner<HashSet<String>>>: UnsafeUnpin, *const ArcInner<Vec<String>> is !null: UnsafeUnpin, PhantomData<ArcInner<Vec<String>>>: UnsafeUnpin, *const LeafNode<String, String> is !null: UnsafeUnpin, PhantomData<Box<(String, String)>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> MaybeSendSync for T

Source§

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

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
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, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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