What are Deep Agents?
Deep Agents is an architecture pioneered by LangChain for building agents that can tackle complex, multi-step tasks. Inspired by applications like Claude Code, Deep Research, and Manus, deep agents go beyond simple ReAct loops with:
| Capability | Description |
|---|---|
| Planning & Task Decomposition | Built-in write_todos tool to break down complex tasks into discrete steps |
| Context Management | File system tools (ls, read_file, write_file, edit_file) to manage large context |
| Sub-Agent Spawning | Delegate work to specialized sub-agents for context isolation |
| Long-Term Memory | Persist memory across conversations and threads |
This SDK brings the Deep Agents architecture to Rust, with type safety, native performance, and memory safety.
Why Rust for Deep Agents?
Building AI agents shouldn't mean sacrificing performance or type safety. While Python frameworks dominate the AI space, Rust Deep Agents SDK brings the reliability and speed of Rust to agent development.
Comparison with Alternatives
| Feature | Rust Deep Agents | LangChain | CrewAI | AutoGen |
|---|---|---|---|---|
| Language | Rust | Python | Python | Python |
| Type Safety | Compile-time | Runtime | Runtime | Runtime |
| Performance | Native speed | Interpreted | Interpreted | Interpreted |
| Memory Safety | Guaranteed | GC-dependent | GC-dependent | GC-dependent |
| Async/Concurrent | Tokio-native | asyncio | asyncio | asyncio |
| Tool Macro | #[tool] |
Decorators | Decorators | Manual |
| Token Tracking | Built-in | Callbacks | Manual | Manual |
| HITL Workflows | Native | Plugin | Limited | Plugin |
| PII Protection | Automatic | Manual | Manual | Manual |
Ideal Use Cases
- Enterprise applications requiring reliability and compliance
- High-throughput systems processing thousands of agent requests
- Security-critical environments where memory safety matters
- Cloud-native deployments on AWS Lambda, ECS, or Kubernetes
- Rust teams who want AI capabilities without Python dependencies
Features
Multi-Provider LLM Support
The SDK is model-agnostic — pass any model string supported by the provider:
- OpenAI: Any model (e.g.,
gpt-5.2,gpt-4o,o1-pro,gpt-4o-mini) - Anthropic: Any model (e.g.,
claude-opus-4.5,claude-sonnet-4.5,claude-haiku-4.5) - Google Gemini: Any model (e.g.,
gemini-2.5-pro,gemini-2.5-flash,gemini-2.0-flash)
Ergonomic Tool System
#[tool]macro for zero-boilerplate tool definitions- Automatic JSON Schema generation
- Support for sync and async tools
Flexible Persistence
- In-memory storage for development
- Redis for production deployments
- PostgreSQL for enterprise environments
- DynamoDB for AWS-native architectures
Token Tracking and Cost Control
- Real-time usage monitoring
- Cost estimation per request
- Budget alerts and limits
Human-in-the-Loop (HITL)
- Configurable approval workflows
- Tool-level interrupt policies
- Audit trail for compliance
Enterprise Security
- Automatic PII sanitization
- Sensitive field redaction
- Compliance-ready event logging
Token Optimization with TOON Format
- TOON (Token-Oriented Object Notation) support for 30-60% token reduction
- Compact, human-readable data serialization
- Feature-gated opt-in via
toonfeature flag
Quick Start
Installation
Add to your Cargo.toml:
[]
= "0.0.29"
= { = "1.0", = ["full"] }
= "1.0"
Your First Agent
use ;
use AgentStateSnapshot;
use tool;
use Arc;
// Define a tool with a simple macro
async
Examples
Explore comprehensive examples demonstrating SDK capabilities:
| Example | Description | Complexity |
|---|---|---|
simple-agent |
Basic agent with OpenAI | Beginner |
tool-test |
Custom tools with #[tool] macro |
Beginner |
anthropic-tools-test |
Using Claude models | Beginner |
gemini-tools-test |
Using Gemini models | Beginner |
token-tracking-demo |
Monitor usage and costs | Intermediate |
event-system-demo |
Real-time event broadcasting | Intermediate |
checkpointer-demo |
State persistence | Intermediate |
hitl-demo |
Human-in-the-loop basics | Intermediate |
hitl-financial-advisor |
Production HITL workflow | Advanced |
subagent-demo |
Multi-agent delegation | Advanced |
streaming-events-demo |
SSE/WebSocket streaming | Advanced |
automotive-web-service |
Full-stack web application | Advanced |
toon-format-demo |
Token-efficient TOON format | Intermediate |
Running Examples
Architecture
rust-deep-agents-sdk/
├── crates/
│ ├── agents-core/ # Core traits, messages, state models
│ ├── agents-runtime/ # Execution engine, builders, middleware
│ ├── agents-toolkit/ # Built-in tools and utilities
│ ├── agents-macros/ # #[tool] procedural macro
│ ├── agents-sdk/ # Unified SDK with feature flags
│ ├── agents-aws/ # AWS integrations (DynamoDB, Secrets)
│ └── agents-persistence/ # Redis, PostgreSQL backends
├── examples/ # Working examples and demos
├── docs/ # Documentation and guides
└── deploy/ # Terraform modules for AWS
Provider Support
The SDK is model-agnostic — you can use any model string supported by the provider's API.
| Provider | Example Models | Status |
|---|---|---|
| OpenAI | gpt-5.2, gpt-4o, o1-pro, o1-mini, gpt-4o-mini |
Stable |
| Anthropic | claude-opus-4.5, claude-sonnet-4.5, claude-haiku-4.5 |
Stable |
| Google Gemini | gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash |
Stable |
Note: Model availability depends on your API access. The SDK passes your model string directly to the provider — any model they support will work.
Middleware Stack
The SDK includes a composable middleware system:
- Token Tracking — Usage and cost monitoring
- HITL — Human approval workflows
- Planning — Todo list management
- Summarization — Context window management
- PII Sanitization — Automatic data protection
- SubAgent — Task delegation to specialized agents
Advanced Usage
use ;
use Arc;
// OpenAI
let openai = new;
// Anthropic Claude
let claude = new;
// Google Gemini
let gemini = new;
// Use any provider with the same builder API
let agent = new
.with_model
.build?;
use ;
let token_config = TokenTrackingConfig ;
let agent = new
.with_model
.with_token_tracking_config
.build?;
use ;
use HashMap;
let mut policies = new;
policies.insert;
// Use with_tool_interrupt() for each tool requiring approval
let agent = new
.with_model
.with_tool_interrupt
.with_checkpointer
.build?;
// Handle interrupts
if let Some = agent.current_interrupt.await?
use ;
use RedisCheckpointer;
use Arc;
// Development: In-memory
let checkpointer = new;
// Production: Redis
let checkpointer = new;
let agent = new
.with_model
.with_checkpointer
.build?;
// Save and restore conversation state
let thread_id = "user-123";
agent.save_state.await?;
agent.load_state.await?;
use ;
use AgentEvent;
use async_trait;
let agent = new
.with_model
.with_event_broadcaster
.build?;
use ;
let researcher = new;
let writer = new;
// Use with_subagent_config() to add sub-agents
let agent = new
.with_model
.with_subagent_config
.with_auto_general_purpose
.build?;
TOON (Token-Oriented Object Notation) is a compact data format that reduces token usage by 30-60% compared to JSON. Enable it for cost savings and faster responses:
use ;
let agent = new
.with_model
.with_prompt_format // Enable TOON format
.build?;
You can also encode data directly:
use ToonEncoder;
use json;
let encoder = new;
let data = json!;
// TOON output is ~40% smaller than JSON
let toon_string = encoder.encode?;
// users[2]{id,name,role}:
// 1,Alice,admin
// 2,Bob,user
See the TOON Format Guide and toon-format-demo for more details.
Feature Flags
[]
# Default: includes toolkit
= "0.0.29"
# Minimal: core only
= { = "0.0.29", = false }
# With persistence
= { = "0.0.29", = ["redis"] }
= { = "0.0.29", = ["postgres"] }
# With AWS
= { = "0.0.29", = ["aws", "dynamodb"] }
# With TOON format (token optimization)
= { = "0.0.29", = ["toon"] }
# Everything
= { = "0.0.29", = ["full"] }
| Feature | Description |
|---|---|
toolkit |
Built-in tools (default) |
toon |
TOON format for token-efficient prompts |
redis |
Redis persistence backend |
postgres |
PostgreSQL persistence backend |
dynamodb |
DynamoDB persistence backend |
aws |
AWS integrations (Secrets Manager, etc.) |
full |
All features enabled |
Development
Environment Variables
# Optional: for web search
Contributing
We welcome contributions of all kinds:
- Bug reports and fixes
- Feature requests and implementations
- Documentation improvements
- Test coverage
Please read our Contributing Guide to get started.
New contributors can look for issues labeled good first issue.
Roadmap
Providers
- AWS Bedrock provider (Claude, Titan, Llama)
- Ollama for local/self-hosted models
- Azure OpenAI Service
Features
- Custom sub-agent execution graphs
- Advanced state features (encryption, migrations)
- Enhanced tool composition and validation
- WebAssembly support
- OpenTelemetry integration
See the full roadmap for details.
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.