Quick Start
use Arc;
use ;
async
Use Cases
Example applications built with this project.
Consider setting your LLM provider's environment variables for key, model or base URL.
Project Scanner
Scans a directory and outputs a JSON summary with project description and languages used.
Output:
Deep Research
Spawns three researcher sub-agents in parallel, then aggregates their findings into a structured decision. Requires BRAVE_API_KEY for web search.
Output:
{
"title": "What Constitutes a Good Life: A Multi-Perspective Analysis",
"research": "A good life emerges from the convergence of philosophical wisdom, scientific research, and cultural understanding. Key elements include meaningful relationships and social connections, a sense of purpose and personal growth, physical and mental well-being, contributing to something beyond oneself, and living in accordance with personal values. While cultural contexts vary, common themes across traditions emphasize virtue, balance, gratitude, and the cultivation of both inner fulfillment and positive impact on others."
}
API
Configure an AgentBuilder with a provider, model, tools, and prompt, then call .run() to get an AgentOutput. Stream Events during execution.
LlmProvider
Connect to any LLM. Providers own a reqwest::Client for connection pooling and SSE streaming.
use ;
let provider = from_api_key;
let provider = from_api_key;
let provider = from_api_key;
let client = new; // share a connection pool
let provider = new;
AgentBuilder
One builder for everything — agent definition, runtime context, and execution.
use AgentBuilder;
let output = new
.identity_prompt
.instruction_prompt
.model
.tool
.provider
.run
.await?;
Prompt types
| Prompt | Purpose |
|---|---|
instruction_prompt |
The task for this run (required for .run()) |
context_prompt |
Additional context alongside the instruction |
behavior_prompt |
How the agent behaves — defaults provided |
identity_prompt |
Who the agent is — persistent across runs |
Use {key} placeholders in the identity prompt and fill them with template_variable (or template_variables).
Sub-agents
Use .build() to get Arc<dyn Agent> for registration as a sub-agent. Without .model(), a sub-agent inherits its parent's model at runtime. Clone the builder to create multiple similar agents:
let researcher_base = new
.model
.identity_prompt
.tool
.max_turns;
let r1 = researcher_base.clone.name.build?;
let r2 = researcher_base.clone.name.build?;
let output = new
.name
.identity_prompt
.sub_agent
.sub_agent
Guardrails
Limit agent execution to prevent runaway cost or duration.
| Method | What it does |
|---|---|
.max_turns(10) |
Stop after N agentic loop iterations |
.max_budget(1.0) |
Abort when estimated USD cost exceeds limit |
.max_tokens(4096) |
Cap output tokens per LLM request |
.cancel_signal(signal) |
Abort via an external Arc<AtomicBool> (e.g., on Ctrl+C) |
Behavior prompts
Agents ship with default behavior prompts appended to the identity prompt. Override any:
| Variant | Default behavior |
|---|---|
TaskExecution |
Read before modifying, don't add unrequested features, diagnose failures |
ToolUsage |
Use dedicated tools over bash, parallelize independent calls |
ActionSafety |
Consider reversibility, confirm destructive operations |
OutputEfficiency |
Be concise, lead with the answer, skip filler |
use BehaviorPrompt;
new
.behavior_prompt
.behavior_prompt
Sessions
Record every message exchanged during a run to disk as JSONL. The agent is not aware of this — recording happens transparently in the framework.
new
.session_dir
Each run writes <dir>/sessions/<id>/transcript.jsonl — one JSON line per user message, assistant response, and tool result, with timestamps and token usage.
Events
Emitted via AgentBuilder.event_handler() during execution.
| Event | Description |
|---|---|
AgentStart |
Agent begins execution |
AgentEnd |
Agent finishes with turn count |
AgentError |
Agent encountered an error |
TurnStart / TurnEnd |
Turn boundaries |
RequestStart / RequestEnd |
LLM request lifecycle |
TextChunk |
Streamed text token |
ToolCallStart / ToolCallEnd |
Tool execution lifecycle |
TokenUsage |
Token counts for a request |
BudgetUsage |
Cost tracking update |
Tools
Define what the agent can do. Read-only tools run concurrently.
use ;
let tool = new
.schema
.read_only
.handler
.build;
Built-in tools:
| Tool | Description |
|---|---|
ReadFileTool |
Read a file with line numbers, offset, and limit |
WriteFileTool |
Create or overwrite a file |
EditFileTool |
Find-and-replace in a file |
GlobTool |
Find files by pattern (e.g., **/*.rs) |
GrepTool |
Search file contents by substring |
ListDirectoryTool |
List directory entries with type and size |
BashTool |
Execute a shell command |
ToolSearchTool |
Discover available tools by keyword |
SpawnAgentTool |
Delegate work to a sub-agent |
TaskTool |
Persistent task management (create, update, list, get) |
AgentOutput
The result of .run().
output.response_raw // free-form LLM text
output.response // validated JSON if output_schema was set
output.statistics.costs // total USD spent
output.statistics.input_tokens // total input tokens
output.statistics.output_tokens// total output tokens
output.statistics.requests // number of LLM calls
output.statistics.tool_calls // number of tool executions
output.statistics.turns // number of agentic turns
With .output_schema(), the agent returns validated JSON in output.response:
let output = new
.output_schema
.max_schema_retries // retry if agent doesn't comply (default: 3)
.run.await?;
output.response.unwrap // "billing"
Development
Environment
Use cases and integration tests pick up the LLM provider from these environment variables:
Anthropic
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
API key (required) |
ANTHROPIC_BASE_URL |
API URL (default: https://api.anthropic.com) |
ANTHROPIC_MODEL |
Model (default: claude-sonnet-4-20250514) |
Mistral
| Variable | Description |
|---|---|
MISTRAL_API_KEY |
API key (required) |
MISTRAL_BASE_URL |
API URL (default: https://api.mistral.ai) |
MISTRAL_MODEL |
Model (default: mistral-medium-2508) |
LiteLLM proxy
| Variable | Description |
|---|---|
LITELLM_API_URL |
Proxy URL (default: http://localhost:4000) |
LITELLM_API_KEY |
Auth key (optional) |
LITELLM_MODEL |
Model (default: claude-sonnet-4-20250514) |