Expand description
§adk-tool
Tool system for ADK agents: typed Rust tools, toolset composition, hosted provider tools, and Model Context Protocol clients and servers.
§Overview
This crate provides the tool infrastructure for ADK agents:
tool- Turn an async function into aToolwhose arguments are checked against the derived schema before it runsFunctionTool- Create tools from async Rust functionsStatefulTool- ShareArc<S>state with a tool handlerAgentTool- Use agents as callable tools for compositionAdvisorTool- Let an agent consult a stronger or different model for advice mid-task, under the run’s budget, spend ledger and kill switchGoogleSearchTooland the otherbuiltinwrappers - Provider-hosted tools, each declaring itsToolEffectMcpToolset- MCP tools, resources, prompts, completion, elicitation, subscriptions, and negotiated tasks with themcpfeatureMcpServerManager- Dynamic local MCP server registry, process lifecycle, persistence, health monitoring, and bounded restart with themcpfeatureBasicToolset,FilteredToolset,MergedToolset,PrefixedToolset- Group, filter, combine, and namespace toolsetsToolArgumentValidator- Check hand-written tools’ arguments against a JSON SchemaExitLoopTool- Control flow for loop agentsLoadArtifactsTool- Inject binary artifacts into context
§Quick Start
use adk_core::{Result, ToolContext};
use adk_tool::FunctionTool;
use schemars::JsonSchema;
use serde::Serialize;
use serde_json::{Value, json};
use std::sync::Arc;
#[derive(Serialize, JsonSchema)]
struct WeatherParams {
/// The city to get weather for
city: String,
}
async fn get_weather(_ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
let city = args["city"].as_str().unwrap_or("Unknown");
Ok(json!({
"city": city,
"temperature": 22,
"condition": "sunny"
}))
}
let tool = FunctionTool::new("get_weather", "Get current weather for a city", get_weather)
.with_parameters_schema::<WeatherParams>();§MCP Integration
Connect to MCP servers for external tools (requires the mcp feature):
use adk_tool::{
McpToolset,
mcp::rmcp::{ServiceExt, transport::TokioChildProcess},
};
use tokio::process::Command;
let mut command = Command::new("/opt/company/bin/workspace-mcp");
command.arg("--stdio").arg("--root").arg("/srv/workspace");
let client = ().serve(TokioChildProcess::new(command)?).await?;
let toolset = McpToolset::new(client);§Features
No feature is on by default; function tools, agent tools and toolsets need none. MCP
(mcp, http-transport, mcp-server, mcp-sampling, mcp-apps), memory tools
(memory-tools, graph-memory-tools), code execution (code, code-embedded-js,
code-embedded-python, code-docker), slack, bigquery, spanner, example-store and
vertex-agent-registry each have a feature; the
README
says what each enables.
Re-exports§
pub use memory::GraphMemoryToolset;pub use memory::RelateTool;pub use memory::RememberTool;pub use advisor::AdvisorTool;pub use advisor::AdvisorToolBuilder;pub use builtin::AnthropicAdvisorTool;pub use builtin::AnthropicBashTool20241022;pub use builtin::AnthropicBashTool20250124;pub use builtin::AnthropicTextEditorTool20250124;pub use builtin::AnthropicTextEditorTool20250429;pub use builtin::AnthropicTextEditorTool20250728;pub use builtin::BypassBuiltinTool;pub use builtin::BypassMultiToolsLimit;pub use builtin::DeepSeekWebSearchTool;pub use builtin::ExitLoopTool;pub use builtin::GeminiCodeExecutionTool;pub use builtin::GeminiComputerEnvironment;pub use builtin::GeminiComputerUseTool;pub use builtin::GeminiFileSearchTool;pub use builtin::GoogleMapsContext;pub use builtin::GoogleMapsTool;pub use builtin::GoogleSearchTool;pub use builtin::LoadArtifactsTool;pub use builtin::OpenAIApplyPatchTool;pub use builtin::OpenAIApproximateLocation;pub use builtin::OpenAICodeInterpreterTool;pub use builtin::OpenAIComputerEnvironment;pub use builtin::OpenAIComputerUseTool;pub use builtin::OpenAIFileSearchTool;pub use builtin::OpenAIImageGenerationTool;pub use builtin::OpenAILocalShellTool;pub use builtin::OpenAIMcpTool;pub use builtin::OpenAIShellTool;pub use builtin::OpenAIWebSearchTool;pub use builtin::UrlContextTool;pub use builtin::WebSearchTool;pub use builtin::WebSearchUserLocation;pub use example_store::ExampleStoreClient;pub use example_store::ExampleStoreConfig;pub use example_store::ExampleStoreProvider;pub use mcp::AutoDeclineElicitationHandler;pub use mcp::ElicitationHandler;pub use mcp::McpAuth;pub use mcp::McpDiscoveryLimits;pub use mcp::McpHttpClientBuilder;pub use mcp::McpSchemaLimits;pub use mcp::McpServerManager;pub use mcp::McpTaskConfig;pub use mcp::McpToolset;pub use mcp::OAuth2Config;pub use mcp::ResourceNotificationHandler;pub use toolset::BasicToolset;pub use toolset::FilteredToolset;pub use toolset::MergedToolset;pub use toolset::PrefixedToolset;pub use toolset::string_predicate;pub use vertex::agent_registry::AgentRegistryClient;pub use vertex::agent_registry::AgentRegistryConfig;pub use vertex::agent_registry::AgentSearchTool;pub use code_execution::FrontendCodeTool;pub use code_execution::JavaScriptCodeTool;pub use code_execution::PythonCodeTool;pub use code_execution::MontyPythonCodeTool;pub use code_execution::MontyPythonCodeToolBuilder;
Modules§
- advisor
- Advisor consultation: a tool an agent calls to ask a stronger or different model for advice mid-task.
- bigquery
- Native BigQuery toolset for ADK agents.
- builtin
- Built-in tool wrappers for Gemini, OpenAI, and Anthropic hosted tools.
- code_
execution - Code execution tools for ADK agents.
- example_
store - Vertex AI Example Store client and few-shot retrieval provider.
- mcp
- Model Context Protocol (MCP) clients, server SDK re-export, catalog APIs, elicitation, tasks, HTTP transport, and dynamic local-server management.
- memory
- Memory tools for ADK agents.
- sampling
- MCP sampling callback support for ADK agents.
- slack
- Native Slack toolset for ADK agents.
- spanner
- Native Spanner toolset for ADK agents.
- toolset
- Toolset combinators: basic, filtered, merged, and prefixed toolsets.
- vertex
- Hosted Google Cloud registry integrations for agent tooling.
Structs§
- AdkError
- Unified structured error type for all ADK-Rust operations.
- Agent
Tool - AgentTool wraps an Agent to make it callable as a Tool.
- Agent
Tool Config - Configuration options for AgentTool behavior.
- Code
Tool - Re-export
adk_code::CodeToolas the recommended code execution tool. A tool that executes code through language-specific pipelines. - Function
Tool - A tool created from an async Rust function.
- Resource
- A known resource that the server is capable of reading (spec
Resource). - Resource
Template - A template description for resources available on the server (spec
ResourceTemplate). - Simple
Tool Context - A lightweight
ToolContextwith sensible defaults for non-agent callers. - Stateful
Tool - A generic tool wrapper that manages shared state for stateful closures.
- Tool
Argument Validator - Validates tool-call arguments against a JSON Schema.
Enums§
- Agent
Tool Failure Mode - Controls how an
AgentToolreports delegated execution failures. - Agent
Tool Session Snapshot - Controls which parent session data is copied into an agent-tool invocation.
- Agent
Tool State Merge Policy - Merge behavior for state produced by an agent-as-tool invocation.
- Error
Category - The kind of failure independent of subsystem.
- Error
Component - The subsystem that produced the error — the origin, not the boundary it surfaces through.
- Resource
Contents - The contents of a specific resource or sub-resource.
- Tool
Effect - The side-effect class of a tool, reported by
Tool::effect.
Constants§
- TOOL_
INVALID_ ARGUMENTS_ CODE - The error code for a call whose arguments do not fit the tool.
- TOOL_
INVALID_ PARAMETERS_ SCHEMA_ CODE - The error code for a tool whose parameters schema does not compile.
Traits§
- Tool
- The core trait for all tools that agents can invoke.
- Tool
Context - Context available to tools during execution.
- Toolset
- A collection of tools that can be resolved dynamically from context.
Functions§
- close_
object_ schemas - Sets
additionalProperties: falseon each object schema inschemathat declares all of its fields, so a validator rejects keys the schema does not name. - coerce_
integral_ floats - Rewrites each integral float in
argsat a positionschematypes as an integer, so3.0becomes3. - model_
facing_ schema - Reduces a schema generated for a
#[tool]argument type to the form sent to the model.
Type Aliases§
- Result
- Convenience alias used throughout ADK crates.
Attribute Macros§
- async_
trait - tool
- Attribute macro that generates a
Toolimplementation from an async function.