Agent IO
A Rust SDK for building AI agents with multi-provider LLM support.
Features
- Multi-provider LLM support: OpenAI, Anthropic, Google Gemini, and OpenAI-compatible providers
- Tool/Function calling: Built-in tool system with dependency injection
- Streaming responses: Event-based real-time response handling
- Context compaction: Automatic management of long conversation context
- Token tracking: Usage tracking and cost calculation across providers
- Retry mechanism: Built-in exponential backoff retry for rate limit handling
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick Start
Basic Usage
use Arc;
use ;
async
Using Tools
use Arc;
use ;
use ;
async
Supported LLM Providers
| Provider | Model Type | Feature Flag | Environment Variable |
|---|---|---|---|
| OpenAI | ChatOpenAI |
openai |
OPENAI_API_KEY |
| Anthropic | ChatAnthropic |
anthropic |
ANTHROPIC_API_KEY |
| Google Gemini | ChatGoogle |
google |
GOOGLE_API_KEY |
| OpenRouter | ChatOpenRouter |
- | OPENROUTER_API_KEY |
| Groq | ChatGroq |
- | GROQ_API_KEY |
| Mistral | ChatMistral |
- | MISTRAL_API_KEY |
| DeepSeek | ChatDeepSeek |
- | DEEPSEEK_API_KEY |
| Ollama | ChatOllama |
- | - |
Configuration
Agent Builder
let agent = builder
.with_llm
.system_prompt // System prompt
.max_iterations // Max iterations
.build?;
Tool Configuration
// Create an ephemeral tool (results removed from context after use)
let tool = new
.with_ephemeral; // Remove after use
Event Types
| Event | Description |
|---|---|
AgentEvent::Text |
Text content chunk |
AgentEvent::Thinking |
Model thinking process (Claude support) |
AgentEvent::ToolCall |
Tool call request |
AgentEvent::ToolResult |
Tool execution result |
AgentEvent::FinalResponse |
Final response |
AgentEvent::Error |
Error message |
AgentEvent::StepStart |
Step started |
AgentEvent::StepComplete |
Step completed |
Usage Tracking
// Get session usage statistics
let usage = agent.get_usage.await;
println!;
println!;
OpenAI-Compatible Providers
For providers that support OpenAI API format, use ChatOpenAICompatible:
use ChatOpenAICompatible;
let llm = new
.with_base_url
.with_api_key;
Feature Flags
[]
= "0.1"
= ["openai", "anthropic", "google"]
# Or use "full" to enable all major providers
= ["full"]
Examples
Run the examples:
# Basic example
# Multi-provider example
License
Licensed under the Apache License 2.0.