AI Agent SDK (Rust)
One to one Rust translation of claude code source.
Idiomatic agent sdk inspired by the claude code source leak, written in Rust that runs the full agent loop in-process — no subprocess or CLI required. Deploy anywhere: cloud, serverless, Docker, CI/CD.
Quick Demo
use Agent;
let mut agent = new;
let result = agent.prompt.await?;
println!;
That's it! The agent automatically uses 20+ built-in tools (Bash, Read, Write, Edit, Glob, Grep, WebFetch, etc.) to accomplish tasks.
Core Features
| Feature | Description |
|---|---|
| Agent | Create agents with custom models, tools, and prompts |
| Subagent | Spawn subagents for parallel or specialized tasks |
| Session | Persist, resume, fork conversations on disk |
| Skills | Load external skills or use 15+ bundled skills |
| Plugin | Load plugins with commands, skills, MCP servers |
| Hooks | 20+ lifecycle events for custom workflows |
| Tools | 20+ built-in tools + custom tool registration |
| Memory | Automatic session memory management |
Quick Start
Install:
Configure your API key:
Or use .env file:
AI_AUTH_TOKEN=your-token
AI_MODEL=MiniMaxAI/MiniMax-M2.5
AI_BASE_URL=https://api.minimax.chat/v1
Simple Prompt
use Agent;
let mut agent = new;
let result = agent.prompt.await?;
println!;
Multi-turn Conversation
use Agent;
let mut agent = new;
let r1 = agent.prompt.await?;
let r2 = agent.prompt.await?;
println!;
Custom Tools
use ;
+ Send
let calculator = Tool ;
let mut agent = new;
// Note: Tool registration via agent tools currently uses ToolDefinition
MCP Servers
use ;
let config = Stdio;
let mut agent = new;
// Note: MCP servers configured via AgentOptions
Subagents
use ;
let mut agent = new;
// Note: Subagents are used via the Agent tool at runtime
Skills
use ;
let skill = load_skill_from_dir?;
let mut agent = new;
// Note: Skills are applied via agent configuration
Plugin System
use ;
let plugin = load_plugin.await?;
let plugins = load_plugins_from_dir.await?;
let registry = new;
Hooks
use ;
let mut registry = new;
registry.register;
let mut input = new;
input.tool_name = Some;
let results = registry.execute.await;
Configuration
Options
| Option | Type | Default | Description |
|---|---|---|---|
model |
string | MiniMaxAI/MiniMax-M2.5 | LLM model ID |
api_key |
string | env var | API key |
base_url |
string | — | Custom API endpoint |
cwd |
string | process.cwd() | Working directory |
max_turns |
u32 | 10 | Max agentic turns |
max_budget_usd |
f64 | — | Spending cap |
max_tokens |
u32 | 16384 | Max response tokens |
tools |
Vec | All built-in | Available tools |
allowed_tools |
Vec | — | Tool allow-list |
disallowed_tools |
Vec | — | Tool deny-list |
Environment Variables
| Variable | Description |
|---|---|
AI_AUTH_TOKEN |
API authentication token (required) |
AI_MODEL |
Model name |
AI_BASE_URL |
API endpoint |
AI_CONTEXT_WINDOW |
Override context window size |
AI_DISABLE_AUTO_MEMORY |
Disable auto memory |
AI_MEMORY_PATH_OVERRIDE |
Override memory directory |
Built-in Tools
| Tool | Description |
|---|---|
| Bash | Execute shell commands |
| Read | Read files with line numbers |
| Write | Create / overwrite files |
| Edit | Precise string replacement |
| Glob | Find files by pattern |
| Grep | Search with regex |
| WebFetch | Fetch web content |
| WebSearch | Web search |
| NotebookEdit | Edit Jupyter cells |
| Agent | Spawn subagents |
| TaskCreate/List/Update/Get | Task management |
| TeamCreate/Delete | Multi-agent teams |
| SendMessage | Inter-agent messaging |
| EnterWorktree/ExitWorktree | Git worktree |
| EnterPlanMode/ExitPlanMode | Planning workflow |
| AskUserQuestion | Request user input |
| CronCreate/Delete/List | Scheduled tasks |
| TodoWrite | Session todo list |
Architecture
┌─────────────────────────────────────┐
│ Your Application │
│ use ai_agent_sdk::Agent │
└──────────────┬──────────────────────┘
│
┌──────────▼──────────┐
│ Agent │ Session state, tools
│ prompt() │ MCP connections
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ QueryEngine │ Agent loop:
│ submitMessage() │ API → tools → repeat
└──────────┬──────────┘
│
┌──────────┼──────────┐
│ │ │
┌───▼───┐ ┌───▼───┐ ┌──▼────┐
│ LLM │ │ 20+ │ │ MCP │
│ API │ │Tools │ │Server │
└───────┘ └───────┘ └───────┘
Examples
Run examples from examples/ directory:
# Configure your .env first
License
MIT