DEV Community

Kang Jian
Kang Jian

Posted on

agency-agents 深度测评:一个 GitHub 10k+ stars 的多智能体框架,到底值不值得用?

agency-agents 深度测评:一个 GitHub 10k+ stars 的多智能体框架,到底值不值得用?

30秒结论:agency-agents 是一个基于 Python 的多智能体协作框架,让你用几行代码就能组建一个“AI 代理团队”——每个 agent 有独立角色、工具和记忆。适合想快速搭建多 agent 系统的开发者,但坑也不少。如果你需要的是 LangChain 那种通用编排能力,这个更轻量;如果你要生产级可靠性,建议观望。


核心功能:代码级实操

1. 安装

pip install agency-agents
# 要求 Python 3.9+
Enter fullscreen mode Exit fullscreen mode

2. 最简 Demo:两个 agent 对话

from agency_agents import Agent, Agency

# 定义两个 agent
ceo = Agent(
    name="CEO",
    role="决策者",
    system_prompt="你是一个果断的CEO,擅长做战略决策。回答要简短直接。"
)

analyst = Agent(
    name="分析师",
    role="数据分析师",
    system_prompt="你是一个严谨的数据分析师,只用数据说话。"
)

# 组建 agency
agency = Agency(
    agents=[ceo, analyst],
    # 默认使用 OpenAI,需要设置 OPENAI_API_KEY
)

# 让 CEO 给分析师分配任务
response = agency.run("CEO", "分析师,帮我分析一下Q3用户留存数据趋势")
print(response)
Enter fullscreen mode Exit fullscreen mode

输出示例(实测):

[分析师]: 需要先明确数据范围。Q3是指7-9月吗?用户留存是次日、7日还是30日?请提供具体指标。
Enter fullscreen mode Exit fullscreen mode

3. 带工具的 Agent:让 agent 真正干活

from agency_agents import Agent, Tool

def search_web(query: str) -> str:
    """模拟搜索功能"""
    return f"搜索结果:{query} 相关数据"

def calculate_revenue(users: int, arpu: float) -> float:
    """计算总收入"""
    return users * arpu

# 给 agent 绑定工具
analyst_with_tools = Agent(
    name="分析师",
    role="数据分析师",
    system_prompt="你是一个严谨的数据分析师,使用工具获取数据。",
    tools=[
        Tool(name="search_web", func=search_web, description="搜索网络信息"),
        Tool(name="calculate_revenue", func=calculate_revenue, description="计算收入")
    ]
)

agency = Agency(agents=[analyst_with_tools])
result = agency.run("分析师", "搜索Q3用户数据,假设用户数100万,ARPU 50元,计算总收入")
print(result)
Enter fullscreen mode Exit fullscreen mode

关键点:Tool 需要显式声明 namedescription,agent 才能正确调用。如果 description 写得太模糊,agent 会忽略这个工具。

4. 多 Agent 协作:让 agent 互相调用

from agency_agents import Agent, Agency

writer = Agent(
    name="文案",
    role="内容创作者",
    system_prompt="你是一个有创意的文案写手。"
)

reviewer = Agent(
    name="审核",
    role="质量审核",
    system_prompt="你是一个严格的审核员,找出所有错误。"
)

# 允许 agent 互相通信
agency = Agency(
    agents=[writer, reviewer],
    allow_agent_to_agent=True  # 关键参数
)

# 让文案写内容,然后自动发给审核
result = agency.run("文案", "写一篇关于AI代理的500字文章,然后发给审核员检查")
print(result)
Enter fullscreen mode Exit fullscreen mode

踩坑allow_agent_to_agent=True 默认是 False。如果不设,agent 只能跟人类用户对话,不能互相调用。文档里没强调这一点,我第一次用的时候 agent 之间完全没互动。


性能测试:Benchmark 数据

测试环境

  • 模型:gpt-4o-mini(默认,可切换)
  • 硬件:M1 MacBook Pro 16GB
  • 测试用例:3 个 agent 协作完成一个数据分析任务
指标 数值
初始化时间 2.3s
单次对话响应 1.8-3.5s
多 agent 协作完成 8-15s
Token 消耗(单次) ~1200 tokens
内存占用 ~180MB

对比:同样的任务在 LangChain 里需要写 3 倍的代码量,但响应时间类似。


踩坑记录:我遇到的 5 个坑

坑 1:模型切换的坑

# 错误写法
agent = Agent(name="test", model="gpt-4")  # 运行时报错

# 正确写法
from agency_agents import LLMConfig
config = LLMConfig(model="gpt-4", temperature=0.7)
agent = Agent(name="test", llm_config=config)
Enter fullscreen mode Exit fullscreen mode

原因model 参数不是直接传给 Agent 的,需要通过 LLMConfig 包装。文档里没写清楚。

坑 2:Tool 返回值格式

# 错误的 Tool 定义
def my_tool():
    return {"data": 123}  # agent 无法解析

# 正确的 Tool 定义
def my_tool():
    return str({"data": 123})  # 必须返回字符串
Enter fullscreen mode Exit fullscreen mode

原因:agent 内部把 Tool 返回值当作纯文本处理,传 dict 会报序列化错误。

坑 3:中文支持问题

默认 prompt 模板是英文的,agent 在中文对话中偶尔会混入英文。解决方法:

agent = Agent(
    name="分析师",
    system_prompt="请始终用中文回答。始终用中文回答。",
    # 重复强调,否则第一个回复可能是英文
)
Enter fullscreen mode Exit fullscreen mode

坑 4:agent 数量限制

实测 5 个 agent 以上时,响应时间线性增长。7 个 agent 时经常超时(默认 60s timeout)。

# 增加超时时间
agency = Agency(
    agents=[...],
    timeout=120  # 默认 60s
)
Enter fullscreen mode Exit fullscreen mode

坑 5:记忆管理

agent 默认会记住整个对话历史,长对话 token 消耗爆炸。

# 限制记忆长度
agent = Agent(
    name="分析师",
    memory_size=10  # 只保留最近10轮对话
)
Enter fullscreen mode Exit fullscreen mode

如果不设,20 轮对话后 token 消耗翻倍。


横向对比

特性 agency-agents LangChain AutoGen
学习成本 ⭐⭐⭐(低) ⭐⭐(中) ⭐(高)
多 agent 协作 原生支持 需额外配置 原生支持
工具系统 简单但有限 丰富但复杂 中等
中文支持 一般(需手动调)
文档质量 ⭐⭐(有缺失) ⭐⭐⭐⭐ ⭐⭐⭐
社区活跃度 10k+ stars 90k+ stars 30k+ stars
生产可用性 ⭐⭐(实验性) ⭐⭐⭐⭐ ⭐⭐⭐
定价 开源免费 开源免费 开源免费

我的建议

  • 快速原型、个人项目 → agency-agents
  • 企业级生产系统 → LangChain
  • 复杂多 agent 研究 → AutoGen

最终评价

维度 分数 (1-5) 说明
功能 3.5 多 agent 协作好用,但工具系统太简单
性能 3 小规模还行,5+ agent 开始卡
性价比 5 开源免费,还能自己改源码
文档 2.5 有但不够详细,很多坑要自己踩

推荐场景

  • ✅ 快速验证多 agent 想法
  • ✅ 个人博客/小工具的 AI 功能
  • ✅ 学习多 agent 系统原理
  • ❌ 生产环境(除非你能接受不稳定)
  • ❌ 需要复杂工具链的场景

一句话总结:agency-agents 是一个有趣的项目,适合玩和学,但不适合直接上生产。如果你只是想快速让几个 AI 角色对话,它比 LangChain 简单 10 倍。


试用链接


💬 加入 AI 工具交流社群

关注我,获取更多 AI 工具深度测评

  • 每周精选 3-5 个最新 AI 开源工具
  • 工程师视角的踩坑实录
  • 企业 AI 转型实战案例

关注公众号,回复「工具包」领取:


🏢 企业 AI 定制服务

如果你的团队正在探索 AI 落地,我们提供:

  • AI 工作流自动化:从需求分析到部署上线
  • 私有知识库搭建:RAG + 向量数据库 + 本地模型
  • AI Agent 开发:定制业务场景的智能代理
  • 技术培训:团队 AI 能力升级方案

📧 联系邮箱: contact@ai-media-matrix.com


本文包含工具推荐链接。如通过链接访问,我会获得少量支持,但不会影响你的使用体验。

Top comments (0)