Expand description
Anthropic Messages API adapter for the agentkit agent loop.
This crate implements the agentkit ModelAdapter directly against
Anthropic’s /v1/messages endpoint. The API is not OpenAI-compatible
(different message shape, system is top-level, tool results live as
content blocks inside user messages, etc.), so the generic completions
adapter is not reused.
Streaming is on by default: the adapter consumes Anthropic’s SSE response
and yields ModelTurnEvents as tokens arrive. Call
[AnthropicConfig::with_streaming(false)] to opt out in favour of a single
buffered request.
§Quick start
ⓘ
use agentkit_loop::{Agent, SessionConfig};
use agentkit_provider_anthropic::{AnthropicAdapter, AnthropicConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AnthropicConfig::from_env()?;
let adapter = AnthropicAdapter::new(config)?;
let agent = Agent::builder().model(adapter).build()?;
let _driver = agent.start(SessionConfig::new("demo")).await?;
Ok(())
}Structs§
- Anthropic
Adapter - Model adapter that connects the agentkit agent loop to the Anthropic Messages API.
- Anthropic
Config - Configuration for connecting to the Anthropic Messages API.
- Anthropic
McpServer - MCP server descriptor passed through to Anthropic’s
mcp_serversarray. - Anthropic
Session - An active session with the Anthropic Messages API.
- Anthropic
Turn - A turn in progress against the Messages API.
- Bash
Code Execution Tool - Anthropic server-side bash execution sandbox.
- Code
Execution Tool - Anthropic server-side Python code execution sandbox.
- RawServer
Tool - Passthrough wrapper for any server tool Anthropic has shipped but this crate has not yet added first-class support for.
- Text
Editor Code Execution Tool - Anthropic server-side text editor sandbox.
- WebFetch
Tool - Anthropic server-side web fetch.
- WebSearch
Tool - Anthropic server-side web search.
Enums§
- Anthropic
Error - Errors produced by the Anthropic adapter.
- Output
Effort - Relative reasoning effort hint.
- Output
Format - Structured output format constraint.
- Service
Tier - Priority/standard routing hint.
- Thinking
Config - Extended thinking configuration.
- Tool
Choice - Constraint applied to the model’s tool-choice behaviour.
Constants§
- DEFAULT_
ANTHROPIC_ VERSION - Default
anthropic-versionheader. - DEFAULT_
BASH_ EXECUTION_ VERSION - The default
typeversion string forBashCodeExecutionTool. - DEFAULT_
CODE_ EXECUTION_ VERSION - The default
typeversion string forCodeExecutionTool. - DEFAULT_
ENDPOINT - Default Messages API endpoint.
- DEFAULT_
TEXT_ EDITOR_ EXECUTION_ VERSION - The default
typeversion string forTextEditorCodeExecutionTool. - DEFAULT_
WEB_ FETCH_ VERSION - The default
typeversion string forWebFetchTool. - DEFAULT_
WEB_ SEARCH_ VERSION - The default
typeversion string forWebSearchTool.
Traits§
- Server
Tool - A server-side tool definition appended to the
toolsarray of a Messages API request.
Functions§
- boxed
- Wraps any
ServerToolas anArcso it can live inAnthropicConfig.
Type Aliases§
- Server
Tool Handle - Convenience alias for an owned, clonable handle to a
ServerTool.