pub trait ToolContext: CallbackContext {
Show 18 methods
// Required methods
fn function_call_id(&self) -> &str;
fn actions(&self) -> EventActions;
fn set_actions(&self, actions: EventActions);
fn search_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided methods
fn memory(&self) -> Option<Arc<dyn Memory>> { ... }
fn session(&self) -> Option<&dyn Session> { ... }
fn run_config(&self) -> Option<&RunConfig> { ... }
fn is_cancelled(&self) -> bool { ... }
fn request_metadata(&self) -> HashMap<String, Value> { ... }
fn delegation_depth(&self) -> u32 { ... }
fn max_delegation_depth(&self) -> Option<u32> { ... }
fn orchestration_root_invocation_id(&self) -> &str { ... }
fn orchestration_edge_id(&self) -> Option<&str> { ... }
fn emit_event<'life0, 'async_trait>(
&'life0 self,
_event: Event,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: Sync + 'async_trait { ... }
fn emit_progress<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_stream: &'life1 str,
_chunk: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait { ... }
fn user_scopes(&self) -> Vec<String> { ... }
fn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait { ... }
fn get_secret_for_purpose<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
purpose: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait { ... }
}Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/Result- Unified error handling Context available to tools during execution.
Extends CallbackContext with tool-specific operations like accessing
the function call ID, managing event actions, and searching memory.
Required Methods§
Sourcefn function_call_id(&self) -> &str
fn function_call_id(&self) -> &str
Returns the function call ID for this tool invocation.
Sourcefn actions(&self) -> EventActions
fn actions(&self) -> EventActions
Get the current event actions. Returns an owned copy for thread safety.
Sourcefn set_actions(&self, actions: EventActions)
fn set_actions(&self, actions: EventActions)
Set the event actions (e.g., to trigger escalation or skip summarization).
Provided Methods§
Sourcefn memory(&self) -> Option<Arc<dyn Memory>>
fn memory(&self) -> Option<Arc<dyn Memory>>
Returns the memory service backing the parent invocation, when exposed.
The default keeps contexts written before this capability backward compatible. Agent-as-tool adapters use it only when memory forwarding is explicitly enabled.
Sourcefn session(&self) -> Option<&dyn Session>
fn session(&self) -> Option<&dyn Session>
Returns the parent session, when exposed by the runtime tool context.
Agent-as-tool adapters can snapshot its history and state for a child invocation without sharing mutable session ownership.
Sourcefn run_config(&self) -> Option<&RunConfig>
fn run_config(&self) -> Option<&RunConfig>
Returns the parent run configuration, when exposed by the runtime.
Sourcefn is_cancelled(&self) -> bool
fn is_cancelled(&self) -> bool
Returns whether the parent invocation has been cancelled.
Sourcefn request_metadata(&self) -> HashMap<String, Value>
fn request_metadata(&self) -> HashMap<String, Value>
Returns authenticated request metadata inherited from the parent run.
Sourcefn delegation_depth(&self) -> u32
fn delegation_depth(&self) -> u32
Returns the current nested agent-as-tool delegation depth.
Sourcefn max_delegation_depth(&self) -> Option<u32>
fn max_delegation_depth(&self) -> Option<u32>
Returns the maximum nested agent-as-tool delegation depth.
Sourcefn orchestration_root_invocation_id(&self) -> &str
fn orchestration_root_invocation_id(&self) -> &str
Returns the root invocation that owns this orchestration tree.
Sourcefn orchestration_edge_id(&self) -> Option<&str>
fn orchestration_edge_id(&self) -> Option<&str>
Returns the causal relationship execution containing this tool call.
Sourcefn emit_event<'life0, 'async_trait>(
&'life0 self,
_event: Event,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
fn emit_event<'life0, 'async_trait>(
&'life0 self,
_event: Event,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
Emits a nested agent event through the parent agent’s event stream.
The default is a no-op. AgentTool uses this only when event forwarding is explicitly enabled, preserving existing callers’ output behavior.
Sourcefn emit_progress<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_stream: &'life1 str,
_chunk: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
fn emit_progress<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_stream: &'life1 str,
_chunk: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
Emit streaming progress output during long-running tool execution.
Tools call this to push intermediate stdout/stderr to the UI layer as it arrives, rather than waiting for the tool to finish. This enables streaming terminal output for shell commands, build logs, etc.
§Arguments
stream- The output stream:"stdout","stderr", or a custom labelchunk- The text chunk to emit
§Example
// Inside a tool's execute() method:
ctx.emit_progress("stdout", "Compiling project...\n").await;
ctx.emit_progress("stdout", "Build successful!\n").await;
ctx.emit_progress("stderr", "warning: unused variable\n").await;The default implementation is a no-op. Runners and UI layers that support streaming output override this to forward chunks to the client.
Sourcefn user_scopes(&self) -> Vec<String>
fn user_scopes(&self) -> Vec<String>
Returns the scopes granted to the current user for this invocation.
Implementations may resolve scopes from session state, JWT claims, or an external identity provider. The default returns an empty set (no scopes granted), which means scope-protected tools will be denied unless the implementation is overridden.
Sourcefn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
fn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Retrieve a secret by name from the configured secret provider.
Returns Ok(Some(value)) if a secret provider is configured and the
secret exists, Ok(None) if no secret provider is configured, or an
error if the provider fails.
§Example
async fn use_secret(ctx: &dyn ToolContext) -> adk_core::Result<()> {
if let Some(api_key) = ctx.get_secret("slack-bot-token").await? {
// use the secret
}
Ok(())
}Sourcefn get_secret_for_purpose<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
purpose: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
fn get_secret_for_purpose<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
purpose: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
Resolves a secret, stating why it is needed.
The tool identity is added by the framework, not taken from the tool, so a
purpose is the only part a tool contributes. An authorizing
SecretService sees both.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".