Agent 核心评测指标:首字延迟、完成时间与任务成功率 Agent 核心评测指标首字延迟、完成时间与任务成功率一、Agent 的效果变好了——这句话没有量化就毫无意义Agent 迭代中最危险的信号是主观评价。改了一版 Prompt开发说感觉好了PM 说好像还行然后就上线了。评测不量化迭代就没有方向。Agent 的评测指标应当覆盖三个维度响应性能用户等多久、任务效果是否完成、资源效率消耗了多少 Token/钱。首字延迟TTFT、端到端完成时间、任务成功率是三个核心指标。二、三大核心指标的定义与关系graph LR A[用户发送消息] -- B[TTFTbr/首字延迟] B -- C[TTCTbr/任务完成时间] B -.- B1[指标: Time To First Tokenbr/目标: 1sbr/测量: 从请求到第一个字的时间] C -.- C1[指标: Time To Complete Taskbr/目标: 30sbr/测量: 从请求到最终输出的时间] A -- D[任务成功率br/(Task Success Rate)] D -- D1[是否完成用户意图br/- 自动化评测br/- LLM Judge 评分br/- 用户反馈加权] style B fill:#4A90D9,color:#fff style C fill:#F5A623,color:#000 style D fill:#50B86C,color:#fff指标 1: 首字延迟TTFT定义从用户发送消息到第一个字符/Token 返回的时间。为什么重要TTFT 决定用户的等待感。人类对反馈的期望在 1 秒内。超过 3 秒用户就会觉得卡。计算TTFT T(first_token_generated) - T(request_sent)目标P50 500ms, P95 1s, P99 2s影响因素LLM 服务的排队时间Prompt 处理时间模型推理的 prefill 阶段处理输入 tokens指标 2: 任务完成时间TTCT定义从用户发送消息到 Agent 输出最终结果的总时间。包含工具调用轮次。计算TTCT T(final_response_complete) - T(request_sent)目标P50 15s, P95 30s影响因素LLM 生成 Token 数 × 每个 Token 的生成时间工具调用的轮次 × 每轮工具的响应时间网络延迟指标 3: 任务成功率Task Success Rate定义Agent 是否成功完成用户意图。为什么复杂成功没有标准定义。翻译任务的成功可以通过 BLEU/BERTScore 自动评测但帮我写一封道歉信的成功需要人类判断。三、三项指标的生产级采集 Agent 核心评测指标采集器 采集 TTFT、TTCT、任务成功率 import time import json from dataclasses import dataclass, field from typing import Dict, List, Optional from prometheus_client import Histogram, Counter, Gauge # Prometheus 指标定义 agent_ttft_seconds Histogram( agent_ttft_seconds, Time To First Token (seconds), buckets[0.1, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0, 10.0], ) agent_ttct_seconds Histogram( agent_ttct_seconds, Time To Complete Task (seconds), buckets[1, 2.5, 5, 10, 15, 20, 30, 45, 60, 120, 300], ) agent_task_total Counter( agent_task_total, Total agent tasks, [status], # success, partial_success, failure ) agent_tokens_used Counter( agent_tokens_used, Total tokens consumed, [type], # prompt, completion ) agent_tool_calls Histogram( agent_tool_calls_per_task, Number of tool calls per task, buckets[0, 1, 2, 3, 5, 8, 10, 15], ) dataclass class AgentMetrics: 单次 Agent 调用的评测指标 session_id: str turn_id: str # 时间指标 request_time: float 0.0 first_token_time: float 0.0 completion_time: float 0.0 # Token 指标 prompt_tokens: int 0 completion_tokens: int 0 # 工具调用 tool_calls_count: int 0 tool_calls_detail: List[Dict] field(default_factorylist) # 任务结果 task_status: str unknown # success, partial_success, failure final_response: str property def ttft_sec(self) - float: return self.first_token_time - self.request_time property def ttct_sec(self) - float: return self.completion_time - self.request_time def to_prometheus(self): 上报指标到 Prometheus agent_ttft_seconds.observe(self.ttft_sec) agent_ttct_seconds.observe(self.ttct_sec) agent_task_total.labels(statusself.task_status).inc() agent_tokens_used.labels(typeprompt).inc(self.prompt_tokens) agent_tokens_used.labels(typecompletion).inc(self.completion_tokens) agent_tool_calls.observe(self.tool_calls_count) class AgentMetricsCollector: Agent 评测指标采集器 def __init__(self): self.current_metrics: Optional[AgentMetrics] None def start_tracking(self, session_id: str, turn_id: str) - AgentMetrics: 开始追踪一次 Agent 调用 self.current_metrics AgentMetrics( session_idsession_id, turn_idturn_id, request_timetime.time(), ) return self.current_metrics def record_first_token(self): 记录首字时间 if self.current_metrics: self.current_metrics.first_token_time time.time() def record_completion( self, status: str, response: str, prompt_tokens: int, completion_tokens: int, tool_calls: List[Dict], ): 记录任务完成 if not self.current_metrics: return self.current_metrics.completion_time time.time() self.current_metrics.task_status status self.current_metrics.final_response response self.current_metrics.prompt_tokens prompt_tokens self.current_metrics.completion_tokens completion_tokens self.current_metrics.tool_calls_count len(tool_calls) self.current_metrics.tool_calls_detail tool_calls # 上报到 Prometheus self.current_metrics.to_prometheus() # 输出日志 self._log_metrics(self.current_metrics) def _log_metrics(self, m: AgentMetrics): 记录评测指标到结构化日志 log_entry { type: agent_metrics, session_id: m.session_id, turn_id: m.turn_id, ttft_ms: round(m.ttft_sec * 1000, 1), ttct_ms: round(m.ttct_sec * 1000, 1), prompt_tokens: m.prompt_tokens, completion_tokens: m.completion_tokens, total_tokens: m.prompt_tokens m.completion_tokens, tool_calls: m.tool_calls_count, status: m.task_status, tools_detail: [ {name: tc.get(name, ), duration_ms: tc.get(duration_ms, 0)} for tc in m.tool_calls_detail ], } print(json.dumps(log_entry))四、三项指标的关系与解读场景TTFTTTCT任务成功率诊断正常0.8s12s92%✅模型升级后0.6s15s88%新模型更快但质量下降Prompt 改后1.2s20s95%更详细的 Prompt 增加延迟但提高质量排队拥堵5s25s92%LLM 服务过载需扩容缺点任务成功率的主观性即使用 LLM Judge 评测不同的评价模型给出的成功率可能差 10%。首字延迟的误导性TTFT 只是第一个字的时间用户感知延迟是整个响应的时间。如果 TTFT 是 0.3s 但之后每字 0.5s用户体验仍然差。缺乏归一化300 Token 的回答和 3000 Token 的回答TTCT 自然不同。需要在评测中按 Token 数量归一化。五、总结Agent 评测的三个核心指标首字延迟TTFT决定等待感、任务完成时间TTCT反映整体效率、任务成功率衡量有没有用。三者需要共同观察——单独优化任何一个都可能导致其他劣化如降低 TTFT 可能缩短 Prompt 导致成功率下降。指标采集通过 Prometheus 上报实时监控通过结构化日志做离线分析。

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/9/25 12:45:43
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/24 14:25:52
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/26 3:42:08
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/9/23 8:01:38
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/26 4:08:27
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/25 15:49:36

日新闻

周新闻