Build AI agents in Rust with 5 lines of code. TraitClaw provides type-safe tools, streaming responses, persistent memory, multi-agent teams, reasoning strategies, and MCP integration β all with zero-cost abstractions and no garbage collector.
use traitclaw::prelude::*;
use traitclaw_openai_compat::OpenAiCompatProvider;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let agent = Agent::builder()
.provider(OpenAiCompatProvider::openai("gpt-4o-mini", api_key))
.system("You are a helpful assistant")
.build()?;
let output = agent.run("Hello!").await?;
println!("{}", output.text());
Ok(())
}
Why TraitClaw?
- π§© Composable Trait Architecture β 8 core traits (
Provider, Tool, Memory, Guard, Hint, Tracker, ContextManager, OutputTransformer) compose into any agent topology
- π§ Type-Safe Tool Calling β
#[derive(Tool)] generates JSON schemas from Rust structs at compile time
- π§ Multi-Strategy Reasoning β Built-in ReAct, Chain-of-Thought, and MCTS strategies via
AgentStrategy trait
- π₯ Multi-Agent Teams β Teams, routers, delegation, and verification chains out of the box
- π MCP Integration β Native Model Context Protocol client for tool discovery
- π‘ First-Class Streaming β
async Stream with typed events, not string concatenation
- π Production Observability β
tracing integration for structured logging and OpenTelemetry
- π¦ Zero-Cost Abstractions β No GC, no runtime, single static binary
Quick Start
cargo add traitclaw traitclaw-openai-compat tokio anyhow
Feature Matrix
| Category |
Feature |
Status |
| Core |
Agent & Builder |
β
|
|
8 Core Traits |
β
|
|
Tool System + #[derive(Tool)] |
β
|
|
Real-Time Streaming |
β
|
|
Structured Output (JSON β Rust) |
β
|
| Reasoning |
ReAct (ThinkβActβObserve) |
β
|
|
Chain-of-Thought |
β
|
|
Monte Carlo Tree Search |
β
|
|
Custom Strategies |
β
|
| Providers |
OpenAI / GPT |
β
|
|
Anthropic / Claude |
β
|
|
OpenAI-Compatible (Ollama, Groq, Mistral, vLLM) |
β
|
| Memory |
In-Memory |
β
|
|
SQLite Persistent |
β
|
|
Compressed (LLM + Rule-Based) |
β
|
| Orchestration |
Multi-Agent Teams |
β
|
|
Router Strategies (Sequential, Leader, Conditional) |
β
|
|
Verification Chains |
β
|
|
Agent Factory & Pool |
β
|
| Integration |
MCP Client (stdio + SSE) |
β
|
|
RAG Pipeline (BM25, Embeddings, Hybrid) |
β
|
|
Evaluation Framework |
β
|
| Safety |
Guards (Loop Detection, Rate Limit, Shell Deny) |
β
|
|
Hints (Budget, System Prompt Reminder) |
β
|
|
Trackers (Adaptive) |
β
|
| Observability |
tracing Integration |
β
|
|
Lifecycle Hooks |
β
|
| Planned |
Benchmarks & Orchestration Strategy |
π v1.1 |
|
Inter-Agent Contracts |
π v1.2 |
|
Retry & Checkpoint Resilience |
π v1.3 |
Features
π§ Type-Safe Tool Calling
#[derive(Tool)]
#[tool(description = "Search the web")]
struct WebSearch { query: String }
π― Structured Output
#[derive(Deserialize, JsonSchema)]
struct Review { title: String, rating: u8 }
let review: Review = agent.run_structured("Review Inception").await?;
π‘ Real-Time Streaming
let mut stream = agent.stream("Tell me a story");
while let Some(Ok(StreamEvent::TextDelta(text))) = stream.next().await {
print!("{text}");
}
π‘οΈ Steering β Guards, Hints & Trackers
use traitclaw_steering::Steering;
let steering = Steering::auto();
πΎ Persistent Memory
use traitclaw_memory_sqlite::SqliteMemory;
let memory = SqliteMemory::new("./agent.db")?;
π₯ Multi-Agent Teams
use traitclaw_team::{Team, AgentRole};
let team = Team::new("research")
.add_role(AgentRole::new("researcher", "Research topics"))
.add_role(AgentRole::new("writer", "Write summaries"));
π MCP Integration
use traitclaw_mcp::McpServer;
let server = McpServer::stdio("npx", &["-y", "@mcp/server-filesystem", "."]).await?;
π§ Reasoning Strategies
use traitclaw_strategies::ReActStrategy;
let strategy = ReActStrategy::builder().max_steps(10).build();
ποΈ Architecture Overview
TraitClaw follows a layered trait architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β traitclaw (meta-crate) β
β Re-exports everything. One dependency, full power. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Extension Crates β
β ββββββββββββ ββββββββββββ βββββββββ ββββββββ β
β β steering β β sqlite β β mcp β β team β ... β
β ββββββββββββ ββββββββββββ βββββββββ ββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Provider Crates β
β ββββββββββββββββ ββββββββββββββ ββββββββββββββββββββ β
β β openai-compatβ β anthropic β β openai (native) β β
β ββββββββββββββββ ββββββββββββββ ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β traitclaw-core (foundation) β
β Agent Β· Provider Β· Tool Β· Memory Β· Guard Β· Hint Β· β
β Tracker Β· ContextManager Β· OutputTransformer Β· β
β ExecutionStrategy Β· AgentStrategy Β· AgentHook β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The Agent Loop
- Context Hydration β Retrieve past dialogue from
Memory, append user prompt
- Provider Generation β LLM evaluates context, returns text or tool call
- Tool Resolution β Parse arguments, execute Rust function, append result
- Recursive Reasoning β Repeat steps 2β3 until task is complete
- Memory Commit β Save final trajectory back to
Memory
βοΈ Feature Flags
[dependencies]
traitclaw = { version = "1.0", features = ["full"] }
| Feature |
Crate |
Default |
openai-compat |
traitclaw-openai-compat |
β
|
macros |
traitclaw-macros |
β
|
steering |
traitclaw-steering |
β |
sqlite |
traitclaw-memory-sqlite |
β |
mcp |
traitclaw-mcp |
β |
rag |
traitclaw-rag |
β |
team |
traitclaw-team |
β |
eval |
traitclaw-eval |
β |
strategies |
traitclaw-strategies |
β |
tiktoken |
Accurate token counting |
β |
full |
All of the above |
β |
π¦ Crate Ecosystem
| Crate |
Purpose |
traitclaw |
Meta-crate β start here |
traitclaw-core |
Core traits, Agent runtime, Builder |
traitclaw-macros |
#[derive(Tool)] proc macro |
traitclaw-openai-compat |
OpenAI, Ollama, Groq, Mistral, vLLM |
traitclaw-openai |
Native OpenAI + Structured Output |
traitclaw-anthropic |
Anthropic Claude provider |
traitclaw-steering |
Guards, Hints, Trackers |
traitclaw-memory-sqlite |
SQLite persistent memory |
traitclaw-mcp |
MCP client (stdio + SSE) |
traitclaw-rag |
RAG pipeline (BM25, embeddings, hybrid) |
traitclaw-team |
Multi-agent teams & orchestration |
traitclaw-eval |
Evaluation & benchmarking |
traitclaw-strategies |
ReAct, CoT, MCTS reasoning |
traitclaw-test-utils |
Mock providers & test helpers |
π Examples
cd examples/01-hello-agent && cargo run
π Stability Policies
Semantic Versioning
TraitClaw follows Semantic Versioning 2.0.0:
| Change Type |
Allowed In |
| Bug fixes |
Patch (1.0.x) |
| New public types, traits, methods |
Minor (1.x.0) |
| MSRV bump |
Minor (1.x.0) |
| Deprecation notices |
Minor (1.x.0) |
| Removal of deprecated items |
Major (2.0.0) |
| Trait signature changes |
Major (2.0.0) |
MSRV (Minimum Supported Rust Version)
- Current: Rust 1.75
- Bumped only in minor releases, never in patches
- Always documented in CHANGELOG.md
- Maintains a minimum 6-month lag from the latest Rust stable release
Deprecation Policy
- Deprecated items are marked with
#[deprecated(since = "1.x", note = "Use Y instead")]
- Items remain available for a minimum of 2 minor versions after deprecation
- Deprecated items are removed only in the next major version (v2.0.0)
πΊοΈ Roadmap
| Version |
Codename |
Focus |
| v1.0.0 |
Production Ready |
β
Stable API, crates.io publication |
| v1.1.0 |
Benchmark & Orchestrate |
Benchmarks, orchestration strategy |
| v1.2.0 |
Contracts |
Inter-agent contracts, typed delegation |
| v1.3.0 |
Resilience |
Retry, checkpoint, fault tolerance |
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.