pub trait ToolContext: CallbackContext {
// 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 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 { ... }
}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 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(())
}Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".