Rust Deep Agents SDK
High-performance Rust framework for composing reusable "deep" AI agents with custom tools, sub-agents, and prompts. This repository contains the SDK workspace, AWS integration helpers, documentation, and deployment scaffolding.
Workspace Layout
crates/agents-core
– Domain traits, message structures, prompt packs, and state models.crates/agents-runtime
– Tokio-powered runtime glue between planners, tools, and state stores.crates/agents-toolkit
– Built-in tools (mock filesystem, todo management) and utilities.crates/agents-aws
– AWS adapters (Secrets Manager, DynamoDB, CloudWatch) behind feature flags.examples/
– Reference agents;getting-started
provides the echo smoke test.agents-example-cli
provides a local CLI harness using OpenAI.
deploy/
– Terraform modules and IaC assets for AWS environments.docs/
– Roadmap, ADRs, playbooks, and reference material.
Installation
Add the unified SDK to your Cargo.toml
:
# Simple installation (includes toolkit by default)
[]
= "0.0.1"
# Or choose specific features:
# agents-sdk = { version = "0.0.1", default-features = false } # Core only
# agents-sdk = { version = "0.0.1", features = ["aws"] } # With AWS
# agents-sdk = { version = "0.0.1", features = ["redis"] } # With Redis persistence
# agents-sdk = { version = "0.0.1", features = ["postgres"] } # With PostgreSQL persistence
# agents-sdk = { version = "0.0.1", features = ["dynamodb"] } # With DynamoDB persistence
# agents-sdk = { version = "0.0.1", features = ["full"] } # Everything
Individual Crates (Advanced)
If you prefer granular control, you can also use individual crates:
[]
= "0.0.1" # Core traits and types
= "0.0.1" # Agent runtime and builders
= "0.0.1" # Built-in tools (optional)
= "0.0.1" # AWS integrations (optional)
Quick Start
Basic Agent with Tools
use ;
use tool;
use Arc;
// Define a tool using the #[tool] macro - it's that simple!
async
Defining Tools
The #[tool]
macro automatically generates the schema and wrapper code:
use tool;
// Simple tool
// Async tool
async
// Tool with optional parameters
// Use the tools:
let tools = vec!;
Using Persistence Backends
Choose the persistence layer that fits your infrastructure:
use ;
use Arc;
async
See examples/checkpointer-demo
for a complete working example.
Human-in-the-Loop (HITL) Tool Approval
The HITL middleware allows you to require human approval before executing specific tools. This is essential for:
- Critical Operations: Database modifications, file deletions, API calls with side effects
- Security Review: Operations that access sensitive data or external systems
- Cost Control: Expensive API calls or resource-intensive operations
- Compliance: Operations requiring audit trails or manual oversight
Quick Start - HITL in 3 Steps
Step 1: Configure HITL Policies
use ;
use Arc;
// Step 1: Define HITL policies
let checkpointer = new;
let mut agent_builder = new
.with_model
.with_tools;
// Add HITL policy for each critical tool
agent_builder = agent_builder.with_tool_interrupt;
let agent = agent_builder
.with_checkpointer // Required for HITL!
.build?;
Step 2: Handle Interrupts
use ;
// Agent will pause when it tries to call a restricted tool
match agent.handle_message.await
Step 3: Resume with Approval
// After human reviews and approves
agent.resume_with_approval.await?;
// Or modify the arguments
agent.resume_with_approval.await?;
// Or reject
agent.resume_with_approval.await?;
Important: HITL requires a checkpointer to persist interrupt state. If no checkpointer is configured, HITL will be automatically disabled with a warning.
HITL Policy Structure
The HitlPolicy
struct controls tool execution behavior:
Handling Interrupts
When a tool requires approval, the agent execution pauses and creates an interrupt:
use ;
use Arc;
// Agent encounters a tool requiring approval
let result = agent.handle_message.await;
// Execution pauses with an interrupt error
match result
Responding to Interrupts
Use HitlAction
to respond to interrupts:
use HitlAction;
// 1. Accept - Execute with original arguments
agent.resume_with_approval.await?;
// 2. Edit - Execute with modified arguments
agent.resume_with_approval.await?;
// 3. Reject - Cancel execution with optional reason
agent.resume_with_approval.await?;
// 4. Respond - Provide custom message instead of executing
agent.resume_with_approval.await?;
Complete HITL Example
use ;
use HashMap;
use Arc;
use json;
async
See Complete Example: examples/hitl-financial-advisor
- Full working demo with real OpenAI integration, showing transfer approvals, sub-agents, and all HITL actions.
HITL Best Practices
- Always use a checkpointer: HITL requires state persistence to work correctly
- Provide clear policy notes: Help humans understand why approval is needed
- Handle all action types: Support Accept, Edit, Reject, and Respond in your UI
- Log interrupt decisions: Maintain audit trails for compliance
- Test interrupt scenarios: Verify your approval workflow handles edge cases
- Consider timeout policies: Decide how long to wait for human response
- Use appropriate granularity: Not every tool needs approval - focus on critical operations
Development Setup (From Source)
# Format, lint, and test
# Run examples
Features
✅ Core Features (Python Parity Achieved)
Agent Builder API
ConfigurableAgentBuilder
with fluent interface matching Python's API.with_model()
method supporting OpenAI, Anthropic, and Gemini models.get_default_model()
function returning pre-configured Claude Sonnet 4- Async and sync agent creation:
create_deep_agent()
andcreate_async_deep_agent()
Middleware Stack
- Planning Middleware: Todo list management with comprehensive tool descriptions
- Filesystem Middleware: Mock filesystem with
ls
,read_file
,write_file
,edit_file
tools - SubAgent Middleware: Task delegation to specialized sub-agents
- HITL (Human-in-the-Loop): Tool execution interrupts with approval policies
- Configurable per-tool approval requirements
- Support for Accept, Edit, Reject, and Respond actions
- Automatic state persistence with checkpointer integration
- Policy notes for human reviewers
- Summarization Middleware: Context window management
- AnthropicPromptCaching: Automatic prompt caching for efficiency
State Management
- State Reducers: Smart merging functions matching Python's
file_reducer
behavior - Persistence:
Checkpointer
trait with multiple backend implementations - Thread Management: Save/load/delete agent conversation threads
Persistence Backends
- InMemory: Built-in, zero-config persistence (development)
- Redis: High-performance in-memory data store with optional durability
- PostgreSQL: ACID-compliant relational database with full SQL support
- DynamoDB: AWS-managed NoSQL database with auto-scaling
Provider Support
- Anthropic: Claude models with prompt caching support
- OpenAI: GPT models integration
- Gemini: Google's Gemini Chat models
Built-in Tools
- Todo Management:
write_todos
with detailed usage examples - File Operations: Full CRUD operations on mock filesystem
- Task Delegation:
task
tool for spawning ephemeral sub-agents
🚧 Future Features (Planned)
Custom SubAgent Support
Enable users to define completely custom execution graphs beyond simple prompt/tool configurations:
// Future API design
let custom_subagent = CustomSubAgent ;
let agent = new
.with_custom_subagent
.build?;
Benefits:
- Full control over sub-agent execution flow
- Custom state management within sub-agents
- Complex branching and conditional logic
- Integration with external systems and APIs
Dict-based Model Configuration
Allow models to be configured via dictionary/struct configs in addition to instances:
// Future API design
let agent = new
.with_model_config
.build?;
Benefits:
- Simplified configuration management
- Easy serialization/deserialization of agent configs
- Runtime model switching without code changes
- Better integration with configuration management systems
Advanced State Features
- Distributed State Stores: Redis, DynamoDB backends for multi-agent systems
- State Migrations: Schema evolution support for long-running agents
- State Encryption: Automatic encryption for sensitive data
- Custom Reducers: User-defined state merging logic beyond built-in reducers
Enhanced Tool System
- Dynamic Tool Registration: Runtime tool addition/removal
- Tool Composition: Combining multiple tools into workflows
- Tool Validation: Schema-based input/output validation
- Tool Metrics: Performance and usage analytics
Support the Project
If you find this project helpful, consider supporting its development:
Your support helps maintain and improve this open-source project. Thank you! ❤️
Next Steps
Follow the roadmap to implement planners, runtime orchestration, AWS integrations, and customer-ready templates.