Skip to main content

Crate agentkit_provider_anthropic

Crate agentkit_provider_anthropic 

Source
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§

AnthropicAdapter
Model adapter that connects the agentkit agent loop to the Anthropic Messages API.
AnthropicConfig
Configuration for connecting to the Anthropic Messages API.
AnthropicMcpServer
MCP server descriptor passed through to Anthropic’s mcp_servers array.
AnthropicSession
An active session with the Anthropic Messages API.
AnthropicTurn
A turn in progress against the Messages API.
BashCodeExecutionTool
Anthropic server-side bash execution sandbox.
CodeExecutionTool
Anthropic server-side Python code execution sandbox.
RawServerTool
Passthrough wrapper for any server tool Anthropic has shipped but this crate has not yet added first-class support for.
TextEditorCodeExecutionTool
Anthropic server-side text editor sandbox.
WebFetchTool
Anthropic server-side web fetch.
WebSearchTool
Anthropic server-side web search.

Enums§

AnthropicError
Errors produced by the Anthropic adapter.
OutputEffort
Relative reasoning effort hint.
OutputFormat
Structured output format constraint.
ServiceTier
Priority/standard routing hint.
ThinkingConfig
Extended thinking configuration.
ToolChoice
Constraint applied to the model’s tool-choice behaviour.

Constants§

DEFAULT_ANTHROPIC_VERSION
Default anthropic-version header.
DEFAULT_BASH_EXECUTION_VERSION
The default type version string for BashCodeExecutionTool.
DEFAULT_CODE_EXECUTION_VERSION
The default type version string for CodeExecutionTool.
DEFAULT_ENDPOINT
Default Messages API endpoint.
DEFAULT_TEXT_EDITOR_EXECUTION_VERSION
The default type version string for TextEditorCodeExecutionTool.
DEFAULT_WEB_FETCH_VERSION
The default type version string for WebFetchTool.
DEFAULT_WEB_SEARCH_VERSION
The default type version string for WebSearchTool.

Traits§

ServerTool
A server-side tool definition appended to the tools array of a Messages API request.

Functions§

boxed
Wraps any ServerTool as an Arc so it can live in AnthropicConfig.

Type Aliases§

ServerToolHandle
Convenience alias for an owned, clonable handle to a ServerTool.