Tool system
Defining tools
Define tools using JSON Schema:Implementing AgentToolDispatcher
TheAgentToolDispatcher trait connects your tools to the agent:
ToolRegistry (dynamic registration)
ToolRegistry (dynamic registration)
For dynamic tool registration:
Multimodal tool results
Built-in tools returnToolOutput, which supports both JSON and multimodal content:
ToolOutput::Json is serialized into a text content block in the tool result. ToolOutput::Blocks passes content blocks directly into ToolResult.content, enabling tools to return images and other rich content to vision-capable models.
The built-in view_image tool uses this mechanism to read image files from disk and return them as ContentBlock::Image blocks. It is automatically hidden from models that lack vision or image tool result support.
Session stores
- JsonlStore
- MemoryStore
File-based persistence using JSONL format:
Implementing a custom store
Implementing a custom store
Implement the
SessionStore trait and pass it to AgentFactory::session_store(). Then build a runtime-backed SessionService so the custom store participates in the canonical session lifecycle instead of only a one-off direct agent.Prefer
SessionStore + session_store() over implementing AgentSessionStore directly.
SessionStore is the richer trait (with list, delete, exists) and AgentFactory
automatically wraps it via StoreAdapter. Implementing AgentSessionStore directly
bypasses the factory and loses runtime-backed session orchestration.MCP integration
Route tool calls across multiple MCP servers:See also
- Rust SDK overview - getting started, sessions, events
- Rust SDK advanced - expert-only direct agent construction, providers, hooks
- Tools concept - how the tool system works
