Expand description
Agent SDK - A Rust SDK for building LLM-powered agents.
This crate provides the building blocks for creating AI agents with:
- Tool execution and lifecycle hooks
- Streaming event-based architecture
- Provider-agnostic LLM interface
- Built-in primitive tools for file operations
§Example
ⓘ
use agent_sdk::{builder, ToolContext, ThreadId, providers::AnthropicProvider};
// Build agent with defaults (in-memory stores, default hooks)
let agent = builder()
.provider(AnthropicProvider::sonnet(api_key))
.build();
// Run the agent
let thread_id = ThreadId::new();
let tool_ctx = ToolContext::new(());
let mut events = agent.run(thread_id, "Hello!".to_string(), tool_ctx);
while let Some(event) = events.recv().await {
println!("{:?}", event);
}§Custom Configuration
ⓘ
use agent_sdk::{builder, AgentConfig, ToolRegistry, providers::AnthropicProvider};
let agent = builder()
.provider(AnthropicProvider::sonnet(api_key))
.tools(my_tools)
.config(AgentConfig {
max_turns: 20,
system_prompt: "You are a helpful assistant.".to_string(),
..Default::default()
})
.build();§Custom Stores and Hooks
ⓘ
use agent_sdk::builder;
let agent = builder()
.provider(my_provider)
.hooks(my_hooks)
.message_store(my_message_store)
.state_store(my_state_store)
.build_with_stores();Re-exports§
pub use llm::LlmProvider;
Modules§
- context
- Context compaction for long-running conversations.
- llm
- mcp
- Model Context Protocol (MCP) client support.
- primitive_
tools - Primitive tools that work with the Environment abstraction.
- providers
- LLM Provider implementations.
- skills
- Skills system for loading agent behavior from markdown files.
- subagent
- Subagent support for spawning child agents.
- web
- Web tools for search and fetching.
Structs§
- Agent
Capabilities - Capabilities that control what the agent can do.
- Agent
Config - Configuration for the agent loop
- Agent
Loop - The main agent loop that orchestrates LLM calls and tool execution.
- Agent
Loop Builder - Builder for constructing an
AgentLoop. - Agent
State - Snapshot of agent state for checkpointing
- Allow
AllHooks - Hooks that allow all tools without confirmation
- Default
Hooks - Default hooks implementation that uses tier-based decisions
- Exec
Result - Result from command execution
- File
Entry - Entry in a directory listing
- Grep
Match - Match result from grep operation
- InMemory
File System - In-memory filesystem for testing
- InMemory
Store - In-memory implementation of
MessageStoreandStateStore. Useful for testing and simple use cases. - Local
File System - Local filesystem implementation using
std::fs - Logging
Hooks - Hooks that log all events (useful for debugging)
- Null
Environment - A null environment that rejects all operations. Useful as a default when no environment is configured.
- Pending
Action - State of a pending action that requires confirmation or PIN
- Retry
Config - Configuration for retry behavior on transient errors.
- Thread
Id - Unique identifier for a conversation thread
- Token
Usage - Token usage statistics
- Tool
Context - Context passed to tool execution
- Tool
Registry - Registry of available tools
- Tool
Result - Result of a tool execution
Enums§
- Agent
Event - Events emitted by the agent loop during execution. These are streamed to the client for real-time UI updates.
- Tool
Decision - Decision returned by pre-tool hooks
- Tool
Tier - Permission tier for tools
Traits§
- Agent
Hooks - Lifecycle hooks for the agent loop. Implement this trait to customize agent behavior.
- Environment
- Environment abstraction for file and command operations.
- Message
Store - Trait for storing and retrieving conversation messages. Implement this trait to persist messages to your storage backend.
- State
Store - Trait for storing agent state checkpoints. Implement this to enable conversation recovery and resume.
- Tool
- Definition of a tool that can be called by the agent
Functions§
- builder
- Create a new builder for constructing an
AgentLoop.