Skip to content
🔗 分享本题
查看我的学习进度 →

Agent 评测结合离线基准、分层评审和在线监控形成持续改进闭环

🧠 记忆锚点:别只看最终答案;评任务、轨迹、工具、恢复、成本与安全。

💡 答案要点

Agent评测 = 用标准化任务集量化Agent在规划/工具使用/多轮交互的能力

评测维度

维度含义指标
任务成功率从头到尾完成任务成功率%
工具使用准确性选对工具+正确参数工具调用准确率
规划效率步骤数 vs 最优步骤数效率比
鲁棒性面对错误/噪声的恢复能力错误恢复率
成本效率完成任务的Token/时间开销Cost per task

主流Benchmark

1. AgentBench(清华/伯克利)

python
# 8种真实环境测试
environments = {
    "OS": "操作系统Shell命令",
    "DB": "数据库SQL查询",
    "KG": "知识图谱推理",
    "WebShop": "网购任务",
    "WebArena": "网页操作",
    "HumanEval": "代码生成",
    "Mind2Web": "网页导航",
    "Card Game": "卡牌游戏策略",
}

# GPT-4在AgentBench的表现
gpt4_scores = {
    "OS": 0.58,
    "DB": 0.33,
    "KG": 0.92,
    "WebShop": 0.40,
    # 开源模型普遍<0.05
}

2. 自建Benchmark(生产环境推荐)

展开 Python 代码示例(107 行)
python
class AgentBenchmark:
    """针对业务场景的自定义评测"""

    def __init__(self, agent, test_cases):
        self.agent = agent
        self.test_cases = test_cases  # 标注好的测试集

    def evaluate(self):
        results = {
            "task_success": [],      # 任务成功率
            "tool_accuracy": [],     # 工具调用准确率
            "step_efficiency": [],   # 步骤效率
            "cost": [],             # Token消耗
        }

        for case in self.test_cases:
            start_time = time.time()

            # 运行Agent
            try:
                result = self.agent.run(case["input"])
                success = self.evaluate_success(result, case["expected_output"])
            except Exception as e:
                success = False
                result = None

            elapsed = time.time() - start_time

            # 记录指标
            results["task_success"].append(success)

            if hasattr(self.agent, "tool_calls_log"):
                tool_acc = self.evaluate_tool_accuracy(
                    self.agent.tool_calls_log,
                    case["expected_tools"]
                )
                results["tool_accuracy"].append(tool_acc)

            results["cost"].append(self.agent.total_tokens)

        # 汇总
        return {
            "task_success_rate": sum(results["task_success"]) / len(results["task_success"]),
            "avg_tool_accuracy": sum(results["tool_accuracy"]) / len(results["tool_accuracy"]),
            "avg_tokens_per_task": sum(results["cost"]) / len(results["cost"]),
        }

    def evaluate_success(self, result, expected):
        """评估任务是否成功"""
        # 方式1:精确匹配
        if result == expected:
            return True

        # 方式2:语义相似度
        similarity = compute_similarity(result, expected)
        return similarity > 0.85

        # 方式3:LLM-as-Judge
        judge_prompt = f"""
        预期答案:{expected}
        Agent实际输出:{result}

        Agent是否正确完成了任务?(是/否):
        """
        judgment = llm.generate(judge_prompt, temperature=0)
        return "是" in judgment

    def evaluate_tool_accuracy(self, actual_calls, expected_calls):
        """评估工具调用准确率"""
        if not expected_calls:
            return 1.0

        correct = 0
        for i, (actual, expected) in enumerate(zip(actual_calls, expected_calls)):
            # 工具名正确
            if actual["tool"] == expected["tool"]:
                correct += 0.5

            # 参数正确
            param_match = sum(
                actual["params"].get(k) == v
                for k, v in expected["params"].items()
            ) / len(expected["params"])
            correct += 0.5 * param_match

        return correct / len(expected_calls)

# 使用
test_cases = [
    {
        "input": "查询北京明天天气",
        "expected_output": "明天北京气温X度,晴天",
        "expected_tools": [{"tool": "weather_api", "params": {"city": "北京", "date": "tomorrow"}}]
    },
    {
        "input": "帮我发邮件给张三,告诉他明天开会",
        "expected_output": "邮件已发送",
        "expected_tools": [{"tool": "send_email", "params": {"to": "[email protected]", "subject": "开会通知"}}]
    }
]

benchmark = AgentBenchmark(my_agent, test_cases)
scores = benchmark.evaluate()

print(f"任务成功率: {scores['task_success_rate']:.1%}")
print(f"工具准确率: {scores['avg_tool_accuracy']:.1%}")
print(f"平均Token消耗: {scores['avg_tokens_per_task']:.0f}")

持续评测体系

展开 Python 代码示例(35 行)
python
class AgentMonitor:
    """生产环境持续监控"""

    def log_interaction(self, session_id, query, result, tools_used, tokens):
        """记录每次Agent交互"""
        record = {
            "session_id": session_id,
            "timestamp": time.time(),
            "query": query,
            "result": result,
            "tools_used": tools_used,
            "tokens": tokens,
            "user_feedback": None  # 后续收集
        }
        self.db.insert(record)

    def collect_feedback(self, session_id, rating: int, comment: str = ""):
        """收集用户反馈(1-5星)"""
        self.db.update(session_id, {
            "user_feedback": rating,
            "comment": comment
        })

    def generate_weekly_report(self):
        """每周评测报告"""
        records = self.db.query_last_7_days()

        return {
            "total_sessions": len(records),
            "success_rate": self.calc_success_rate(records),
            "avg_feedback": self.calc_avg_feedback(records),
            "tool_usage_stats": self.calc_tool_stats(records),
            "failure_cases": self.find_failures(records),
            "cost_summary": sum(r["tokens"] for r in records)
        }

面试话术:

示例表达(仅在能用本人经历或可复现实验佐证时使用): "Agent评测分离线和在线两套。离线用自建Benchmark:覆盖任务成功率、工具调用准确率、步骤效率、Token成本4个维度,测试集至少100条覆盖各种边界情况。评判方式用LLM-as-Judge,比精确匹配更灵活,准确率和人工评估一致性>85%。在线用生产监控:记录每次交互,收集用户1-5星反馈,每周生成报告。我们的Agent上线后,通过持续评测发现工具参数错误率偏高,针对性优化Prompt后,工具准确率从72%→91%。"

📚 参考:AgentBench:Evaluating LLMs as Agents(原论文)


主流 Benchmark 三:VAKRA(IBM Research 2026年4月新版企业级Agent评测)

VAKRA = Tool-grounded, Executable Benchmark for Enterprise Agents

维度说明
发布时间2026年4月15日
发布方IBM Research
定位企业级 API Agent 评测基准
规模8000+ 本地托管 API,62个领域,真实数据库
核心特点可执行环境 + 完整执行轨迹

四大评测任务:

任务测试能力实例数工具数
API Chaining商业智能 API 链式调用2077SLOT-BIRD + SEL-BIRD
Tool Selection从仪表板 API 中选择正确工具1597REST-BIRD,6-328个/域
Multi-Hop Reasoning多跳推理869REST-BIRD
Doc Retrieval + API文档检索 + API 调用混合待确认MCP 协议

VAKRA vs 传统 Benchmark:

维度传统 Benchmark(AgentBench等)VAKRA
环境模拟/离线评测真实可执行环境
API静态测试用例8000+ 真实 API
数据人工构造真实数据库
执行不可执行MCP 协议真实调用
评测方式最终答案匹配完整执行轨迹验证

VAKRA 的 MCP 架构亮点:

python
# VAKRA 使用 MCP 协议连接 API
# get_data(tool_universe_id) 初始化数据源
# 避免大量数据通过 MCP 传输

# API 选择限制:OpenAI API 最多 128 个工具
# VAKRA 提供 tool shortlisting 机制处理这个问题

关键洞察:模型在 VAKRA 上表现很差

"Unlike traditional benchmarks that test isolated skills, VAKRA measures compositional reasoning across APIs and documents... models perform poorly on VAKRA"

这说明:

  • 即使是 GPT-4,在真实企业 API 场景下也表现不佳
  • API Agent 的评测需要真实执行环境,而非静态测试
  • 2026 年企业级 Agent 岗位面试,VAKRA 代表了"真实能力评估"的新方向

面试话术:

"VAKRA 是 2026年4月 IBM Research 发布的企业级 Agent 评测基准,和传统 Benchmark 的本质区别是'真实可执行'——8000+ 真实 API、真实数据库、MCP 协议调用,不是静态测试用例。四个任务覆盖 API 链式调用、工具选择、多跳推理、文档+API 混合。关键洞察是'模型在 VAKRA 上表现很差',这告诉我们:即使 GPT-4 在简单场景下很强,在真实企业 API 环境里也远未达到可靠水平。面试时能说出 VAKRA 的特点,说明你对 Agent 评测有实战理解,不只是纸上谈兵。"