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-hookscrate. - 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§
- Hook
Callback Matcher - Hook configuration with optional regex matcher pattern.
- Hook
Registry - A registry of hooks keyed by event type.
Enums§
- Hook
Event - Available hook event types.
- Hook
Input - Union of all hook input types, tagged by event name.
- Hook
Output - Hook return value — either async (fire-and-forget) or sync (blocking).
Functions§
- hook_fn
- Helper to create a
HookCallbackfrom an async function.
Type Aliases§
- Hook
Callback - Type alias for hook callback functions.