agent-base
A lightweight Agent Runtime Kernel for building AI agents in Rust.
agent-base provides the minimal orchestration layer needed to build custom AI agents — LLM integration, tool dispatch, multi-turn conversation, approval flows, event streaming, and error recovery — all with zero business assumptions.
Design Principles
- Clear semantics —
RunOutcomeexplicitly distinguishesCompletedfromFailed; events capture the process, the return value captures the final result. - Simple state model — Runtime memory is the source of truth for live sessions;
SessionStoreis an optional persistence adapter. - Conservative by default — On tool failure, the runtime stops by default (
StopOnError) rather than guessing how to recover. - Strategy injection — All variable behaviors are injected via traits (
ToolErrorRecovery,ToolPolicy,ApprovalHandler,Middleware), not hardcoded.
Features
- LLM Abstraction —
LlmClienttrait with built-in OpenAI and Anthropic implementations - Tool System —
Tooltrait +ToolRegistryfor registration and dispatch - Approval Flow —
ApprovalHandlertrait withAllowOnce/AllowAlways/Denydecisions - Error Recovery —
ToolErrorRecoverytrait; defaults toStopOnError, opt-inRetryOnError - Event Streaming — Structured
AgentEventstream for UI, logging, auditing, and debugging - Multi-turn Sessions —
AgentSessionmanages message history;SessionStorefor optional persistence - Sub-Agents —
SubAgentToolwithEphemeral(default) orPersistentsession policies - Context Management — configurable
ContextWindowManagerfor token budget control - Middleware — hooks at
on_user_message,on_pre_llm, andon_post_llmfor extensions - Checkpoints — structured
Checkpointevents enable future replay, debugging, and resume - MCP Support — built-in
McpClientfor the Model Context Protocol - Skills — composable capability units with auto-registered tools and on-demand detailed prompts
Quick Start
1. Define a Tool
Any capability you want your agent to have is expressed as a Tool:
use ;
use async_trait;
use ;
;
2. Build the Agent
use Arc;
use ;
async
3. Handle Tool Errors
By default, tool failures stop the run. For self-healing agents (e.g. code agents that retry compilation), inject RetryOnError:
use RetryOnError;
let mut runtime = new
.register_tool
.error_recovery // ← retry on failure
.build;
4. Add Approval for Sensitive Tools
use ;
;
;
let mut runtime = new
.register_tool
.tool_policy
.approval_handler
.build;
5. Use a Sub-Agent
use SubAgentTool;
// Build a sub-agent runtime
let sub_llm = new;
let sub_runtime = new
.system_prompt
.build;
// Wrap it as a tool
let math_tool = new;
// Register in the parent agent
let mut parent = new
.register_tool
.build;
Each sub-agent call creates a fresh session by default. Use SubAgentTool::with_persistent() to share context across calls.
Examples
# Configure API key
# Edit .env with your OPENAI_API_KEY or ANTHROPIC_API_KEY
# Run the REPL example
# Run the SubAgent demo
# Run the MCP demo
# Run the Skill demo
What agent-base Does NOT Do
- ❌ No SSH, filesystem, or database tools
- ❌ No workflow DAG / multi-agent orchestration engine
- ❌ No memory / RAG framework
- ❌ No terminal UI or approval dialogs
- ❌ No heavy persistence or transaction system
Business-specific tools and strategies belong in upper layers (ops-agent, db-agent, etc.).
Typical Layering
ops-agent / db-agent / browser-agent ← Business agents
└── agent-base ← Lightweight Runtime Kernel
v1 Semantics
| Convention | Meaning |
|---|---|
run_turn_* → AgentResult<RunOutcome> |
Ok(Completed) = success, Ok(Failed) = finished with error |
AgentEvent::RunFinished |
Process ended — final status is in RunOutcome |
Tool failure → defaults to StopOnError |
Inject RetryOnError for self-healing agents |
SubAgent → defaults to Ephemeral |
Use with_persistent() for shared context |
| Session → memory is source of truth | SessionStore is an optional persistence adapter |
Stability
This project is in early development (v0.1.0). The core abstractions are settling but not yet frozen. Expect minor API changes as the ecosystem evolves.
License
MIT