Expand description
Tool definition and registry.
Tools allow the LLM to perform actions in the real world. This module provides:
Tooltrait - Define custom tools the LLM can callToolNametrait - Marker trait for strongly-typed tool namesPrimitiveToolName- Tool names for SDK’s built-in toolsDynamicToolName- Tool names created at runtime (MCP bridges)ToolRegistry- Collection of available toolsToolContext- Context passed to tool executionListenExecuteTool- Tools that listen for updates, then execute later
§Implementing a Tool
ⓘ
use agent_sdk::{Tool, ToolContext, ToolResult, ToolTier, PrimitiveToolName};
struct MyTool;
// No #[async_trait] needed - Rust 1.75+ supports native async traits
impl Tool<MyContext> for MyTool {
type Name = PrimitiveToolName;
fn name(&self) -> PrimitiveToolName { PrimitiveToolName::Read }
fn display_name(&self) -> &'static str { "My Tool" }
fn description(&self) -> &'static str { "Does something useful" }
fn input_schema(&self) -> Value { json!({ "type": "object" }) }
fn tier(&self) -> ToolTier { ToolTier::Observe }
async fn execute(&self, ctx: &ToolContext<MyContext>, input: Value) -> Result<ToolResult> {
Ok(ToolResult::success("Done!"))
}
}Structs§
- Dynamic
Tool Name - Dynamic tool name for runtime-created tools (MCP bridges, subagents).
- Simple
Tool Adapter - Adapter that turns any
SimpleToolinto a fullToolwithName = DynamicToolName. - Tool
Context - Context passed to tool execution
- Tool
Registry - Registry of available tools.
- Typed
Tool Adapter - Adapter that turns any
TypedToolinto a fullTool.
Enums§
- Erased
Tool Status - Type-erased status for the agent loop.
- Listen
Stop Reason - Reason for stopping a listen session.
- Listen
Tool Update - Update emitted from a
listen()stream. - Primitive
Tool Name - Tool names for SDK’s built-in primitive tools.
- Tool
Status - Status update from an async tool operation.
Traits§
- Async
Tool - A tool that performs long-running async operations.
- Erased
Async Tool - Type-erased async tool trait for registry storage.
- Erased
Listen Tool - Type-erased listen/execute tool trait for registry storage.
- Erased
Tool - Type-erased tool trait for registry storage.
- Listen
Execute Tool - A tool whose runtime has two phases:
- Progress
Stage - Marker trait for tool progress stages (type-safe, like
ToolName). - Simple
Tool - An ergonomic
Toolwhose name is a plain string. - Tool
- Definition of a tool that can be called by the agent.
- Tool
Logic - The
execute-only half of a tool, used as the target of the#[derive(Tool)]/#[derive(TypedTool)]ergonomics macros. - Tool
Name - Marker trait for tool names.
- Typed
Tool - A tool whose model-emitted arguments are validated against a typed,
deserializable
Inputbeforeexecuteruns.
Functions§
- invalid_
tool_ input_ result - Synthesise the structured validation-error
ToolResultreturned to the model when its arguments fail to deserialize into aTypedTool::Input. - stage_
to_ string - Helper to get string representation of a progress stage via serde.
- tool_
name_ from_ str - Parse a tool name from string via serde.
- tool_
name_ to_ string - Helper to get string representation of a tool name via serde.
- validate_
tool_ input - Deserialize raw model args into a typed
Input, or synthesise the structured validation-error result.