traitclaw 1.0.0

A Rust AI Agent Framework β€” Simple by default, powerful when needed
Documentation

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(); // One-liner: guards + hints + tracking

πŸ’Ύ 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

  1. Context Hydration β€” Retrieve past dialogue from Memory, append user prompt
  2. Provider Generation β€” LLM evaluates context, returns text or tool call
  3. Tool Resolution β€” Parse arguments, execute Rust function, append result
  4. Recursive Reasoning β€” Repeat steps 2–3 until task is complete
  5. 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

# Example Description
01 hello-agent Minimal 5-line agent
02 tool-calling Custom tools with #[derive(Tool)]
03 streaming Real-time streaming responses
04 steering Guards, Hints & auto-config
05 structured-output JSON β†’ Rust types
06 memory-persistence SQLite conversation history
10 mcp-client MCP tool discovery
11 custom-strategy Build your own AgentStrategy
12 lifecycle-hooks Observability middleware
13 custom-router Custom team routing logic
14 compressed-memory LLM-powered memory compression
15 context-manager Custom context window management
16 output-transformer Post-process agent output
17 dynamic-tools Runtime tool registration
18 context-managers Built-in context managers
19 grouped-registry Grouped tool registry
20 mcp-tool-registry MCP as ToolRegistry
21 rag-pipeline RAG with BM25 + embeddings
22 multi-agent-team Team orchestration
23 eval-runner Evaluation test suites
24 agent-factory Factory pattern for agents
25 reasoning-strategies ReAct, CoT, MCTS in action
26 observability Tracing & structured logging
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.