agentrs
agentrs is a production-oriented, async-native Rust SDK for building AI agents with a unified provider interface, composable tools, Model Context Protocol (MCP) integration, configurable memory, multi-agent orchestration, and YAML-driven runtime loading.
The project is designed for developers who want an ergonomic Rust API without giving up architectural flexibility. You can start with a single assistant in a few lines, then scale to tool-using agents, web MCP integrations, and orchestrated multi-agent workflows without changing the core programming model.
Why agentrs
- Provider-agnostic abstractions for OpenAI, Azure OpenAI, Anthropic, Gemini, and Ollama
- Async-first execution built on
tokio,futures, andasync_trait - Tool calling with built-in tools, MCP tools, and macro-generated custom tools
- Memory backends for simple chat history, sliding windows, token budgets, and vector retrieval
- Multiple agent loop strategies such as ReAct, chain-of-thought style single-pass execution, and plan-and-execute
- Multi-agent orchestration for sequential and parallel execution
- YAML configuration support for loading single-agent and multi-agent runtimes without hand-writing builders
- Feature-gated architecture so consumers only compile the integrations they need
Architecture
agentrs is organized as a workspace of focused crates:
agentrs/
├── crates/agentrs-core # Core traits, shared types, streaming helpers, errors
├── crates/agentrs-llm # LLM provider implementations
├── crates/agentrs-tools # Tool registry, built-in tools, proc-macro integration
├── crates/agentrs-mcp # MCP stdio and Streamable HTTP clients
├── crates/agentrs-memory # Memory backends
├── crates/agentrs-agents # Agent builders and execution loops
├── crates/agentrs-multi # Multi-agent orchestration
└── crates/agentrs # Facade crate, prelude, YAML runtime loader
Core Design Principles
agentrs-coredefines the contracts:LlmProvider,Tool,Memory, andAgentagentrs-llmadapts concrete model providers into a common chat-completion interfaceagentrs-toolskeeps tool execution decoupled from providers and agent loopsagentrs-mcplets the SDK consume both local MCP servers and remote web MCP endpointsagentrs-memorykeeps memory as a pluggable concern rather than coupling it into a runneragentrs-agentsfocuses on agent behavior and loop controlagentrs-multicomposes multiple agents without changing the single-agent contractagentrsre-exports the public API and adds configuration loading for production setups
Technologies Used
tokiofor async runtime, process management, filesystem access, and concurrency primitivesfuturesandtokio-streamfor streaming and async compositionasync-traitfor async trait contracts across providers, tools, memory, and agentsserde,serde_json, andserde_yamlfor configuration, requests, and schema-like payloadsreqwestfor HTTP transport to model providers and web MCP endpointsthiserrorfor structured error handlingschemarsfor JSON Schema generation in macro-generated toolsproc-macro,syn, andquotefor the#[tool]developer ergonomics layer
Feature Flags
The facade crate exposes the following main features:
[]
= { = "0.1", = ["openai", "mcp", "tool-search"] }
Available features:
openaiazureopenaianthropicollamageminimemory-redistool-fetchtool-searchtool-fstool-bashtool-pythonmcpfull
The default build enables openai, azureopenai, tool-fetch, tool-search, tool-fs, and mcp.
Installation
[]
= { = "0.1", = ["openai", "mcp", "tool-fetch", "tool-search"] }
= { = "1", = ["full"] }
= "1"
For local models with Ollama:
[]
= { = "0.1", = ["ollama", "tool-fs"] }
= { = "1", = ["full"] }
= "1"
Quick Start
use *;
async
Provider Integrations
All providers implement the same LlmProvider contract.
OpenAI
use *;
let llm = from_env
.model
.build?;
Azure OpenAI
use *;
let llm = from_env
.base_url
.model
.build?;
Anthropic
use *;
let llm = from_env
.model
.build?;
Gemini
use *;
let llm = from_env
.model
.build?;
Ollama
use *;
let llm = builder
.base_url
.model
.build?;
Tools
Tools are independent components that can be registered in a ToolRegistry and exposed to the model as callable functions.
Built-in Tools
Available built-in tools include:
CalculatorToolWebFetchToolWebSearchToolFileReadToolFileWriteToolBashToolbehindtool-bashPythonToolbehindtool-python
Registering Tools
use *;
let tools = new
.register
.register
.register;
Custom Tools with #[tool]
use *;
async
let tools = new.register;
Memory Backends
Memory is pluggable and independent from the agent loop.
In-Memory History
use *;
let memory = new;
Sliding Window Memory
use *;
let memory = new;
Token-Aware Memory
use *;
let memory = new;
Vector Memory
use *;
let memory = new;
Agent Execution Strategies
ReAct
Best when the model may need to call tools iteratively.
let mut agent = builder
.llm
.tools
.loop_strategy
.build?;
Chain-of-Thought Style Single Pass
Best for direct reasoning without tools.
let mut agent = builder
.llm
.loop_strategy
.build?;
Plan and Execute
Useful for tasks that benefit from an explicit planning stage.
let mut agent = builder
.llm
.tools
.loop_strategy
.build?;
Streaming Runs
use *;
async
MCP Integration
agentrs supports both local MCP servers over stdio and remote MCP endpoints over Streamable HTTP.
Local MCP Server
use *;
let tools = new
.register_mcp
.await?;
Remote MCP Endpoint
use *;
let tools = new
.register_mcp_http
.await?;
Remote MCP with Optional API Key
use *;
let options = new
.api_key
.api_key_header
.api_key_prefix;
let tools = new
.register_mcp_http_with_options
.await?;
MCP Example
use *;
async
Multi-Agent Orchestration
agentrs-multi composes existing agents into higher-level workflows.
Sequential Routing
use *;
let researcher = builder
.llm
.system
.tool
.build?;
let writer = builder
.llm
.system
.build?;
let mut orchestrator = builder
.add_agent
.add_agent
.routing
.build?;
let output = orchestrator.run.await?;
println!;
Parallel Routing
use *;
let mut orchestrator = builder
.add_agent
.add_agent
.routing
.build?;
YAML Runtime Loading
One of the main production features of agentrs is the ability to create single agents and multi-agent runtimes from .yaml files.
This is useful when:
- prompts should change without recompiling code
- environments use different providers or tools
- orchestrations are controlled by deployment configuration
- you want a clean separation between application code and agent definitions
Load a Single Agent from YAML
use *;
async
Example YAML:
kind: agent
name: calculator-assistant
llm:
provider: open_ai
model: gpt-4o-mini
system: You are a concise assistant that uses tools when helpful.
memory:
type: sliding_window
window_size: 8
tools:
- type: calculator
loop_strategy:
type: re_act
max_steps: 4
temperature: 0.1
max_tokens: 512
Load a Multi-Agent Orchestrator from YAML
use *;
async
Example YAML:
kind: multi_agent
agents:
- name: researcher
llm:
provider: open_ai
model: gpt-4o-mini
system: You gather technical facts and use documentation tools.
tools:
- type: web_search
- type: mcp
target: https://mcp.context7.com/mcp
api_key_header: X-Context7-API-Key
api_key_prefix: ""
loop_strategy:
type: re_act
max_steps: 5
- name: writer
llm:
provider: open_ai
model: gpt-4o-mini
system: You write a polished final answer from the previous agent output.
memory:
type: token_aware
max_tokens: 1200
loop_strategy:
type: chain_of_thought
routing:
type: sequential
order:
- researcher
- writer
Load a Generic Runtime from YAML
use *;
async
This generic loader is useful when a deployment can switch between single-agent and multi-agent modes.
Error Handling
The SDK uses structured errors from agentrs-core:
- provider transport and API failures
- tool validation and execution failures
- memory backend failures
- MCP protocol and transport failures
- invalid configuration and missing fields
- max-step exhaustion in agent loops
Typical usage:
use *;
match agent.run.await
Practical Examples Summary
The repository includes runnable examples for the main features:
examples/simple_agent.rsexamples/tool_use.rsexamples/streaming.rsexamples/multi_agent.rsexamples/mcp_integration.rsexamples/yaml_single_agent.rsexamples/yaml_multi_agent.rsexamples/yaml_runtime.rs
Run them with:
Environment Variables
Common environment variables used by the provider builders:
OPENAI_API_KEYOPENAI_BASE_URLOPENAI_MODELAZURE_OPENAI_KEYAZURE_OPENAI_ENDPOINTAZURE_OPENAI_MODELANTHROPIC_API_KEYGEMINI_API_KEYCONTEXT7_API_KEY
For Ollama you usually only need the local service running at http://localhost:11434.
Testing and Validation
Typical commands used during development:
Current Scope and Notes
- OpenAI, Azure OpenAI, and Ollama currently provide the most complete request/stream integration
- Anthropic and Gemini support
complete()and can be used today, but their streaming implementations are intentionally conservative in this version - Multi-agent YAML currently supports sequential and parallel routing
- YAML config is intended to cover the practical runtime surface, not every internal experimental type
Roadmap Ideas
- YAML support for graph and supervisor orchestration
- richer streaming behavior for all providers
- tool catalogs and dynamic custom tool loading
- deployment-focused validation and schema export for YAML configs
License
Licensed under either:
- MIT license
- Apache License, Version 2.0
at your option.