liquidos-ai/AutoAgents
关于
一个用 Rust 编写的多智能体框架,支持构建、部署和协调多个智能体
人工智能与机器学习可以做什么
- Agent execution: ReAct and basic executors, streaming responses, and structured outputs
- Tooling: Derive macros for tools and outputs, plus a sandboxed WASM runtime for tool execution
- Memory: Sliding window memory with extensible backends
- LLM providers: Cloud and local backends behind a unified interface
实测星标增长
- 24小时
- 0
- 7天
- +8
- 15天
- +13
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.zh-CN.md
原文
AutoAgents
面向生产的 Rust 多智能体框架
English | 中文 | 日本語 | Español | Français | Deutsch | 한국어 | Português (Brasil)
该译文由社区维护,可能滞后;如有差异,以英文版为准。
喜欢这个项目? 在 GitHub 给我们点星
概览
AutoAgents 是一个用于在 Rust 中构建智能系统的模块化多智能体框架。它结合了类型安全的智能体模型、结构化工具调用、可配置内存,以及可插拔的 LLM 后端。该架构面向性能、安全与可组合性,覆盖服务器与边缘环境,并可作为高层智能体 harness 的基础。
关键特性
- 智能体执行:ReAct 与基础执行器、流式响应、结构化输出
- 工具化:工具与输出的派生宏,以及用于工具执行的沙盒化 WASM 运行时
- 记忆:滑动窗口记忆与可扩展后端
- LLM 提供方:统一接口下的云端与本地后端
- LLM 优化:构建带有缓存和重试等优化层的 LLM 流水线,实现更快且更可靠的推理
- 多智能体编排:类型化的发布/订阅通信与环境管理
- 语音处理:本地 TTS 与 STT 支持
- 可观测性:OpenTelemetry 追踪与指标,支持可插拔导出器
支持的 LLM 提供方
云端提供方
| 提供方 | Feature | 对话 | 流式 | 工具调用 | 结构化输出 | 视觉 / 多模态 |
|---|---|---|---|---|---|---|
| OpenAI | openai |
是 | 是 | 是 | 是 | 图片 URL 和内联图片;PDF 会以类型化错误拒绝。 |
| OpenRouter | openrouter |
是 | 是 | 是 | 是 | OpenAI 兼容的图片输入;PDF 会以类型化错误拒绝。 |
| Requesty | requesty |
是 | 是 | 是 | 是 | OpenAI 兼容的图片输入;PDF 会以类型化错误拒绝。 |
| Anthropic | anthropic |
是 | 是 | 是 | 是 | 图片、图片 URL 和 PDF 使用 Anthropic 内容块。 |
| DeepSeek | deepseek |
是 | 是 | 是 | 是 | OpenAI 兼容的图片输入;PDF 会以类型化错误拒绝。 |
| xAI | xai |
是 | 是 | 否 | 取决于模型 | 仅支持纯文本对话;多模态输入返回 LLMError::InvalidRequest。 |
| Phind | phind |
是 | 否* | 否 | 否 | 仅支持纯文本对话;多模态输入返回 LLMError::InvalidRequest。 |
| Groq | groq |
是 | 是 | 是 | 是 | OpenAI 兼容的图片输入;PDF 会以类型化错误拒绝。 |
google |
是 | 是 | 是 | 是 | 支持内联图片和 PDF;图片 URL 会以类型化错误拒绝。 | |
| Azure OpenAI | azure_openai |
是 | 否* | 是 | 是 | 支持图片 URL;PDF 和原始内联图片会以类型化错误拒绝。 |
| MiniMax | minimax |
是 | 是 | 是 | 否 | OpenAI 兼容的图片输入;PDF 会以类型化错误拒绝。 |
本地提供方
| 提供方 | Crate / Feature | 对话 | 流式 | 工具调用 | 结构化输出 | 视觉 / 多模态 | 本地推理 |
|---|---|---|---|---|---|---|---|
| Ollama | ollama |
是 | 是 | 是 | 是 | 取决于模型 | 是,通过 Ollama 服务 |
| Mistral-rs | autoagents-mistral-rs |
是 | 是 | 是 | 是 | 支持视觉模型 | 是,嵌入式运行时 |
| Llama-Cpp | autoagents-llamacpp |
是 | 是 | 是 | 是 | 通过 projector 文件支持视觉模型 | 是,嵌入式运行时 |
实验性提供方
详见 https://github.com/liquidos-ai/AutoAgents-Experimental-Backends
| 提供方 | 状态 |
|---|---|
| Burn | ⚠️ 实验性 |
| Onnx | ⚠️ 实验性 |
提供方支持会根据社区需求持续扩展。
* 流式标记为 否 的提供方使用默认的 ChatProvider::chat_stream 实现,返回 LLMError::Generic("Streaming not supported for this provider"),而不会 panic。
安装
先决条件
- Rust(推荐最新稳定版)
- Cargo 包管理器
- LeftHook 用于 Git hooks 管理
Prerequisite
sudo apt update
sudo apt install build-essential libasound2-dev alsa-utils pkg-config libssl-dev -y
安装 LeftHook
macOS(Homebrew):
brew install lefthook
Linux/Windows(npm):
npm install -g lefthook
克隆并构建
git clone https://github.com/liquidos-ai/AutoAgents.git
cd AutoAgents
lefthook install
cargo build --workspace --features full
CUDA、Vulkan 和 Metal 等硬件特定的加速功能需要 匹配的本地工具链和平台。请仅为你正在构建的特定后端 启用这些功能。
Python 绑定
AutoAgents 将 Python 绑定拆分为独立包:
autoagents-py(核心 Python API + 云端后端)autoagents-guardrails-py(适用于 PythonLLMProvider的可选 Guardrails)autoagents-llamacpp-py(可选本地 llama.cpp 后端)autoagents-mistral-rs-py(可选本地 mistral-rs 后端)
从当前仓库进行开发安装:
uv venv --python=3.12
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip install -U pip maturin==1.13.3 pytest pytest-asyncio pytest-cov
# 清理、构建并安装全部 CPU Python 绑定
make python-bindings-build
# 清理、构建并安装 CPU + CUDA Python 绑定
make python-bindings-build-cuda
这些 Make 目标会在重建前删除过期的 editable-install 产物,避免从源码树中加载旧的
.abi3.so 文件。
示例脚本:
- 核心云端示例:
bindings/python/autoagents/examples/openai_agent.py - llama.cpp 示例:
bindings/python/autoagents-llamacpp/examples/llamacpp_agent.py - mistral-rs 示例:
bindings/python/autoagents-mistralrs/examples/mistral_rs_agent.py
运行测试
cargo test --features "full" --workspace
快速开始
use autoagents::core::agent::memory::SlidingWindowMemory;
use autoagents::core::agent::prebuilt::executor::{ReActAgent, ReActAgentOutput};
use autoagents::core::agent::task::Task;
use autoagents::core::agent::{AgentBuilder, AgentDeriveT, AgentOutputT, DirectAgent};
use autoagents::core::error::Error;
use autoagents::core::tool::{ToolCallError, ToolInputT, ToolRuntime, ToolT};
use autoagents::llm::LLMProvider;
use autoagents::llm::backends::openai::OpenAI;
use autoagents::llm::builder::LLMBuilder;
use autoagents_derive::{agent, tool, AgentHooks, AgentOutput, ToolInput};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::sync::Arc;
#[derive(Serialize, Deserialize, ToolInput, Debug)]
pub struct AdditionArgs {
#[input(description = "Left Operand for addition")]
left: i64,
#[input(description = "Right Operand for addition")]
right: i64,
}
#[tool(
name = "Addition",
description = "Use this tool to Add two numbers",
input = AdditionArgs,
)]
struct Addition {}
#[async_trait]
impl ToolRuntime for Addition {
async fn execute(&self, args: Value) -> Result<Value, ToolCallError> {
println!("execute tool: {:?}", args);
let typed_args: AdditionArgs = serde_json::from_value(args)?;
let result = typed_args.left + typed_args.right;
Ok(result.into())
}
}
#[derive(Debug, Serialize, Deserialize, AgentOutput)]
pub struct MathAgentOutput {
#[output(description = "The addition result")]
value: i64,
#[output(description = "Explanation of the logic")]
explanation: String,
#[output(description = "If user asks other than math questions, use this to answer them.")]
generic: Option<String>,
}
#[agent(
name = "math_agent",
description = "You are a Math agent",
tools = [Addition],
output = MathAgentOutput,
)]
#[derive(Default, Clone, AgentHooks)]
pub struct MathAgent {}
impl From<ReActAgentOutput> for MathAgentOutput {
fn from(output: ReActAgentOutput) -> Self {
let resp = output.response;
if output.done && !resp.trim().is_empty() {
if let Ok(value) = serde_json::from_str::<MathAgentOutput>(&resp) {
return value;
}
}
MathAgentOutput {
value: 0,
explanation: resp,
generic: None,
}
}
}
pub async fn simple_agent(llm: Arc<dyn LLMProvider>) -> Result<(), Error> {
let sliding_window_memory = Box::new(SlidingWindowMemory::new(10));
let agent_handle = AgentBuilder::<_, DirectAgent>::new(ReActAgent::new(MathAgent {}))
.llm(llm)
.memory(sliding_window_memory)
.build()
.await?;
let result = agent_handle.agent.run(Task::new("What is 1 + 1?")).await?;
println!("Result: {:?}", result);
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let api_key = std::env::var("OPENAI_API_KEY").unwrap_or("".into());
let llm: Arc<OpenAI> = LLMBuilder::<OpenAI>::new()
.api_key(api_key)
.model("gpt-4o")
.max_tokens(512)
.temperature(0.2)
.build()
.expect("Failed to build LLM");
let _ = simple_agent(llm).await?;
Ok(())
}
AutoAgents CLI
AutoAgents CLI 用于根据 YAML 配置运行智能体工作流,并通过 HTTP 提供服务。可在 https://github.com/liquidos-ai/AutoAgents-CLI 查看。
示例
浏览示例快速上手:
基础
演示多种示例,如带工具的简单智能体、非常基础的智能体、边缘智能体、链式调用、Actor 模型、流式响应以及添加 Agent Hooks。
LLM 流水线
演示带有缓存与重试等优化层的 LLM 流水线,用于提升性能与可靠性。
Guardrails
演示如何在流水线中通过 LLMLayer 使用 Block、Sanitize、Audit 策略配置输入与输出 Guardrails。
MCP 集成
演示如何将 AutoAgents 与 Model Context Protocol (MCP) 集成。
本地模型
演示如何将 AutoAgents 与 Mistral-rs 集成以使用本地模型。
设计模式
演示链式、规划、路由、并行与反思等设计模式。
提供方
包含如何使用不同 LLM 提供方的示例。
WASM 工具执行
一个可在 WASM 运行时中执行工具的简单智能体。
Coding Agent
一个基于 ReAct 的复杂编码智能体,具备文件操作能力。
语音
运行 AutoAgents 语音示例,支持实时 TTS 与 STT。
Android 本地智能体
在 Android 上使用 AutoAgents-llamacpp 后端运行本地模型的示例应用。
组件
AutoAgents 采用模块化架构:
AutoAgents/
├── crates/
│ ├── autoagents/ # Main library entry point
│ ├── autoagents-core/ # Core agent framework
│ ├── autoagents-protocol/ # Shared protocol/event types
│ ├── autoagents-llm/ # LLM provider implementations
│ ├── autoagents-telemetry/ # OpenTelemetry integration
│ ├── autoagents-toolkit/ # Collection of ready-to-use tools
│ ├── autoagents-mistral-rs/ # LLM provider implementations using Mistral-rs
│ ├── autoagents-llamacpp/ # LLM provider implementation using LlamaCpp
│ ├── autoagents-speech/ # Speech model support for TTS and STT
│ ├── autoagents-guardrails/ # LLM Guardrails implementation
│ ├── autoagents-qdrant/ # Qdrant vector store
│ └── autoagents-derive/ # Procedural macros
├── examples/ # Example implementations
├── bindings/ # Bindings for different languages
核心组件
- 智能体:智能能力的基本单元
- 环境:管理智能体生命周期与通信
- 记忆:可配置的记忆系统
- 工具:外部能力集成
- 执行器:不同推理模式(ReAct、Chain-of-Thought)
开发
运行测试
cargo test --features default
# Python 绑定
make python-bindings-test-clean
# Coverage (requires cargo-tarpaulin)
cargo install cargo-tarpaulin
rustup component add llvm-tools-preview
make coverage-rust
运行基准测试
cargo bench -p autoagents-core --bench agent_runtime
Git Hooks
本项目使用 LeftHook 进行 Git hooks 管理。Hooks 将自动:
- 使用
cargo fmt --check格式化代码 - 使用
cargo clippy -- -D warnings运行静态检查 - 使用
cargo test --features full运行 Rust 测试 - 使用
make python-bindings-test运行 Python 绑定测试
贡献
文档
社区
- GitHub Issues:Bug 报告与功能请求
- Discussions:社区问答与想法交流
- Discord:加入我们的 Discord 社区 https://discord.gg/zfAF9MkEtK
性能
AutoAgents 面向高性能设计:
- 内存高效:通过可配置后端优化内存使用
- 并发:完整的 tokio async/await 支持
- 可扩展:多智能体协作的水平扩展能力
- 类型安全:Rust 类型系统的编译期保障
常见问题
安装、提供商、执行器、环境生命周期和故障排除请参阅文档中的 FAQ。
许可证
AutoAgents 采用双许可证:
- MIT License(MIT_LICENSE)
- Apache License 2.0(APACHE_LICENSE)
你可以根据使用场景选择其一。
致谢
由 Liquidos AI 团队与优秀社区研究者和工程师构建。
特别感谢:
- Rust 社区提供的优秀生态
- LLM 提供方带来的高质量模型 API
- 所有帮助改进 AutoAgents 的贡献者
Star 历史
探索相关项目
加载中…