traitclaw-core
Core traits, types, and runtime for the TraitClaw AI Agent Framework.
This crate provides the foundational building blocks that all TraitClaw crates depend on. Most users should use the traitclaw meta-crate instead of depending on this directly.
Core Abstractions
| Trait/Type | Purpose |
|---|---|
Agent |
Orchestrates LLM calls, tool execution, and streaming |
AgentBuilder |
Fluent builder for configuring agents |
Provider |
Abstract LLM backend (OpenAI, Anthropic, Ollama, etc.) |
Tool / ErasedTool |
Type-safe tool definitions with JSON schema generation |
Memory |
Conversation persistence, working memory, long-term recall |
CompletionResponse |
Structured response from LLM completions |
StreamEvent |
Event types for real-time streaming |
Message |
Chat messages with role (system, user, assistant, tool) |
Usage
use *;
let agent = builder
.provider
.system
.tool
.build?;
// Single-turn completion
let output = agent.run.await?;
// Structured JSON output
let data: MyStruct = agent.run_structured.await?;
// Streaming
let stream = agent.stream;
Key Design Decisions
- Trait-based providers — any LLM backend implements
Provider - Type-erased tools — tools are type-safe at definition, erased at runtime for dynamic dispatch
- Async-first — all I/O operations are async with
tokio - Zero-copy where possible — references and slices over allocations
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.