Skip to main content

tool

Attribute Macro tool 

Source
#[tool]
Expand description

Attribute macro that generates a Tool implementation from an async function.

§Requirements

  • The function must be async
  • It must take exactly one argument (the args struct) that implements serde::de::DeserializeOwned and schemars::JsonSchema
  • It must return Result<serde_json::Value, adk_tool::AdkError>
  • Doc comments become the tool description

§Attributes

Optional attributes can be passed to configure tool metadata:

  • read_only — marks the tool as having no side effects (is_read_only() → true)
  • concurrency_safe — marks the tool as safe for concurrent execution (is_concurrency_safe() → true)
  • long_running — marks the tool as long-running (is_long_running() → true)

§Examples

/// Search the knowledge base for documents matching a query.
#[tool]
async fn search_docs(args: SearchArgs) -> Result<serde_json::Value, adk_tool::AdkError> {
    // ...
}

/// Look up cached data (read-only, safe for parallel dispatch).
#[tool(read_only, concurrency_safe)]
async fn cache_lookup(args: LookupArgs) -> Result<serde_json::Value, adk_tool::AdkError> {
    // ...
}

// Generated: pub struct SearchDocs; implements Tool
// Use: agent_builder.tool(Arc::new(SearchDocs))