Skip to main content

Crate agent_sdk

Crate agent_sdk 

Source
Expand description

§Agent SDK - Claude Agent SDK for Rust

Build production AI agents with Claude. This is a Rust port of the Claude Agent SDK.

§Quick Start

use agent_sdk::{query, Options, Message};
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut stream = query(
        "What files are in this directory?",
        Options::builder()
            .allowed_tools(vec!["Bash".into(), "Glob".into()])
            .build(),
    );

    while let Some(message) = stream.next().await {
        let message = message?;
        if let Message::Result(result) = &message {
            println!("{}", result.result.as_deref().unwrap_or(""));
        }
    }
    Ok(())
}

Re-exports§

pub use error::AgentError;
pub use mcp::McpHttpServerConfig;
pub use mcp::McpServerConfig;
pub use mcp::McpSseServerConfig;
pub use mcp::McpStdioServerConfig;
pub use models::ModelRegistry;
pub use models::PricingRegistry;
pub use options::CustomToolDefinition;
pub use options::ExternalToolHandlerFn;
pub use options::Options;
pub use options::OptionsBuilder;
pub use options::PermissionMode;
pub use options::PreCompactHandlerFn;
pub use options::QueryAttachment;
pub use provider::CostRates;
pub use provider::LlmProvider;
pub use provider::ProviderCapabilities;
pub use providers::AnthropicProvider;
pub use providers::BedrockProvider;
pub use providers::GeminiProvider;
pub use providers::OllamaDiscovery;
pub use providers::OpenAiProvider;
pub use providers::VertexProvider;
pub use query::query;
pub use query::Query;
pub use session::Session;
pub use session::SessionInfo;
pub use tools::executor::ToolResult;
pub use types::agent::AgentDefinition;
pub use types::agent::AgentInput;
pub use types::messages::*;
pub use types::tools::*;

Modules§

client
Canonical API types for the Messages API.
compact
Conversation compaction — summarize older messages when approaching context limits.
error
hooks
Hook system — re-exported from the starpod-hooks crate.
mcp
models
Centralized model catalog with pricing, capabilities, and provider metadata.
options
permissions
Permission evaluation engine.
pricing
Backward-compatible alias for models.
provider
LLM provider trait and shared types.
providers
LLM provider implementations.
query
The query function and agent loop implementation.
sanitize
Tool result sanitization.
session
tools
Built-in tool definitions and execution.
types

Structs§

HookCallbackMatcher
Hook configuration with optional regex matcher pattern.
HookRegistry
A registry of hooks keyed by event type.

Enums§

HookEvent
Available hook event types.
HookInput
Union of all hook input types, tagged by event name.
HookOutput
Hook return value — either async (fire-and-forget) or sync (blocking).

Functions§

hook_fn
Helper to create a HookCallback from an async function.

Type Aliases§

HookCallback
Type alias for hook callback functions.