Skip to main content

Tool system

Defining tools

Define tools using JSON Schema:

Implementing AgentToolDispatcher

The AgentToolDispatcher trait connects your tools to the agent:
For dynamic tool registration:

Multimodal tool results

Tool results can carry either plain text or multimodal content blocks:
ToolResult::new(...) creates a text-only result. ToolResult::with_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 the same content-block 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

File-based persistence using JSONL format:
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.For runtime-backed persistent services, realm persistence still flows through the PersistenceBundle opened for that realm. Treat custom SessionStore implementations as a storage seam for custom builders or direct agent/store integration, not as a drop-in replacement for the entire runtime persistence bundle.

MCP integration

Route tool calls across multiple MCP servers:

See also