Crate agent_sdk

Crate agent_sdk 

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

AgentCapabilities
Capabilities that control what the agent can do.
AgentConfig
Configuration for the agent loop
AgentLoop
The main agent loop that orchestrates LLM calls and tool execution.
AgentLoopBuilder
Builder for constructing an AgentLoop.
AgentState
Snapshot of agent state for checkpointing
AllowAllHooks
Hooks that allow all tools without confirmation
DefaultHooks
Default hooks implementation that uses tier-based decisions
ExecResult
Result from command execution
FileEntry
Entry in a directory listing
GrepMatch
Match result from grep operation
InMemoryFileSystem
In-memory filesystem for testing
InMemoryStore
In-memory implementation of MessageStore and StateStore. Useful for testing and simple use cases.
LocalFileSystem
Local filesystem implementation using std::fs
LoggingHooks
Hooks that log all events (useful for debugging)
NullEnvironment
A null environment that rejects all operations. Useful as a default when no environment is configured.
PendingAction
State of a pending action that requires confirmation or PIN
RetryConfig
Configuration for retry behavior on transient errors.
ThreadId
Unique identifier for a conversation thread
TokenUsage
Token usage statistics
ToolContext
Context passed to tool execution
ToolRegistry
Registry of available tools
ToolResult
Result of a tool execution

Enums§

AgentEvent
Events emitted by the agent loop during execution. These are streamed to the client for real-time UI updates.
ToolDecision
Decision returned by pre-tool hooks
ToolTier
Permission tier for tools

Traits§

AgentHooks
Lifecycle hooks for the agent loop. Implement this trait to customize agent behavior.
Environment
Environment abstraction for file and command operations.
MessageStore
Trait for storing and retrieving conversation messages. Implement this trait to persist messages to your storage backend.
StateStore
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.