J'Blog

13 课 · 进阶

语义检索

基于 Chroma 向量库,与 Workspace 知识库分离。用自然语言描述你想查的内容。 非管理员每人每天可检索 5 次(消耗站点 AI 配额)。

智能体性能评估

原文:Hello-Agents · 第十二章 智能体性能评估 · 在线阅读

一句话

智能体性能评估系统提供了标准化的方法来衡量智能体的能力,包括工具调用能力评估(BFCL)、通用能力评估(GAIA)和数据生成质量评估(AIME)。

什么时候翻这页

当你需要客观评估智能体的性能,比较不同设计方案优劣,或确保智能体在生产环境中的可靠性时。

核心概念

  • 性能评估系统(Evaluation System):提供标准化的方法衡量智能体能力
  • 评估基准(Benchmark):统一的数据集、评估指标和评分方法
  • BFCL(Berkeley Function Calling Leaderboard):UC Berkeley推出,包含1120+测试样本,涵盖simple、multiple、parallel、irrelevance四个类别,使用AST匹配算法
  • GAIA(General AI Assistants):Meta AI和Hugging Face联合推出,包含466个真实世界问题,分为Level 1/2/3三个难度级别,使用准精确匹配算法
  • AST匹配(Abstract Syntax Tree Matching):将函数调用解析为语法树,比较树的结构和节点值
  • 准精确匹配(Quasi Exact Match):允许答案在语义上等价但不完全相同的匹配算法
  • LLM Judge:使用大语言模型作为评委评估生成数据质量
  • Win Rate:通过成对对比评估生成数据相对于参考数据的质量

怎么做

BFCL评估工具调用能力

  1. 安装依赖:
pip install "hello-agents[evaluation]==0.2.7"
pip install "numpy==1.26.4" bfcl-eval
  1. 克隆BFCL仓库:
git clone https://github.com/ShishirPatil/gorilla.git temp_gorilla
cd temp_gorilla/berkeley-function-call-leaderboard
  1. 使用BFCLEvaluationTool评估:
from hello_agents import SimpleAgent, HelloAgentsLLM
from hello_agents.tools import BFCLEvaluationTool

# 创建智能体
llm = HelloAgentsLLM()
agent = SimpleAgent(name="TestAgent", llm=llm)

# 创建评估工具
bfcl_tool = BFCLEvaluationTool()

# 运行评估
results = bfcl_tool.run(
    agent=agent,
    category="simple_python",
    max_samples=5
)

GAIA评估通用能力

  1. 设置环境变量:
export HF_TOKEN="your_huggingface_token"
  1. 使用GIAEvaluationTool评估:
from hello_agents.tools import GIAEvaluationTool

# 创建评估工具
gaia_tool = GIAEvaluationTool()

# 运行评估
results = gaia_tool.run(
    agent=agent,
    level=1,  # 1/2/3
    max_samples=5
)

数据生成质量评估

  1. 生成AIME题目:
from hello_agents.tools import AIMEGenerator

# 创建生成器
generator = AIMEGenerator(delay_seconds=3.0)

# 生成题目
generated_data_path = generator.generate_and_save(
    num_problems=30,
    output_dir="data_generation/generated_data"
)
  1. 使用LLM Judge评估:
from hello_agents.tools import LLMJudgeTool

# 创建评估工具
llm_judge_tool = LLMJudgeTool(llm=llm)

# 运行评估
results = llm_judge_tool.run({
    "generated_data_path": generated_data_path,
    "reference_year": 2025,
    "max_samples": 30,
    "judge_model": "gpt-4o"
})
  1. 使用Win Rate评估:
from hello_agents.tools import WinRateTool

# 创建评估工具
win_rate_tool = WinRateTool(llm=llm)

# 运行评估
results = win_rate_tool.run({
    "generated_data_path": generated_data_path,
    "reference_year": 2025,
    "num_comparisons": 20,
    "judge_model": "gpt-4o"
})
  1. 启动人工验证界面:
python data_generation/human_verification_ui.py data_generation/generated_data/aime_generated_XXXXXX.json

命令 / 代码速查

  • 安装评估模块:pip install "hello-agents[evaluation]==0.2.7"
  • 安装BFCL评估工具:pip install "numpy==1.26.4" bfcl-eval
  • 克隆BFCL仓库:git clone https://github.com/ShishirPatil/gorilla.git temp_gorilla
  • 运行BFCL评估脚本:python chapter12/04_run_bfcl_evaluation.py --category simple_python --samples 10
  • 运行完整评估流程:python data_generation/run_complete_evaluation.py 30 3.0
  • 启动人工验证界面:python data_generation/human_verification_ui.py <data_path>

与 Python / Claude Code 手册的联系

本章节中的评估工具使用Python实现,与Python手册中的数据处理、API调用和错误处理相关。评估流程中的提示词设计与Claude Code手册中的提示词工程章节有密切联系。

初学者易错点

  1. BFCL评估中,AST匹配比简单字符串匹配更智能,但需要注意参数顺序和等价表达式的处理。
  2. GAIA评估使用准精确匹配,允许答案在语义上等价但不完全相同。
  3. 数据生成评估中,建议使用2-3秒的延迟避免API速率限制。
  4. 评估结果可能受LLM模型能力影响,建议使用高性能模型(如GPT-4)作为评委。

相关词条

官方原文:https://github.com/datawhalechina/hello-agents/blob/main/docs/chapter12/%E7%AC%AC%E5%8D%81%E4%BA%8C%E7%AB%A0%20%E6%99%BA%E8%83%BD%E4%BD%93%E6%80%A7%E8%83%BD%E8%AF%84%E4%BC%B0