返回列表
🧠 阿头学 · 💬 讨论题

度量标准即宪法:编码代理自我改进的工程控制权转移

编码代理的自我迭代能力已实质成熟,但工程控制权已从“编写实现代码”彻底上移至“定义不可作弊的度量标准”,拒绝掌握该控制权的团队必将被自动化循环反噬。
打开原文 ↗

2026-08-11 原文链接 ↗
阅读简报
双语对照
完整翻译
原文
讨论归档

核心观点

  • 度量标准取代代码成为核心工程产物:自动化工具的演进已将人类工作重心从实现逻辑推至定义标准,工程师必须将模糊业务规则转化为可版本控制、防钻空子的硬性指标,否则代理将系统性优化出高分低质的结果。
  • 评判权与提案权必须物理隔离:自我改进循环会本能地迎合肤浅目标并自我粉饰,唯有将评分机制外置、强制返回改进理由并锁定留出集,才能阻断“运动员自判”导致的系统性腐败。
  • 评估与可观测性本质是同一循环的两种采样:开发期测试集与生产期真实流量共享同一套质量定义,离线评估标准直接复用为线上监控规则,能彻底消除传统软件中测试与监控割裂带来的维护成本与分布偏移盲区。
  • 行为导向评分优于轨迹精确匹配:代理实现路径的多样性不应被惩罚,评估必须聚焦最终输出结果而非中间调用顺序,否则将扼杀合理创新并导致代理陷入局部最优。

跟我们的关联

  • 对 ATou 意味着工程重心必须从“写代码”转向“写宪法”:开发者需放弃依赖通用基准测试的惰性,下一步应立即提取一个高频失败场景,编写返回明确裁决理由的自定义度量脚本,并将其接入编码代理的迭代循环。
  • 对 Neta 意味着架构设计必须强制实现“提出-评判”分离:系统需内置防作弊机制,下一步应在 CI/CD 流程中部署独立评分服务,严格锁定留出集阈值,禁止优化器动态修改通过标准。
  • 对 Uota 意味着业务规则必须完成从“主观经验”到“可执行指标”的硬编码:产品与合规团队不能仅停留在文档层面,下一步需将核心挽留策略、合规底线转化为二值化检查函数,并直接复用于生产流量监控以捕获真实分布偏移。

讨论引子

  • 当度量标准本身存在盲区时,如何设计“元评估”机制来防止自动化循环在错误方向上高效狂奔?
  • 在复杂多轮交互或创意生成场景中,行为导向评分与轨迹匹配如何平衡,单案例启动法是否会因信噪比过高而陷入局部最优?
  • 将评估与可观测性统一后,面对生产环境的概念漂移与对抗性输入,同一套度量标准应如何动态演进而不丧失基线稳定性?

By @Saboo_Shubham_ and @secchi_elia

当编码代理(coding agents)编写代码时,定义什么是"好"才是真正的工程工作。

编码代理现在可以构建并改进其他代理。编写指令,运行代理,发现失败之处,重写,重复。这个自我改进的循环(self-improving loop)现已交付。将其自动化,正是 agents-cli 的大部分工作——这是我们用于在 Google Cloud 上构建代理的开源 CLI 和技能集(skills)。

但这个循环存在一个盲区。

给它一个肤浅的目标,它会把你的代理优化成某种得分很高但实际表现更差的东西。然后它会报告成功。因为按照它自己的衡量标准,它确实成功了。

这个循环可以自动化一切,唯独不能告诉你"更好"意味着什么。

度量标准(metric)是你现在编写的产物。 定义什么是好的,并将其衡量得足够好,使循环能够朝着它改进——这才是工程判断力的体现。本文将介绍这个循环如何运行、人类在何处保持控制,以及让它保持诚实的七条规则。

http://google.github.io/agents-cli

度量标准(metric)是你现在编写的产物

软件团队早就明白,你衡量什么就会得到什么。这个循环让这句话成了字面意思。它会改进你给出的任何数字,而循环内部没有任何东西能区分一个反映你真实需求的目标和一个仅仅得分很高的目标。

在构建这个工具的过程中,我们不断重新学到这一点。度量标准位于提示词(prompt)、代码和行为的上游。循环会重塑这三者,以适应它所奖励的任何东西。

每一次工具进步都将努力向上推进了一个层级。从汇编到编译器,从编译器到框架。这一次,它从产物(artifact)推进到了标准。

质量是具体的,而且它属于你

真正重要的"好"的定义,很少是公共基准测试(benchmark)所衡量的那个。它是退款政策。是升级规则。是合规底线。是你的客户能识别出的语气。

通用模型不知道这些,通用测试也不会检查它们。

考虑一个支持代理,其规则是在确认取消之前提供挽留路径。模型可以在推理过程中遵循该规则,却在最终回复中将其遗漏。我们见过代理恰恰以这种形态失败:内部状态正确,调用了正确的工具,但发给用户的最终消息仍然回显了一个过时的值。没有崩溃。粗略一看输出也没问题。但用户收到的答案是错的。

只有对回复而非推理过程进行评分的评估(evaluation)才能发现这一点。 而且没有任何公共度量标准知道你的挽留规则存在。因此你自己定义一个:自定义度量标准 retention_offered,返回 0 或 1,以及一句简短的裁决理由。将其写下后,这个定义就归你所有,你可以为其做版本控制,并在出现新的失败时不断完善它。

循环的实践

agents-cli 将这个循环转化为几条命令,在基于 Agent Development Kit (ADK) 构建的代理上运行。将其安装到你的编码代理中:

agents-cli 将度量与改进循环(measure-and-improve loop)转化为几条命令,在基于 Agent Development Kit (ADK) 构建的代理上运行。将其安装到你的编码代理中:

https://google.github.io/agents-cli/

然后描述你想度量什么。

以前面的支持代理为例。没有任何公共度量标准能捕捉其挽留规则,因此你自己定义一个:自定义度量标准 retention_offered,返回 0 或 1,以及一句简短的裁决理由。这个定义就是评判其他一切的标准。

编码代理首先在一组案例上运行你的代理,以生成追踪记录(traces):

agents-cli eval grade \
  --traces artifacts/traces/ \
  --config tests/eval/eval_config.yaml

此时诱人的捷径是让编码代理读取自己的输出并决定是否通过。被要求评判自己回复的代理会乐观地打分,而那些真正重要的失败恰恰是它放行的那种。

评分(Grading)打破了这种循环。每条追踪记录都依据你的度量标准进行打分,这是一个编码代理无法撼动的标准,因此修复方案是由提出它之外的东西来评判的:

uvx google-agents-cli setup

现在循环可以自行改进了。每个失败的案例都会返回度量标准自身的理由,而这个理由就是下一次尝试的方向。编码代理读取它,编辑代理的指令,然后重新运行。接着它比较两次运行结果,以确认这次改动有所帮助,且没有破坏其他任何东西:

agents-cli eval compare \
  artifacts/grade_results/results_baseline.json \
  artifacts/grade_results/results_after_fix.json

这个循环(提出修复、评分、根据理由修订)就是整个优化过程。 它在你的检查点之间无人值守地运行:你设定目标并保留留出集(held-out set),循环所需的一切导向都已在你编写的度量标准中。

https://x.com/@secchi_elia

自我改进循环的七条规则

自动化循环是容易的部分。困难的部分是让人类保持对某个设计为无人值守运行的事物的控制。这七条规则就是方法,而且它们现已内置于 agents-cli 的技能(skills)本身。

规则 1:从一个案例开始,而非一套测试集。 一个失败的案例告诉你下一步该修复什么。二十个案例则什么都不会告诉你。预计需要五到十次迭代才能通过。这很正常。只有当它稳定通过后,才添加下一个案例。

规则 2:让评判者(judges)解释自己。 一个数字只说明你失败了。理由则说明该改什么,而理由正是下一次迭代编写的依据。确定性检查(deterministic checks)除外,因为断言本身就是解释。

规则 3:只要答案是确定性的,就使用代码。 "它是否在确认前调用了挽留工具?" 这是一个 Python 函数。精确、免费、没有评判者方差(judge variance)。把评判者留给语气、完整性、解释是否站得住脚这些方面。

规则 4:给行为打分,而非路径。 一个在查天气之前进行地理编码(geocodes)的代理并没有错。精确匹配轨迹(Exact-match trajectories)最终衡量的是代理改变了多少,而不是它有多好。

规则 5:将不稳定的案例(flaky case)视为一项发现。 在完全相同的运行之间波动的分数意味着你的代理存在你未曾注意到的非确定性(non-deterministic),或者你的评判者存在。多运行几次该案例,看看是哪个在波动。删除它只是消除了证据,而非行为本身。

规则 6:永远不要让提出者(proposer)移动门槛。 门槛有三种移动方式:降低阈值、编辑预期输出、悄悄删除案例。这三种看起来都像是分数在提高。这正是留出切片(held-out slice)的用途。真正的提升也会在那里显现。而取巧的(gamed)提升则不会。

规则 7:只在最后自动优化一次。 提示词优化(Prompt optimization)成本高昂,且只能修复措辞,永远无法修复遗漏的工具调用。围绕它循环会花费数小时,去重新发现失败理由已经说明的东西。

它随时间复合增长

回报随时间增长。评估集(eval set)变成了你组织所定义的质量的持久记录,在开发中按需运行,在每次变更的 CI 中运行,始终依据同一个"好"的定义。

部署之后,同一个定义继续发挥作用。在开发中你称它为评估(eval)。在生产中你称它为监控(monitoring)。它是同一个度量标准。

已部署的代理已经会导出其执行追踪(execution traces)。通过提示词-响应日志记录(prompt-response logging),它的提示词和回复会进入 BigQuery,因此在该表上运行你的度量标准,就是将对真实流量而非书面数据集应用同样的评分步骤。

评估(Eval)和可观测性(observability)原来是一个循环的两种采样方式。 一种采样于你编写的案例,一种采样于你不曾编写的对话。

https://x.com/@Saboo_Shubham_

每个出错的生产交互都会变成一个新案例,由同一个度量标准打分,从此防范该回归(regression)。将每次评分视为关于方向的信号,而非真值(ground truth);相信运行之间的变化,胜过相信任何单次分数。

立即开始

有一条规则凌驾于其他七条之上。编码代理负责迭代。它编写提示词(prompt),运行代理,发现差距并弥合。但它无法生成的是它所优化朝向的"好"的定义。

在启动循环之前,把它写下来。并把它存放在循环触及不到的地方。

然后今天就从 agents-cli 开始,从小处着手:

挑选一个你的代理必须做对的行为。挽留规则。合规底线。你目前通过阅读转录文本检查的东西。把它写成一个返回通过或失败并附带一句简短理由的度量标准。添加一个失败的案例。让你的编码代理指向它,然后让循环运行。

这就是第一次完整的会话:一个度量标准,一个案例,一个循环。完整文档见 google.github.io/agents-cli。

你的代理不必完美。它只需要是可改进的(improvable)。

By @Saboo_Shubham_ and @secchi_elia

By @Saboo_Shubham_ and @secchi_elia

When coding agents write the code, defining what's good is the real engineering job.

当编码代理(coding agents)编写代码时,定义什么是"好"才是真正的工程工作。

Coding agents can now build and improve other agents. Write the instructions, run the agent, find where it fails, rewrite, repeat. That self-improving loop ships today. Automating it is most of what agents-cli, our open-source CLI and skills for building agents on Google Cloud, does.

编码代理现在可以构建并改进其他代理。编写指令,运行代理,发现失败之处,重写,重复。这个自我改进的循环(self-improving loop)现已交付。将其自动化,正是 agents-cli 的大部分工作——这是我们用于在 Google Cloud 上构建代理的开源 CLI 和技能集(skills)。

But the loop has a blind spot.

但这个循环存在一个盲区。

Give it a shallow target and it will optimize your agent into something that scores well and works worse. Then it reports success. Because by its own measure, it succeeded.

给它一个肤浅的目标,它会把你的代理优化成某种得分很高但实际表现更差的东西。然后它会报告成功。因为按照它自己的衡量标准,它确实成功了。

The loop can automate everything except telling you what "better" means.

这个循环可以自动化一切,唯独不能告诉你"更好"意味着什么。

The metric is the artifact you now write. Defining what good means, and measuring it well enough that a loop can improve toward it, is where the engineering judgment went. This article covers how the loop runs, where humans stay in control of it, and the seven rules that keep it honest.

度量标准(metric)是你现在编写的产物。 定义什么是好的,并将其衡量得足够好,使循环能够朝着它改进——这才是工程判断力的体现。本文将介绍这个循环如何运行、人类在何处保持控制,以及让它保持诚实的七条规则。

The metric is what you now author

度量标准(metric)是你现在编写的产物

Software teams have always known you get what you measure. The loop makes it literal. It improves whatever number you give it, and nothing inside it can tell the difference between a target that reflects what you want and one that merely scores well.

软件团队早就明白,你衡量什么就会得到什么。这个循环让这句话成了字面意思。它会改进你给出的任何数字,而循环内部没有任何东西能区分一个反映你真实需求的目标和一个仅仅得分很高的目标。

We kept relearning this while building the tool. The metric sits upstream of the prompt, the code, and the behavior. The loop will reshape all three to fit whatever it rewards.

在构建这个工具的过程中,我们不断重新学到这一点。度量标准位于提示词(prompt)、代码和行为的上游。循环会重塑这三者,以适应它所奖励的任何东西。

Every tooling advance has moved effort up a level. Assembly to compilers. Compilers to frameworks. This one moves it from the artifact to the standard.

每一次工具进步都将努力向上推进了一个层级。从汇编到编译器,从编译器到框架。这一次,它从产物(artifact)推进到了标准。

Quality is specific, and it belongs to you

质量是具体的,而且它属于你

The definition of good that matters is rarely the one a public benchmark measures. It's the refund policy. The escalation rule. The compliance line. The tone your customers recognize.

真正重要的"好"的定义,很少是公共基准测试(benchmark)所衡量的那个。它是退款政策。是升级规则。是合规底线。是你的客户能识别出的语气。

A general model does not know these things, and a general test will not check them.

通用模型不知道这些,通用测试也不会检查它们。

Consider a support agent whose rule is to offer the retention path before confirming a cancellation. A model can follow that rule in its reasoning and still drop it from the final reply. We've watched agents fail in exactly this shape: internal state correct, right tool called, and the final message to the user echoing a stale value anyway. Nothing crashes. The output reads fine on a skim. The answer the user receives is wrong.

考虑一个支持代理,其规则是在确认取消之前提供挽留路径。模型可以在推理过程中遵循该规则,却在最终回复中将其遗漏。我们见过代理恰恰以这种形态失败:内部状态正确,调用了正确的工具,但发给用户的最终消息仍然回显了一个过时的值。没有崩溃。粗略一看输出也没问题。但用户收到的答案是错的。

Only an evaluation that grades the reply, not the reasoning, catches this. And no public metric knows your retention rule exists. So you define your own: a custom metric, retention_offered, that returns 0 or 1 and a one-line reason for the verdict. Written down, that definition is yours to own, version, and sharpen as new failures come in.

只有对回复而非推理过程进行评分的评估(evaluation)才能发现这一点。 而且没有任何公共度量标准知道你的挽留规则存在。因此你自己定义一个:自定义度量标准 retention_offered,返回 0 或 1,以及一句简短的裁决理由。将其写下后,这个定义就归你所有,你可以为其做版本控制,并在出现新的失败时不断完善它。

The loop in practice

循环的实践

agents-cli turns the loop into a few commands, run over agents built with the Agent Development Kit (ADK). Install it into your coding agent:

agents-cli 将这个循环转化为几条命令,在基于 Agent Development Kit (ADK) 构建的代理上运行。将其安装到你的编码代理中:

agents-cli turns the measure-and-improve loop into a few commands, run over agents built with the Agent Development Kit (ADK). Install it into your coding agent:

agents-cli 将度量与改进循环(measure-and-improve loop)转化为几条命令,在基于 Agent Development Kit (ADK) 构建的代理上运行。将其安装到你的编码代理中:

Then describe what you want measured.

然后描述你想度量什么。

Take the support agent from earlier. No public metric captures its retention rule, so you define your own: a custom metric, retention_offered, that returns 0 or 1 and a one-line reason for the verdict. That definition is the standard everything else is judged against.

以前面的支持代理为例。没有任何公共度量标准能捕捉其挽留规则,因此你自己定义一个:自定义度量标准 retention_offered,返回 0 或 1,以及一句简短的裁决理由。这个定义就是评判其他一切的标准。

The coding agent starts by running your agent over a set of cases to produce traces:

编码代理首先在一组案例上运行你的代理,以生成追踪记录(traces):

agents-cli eval grade \
  --traces artifacts/traces/ \
  --config tests/eval/eval_config.yaml
agents-cli eval grade \
  --traces artifacts/traces/ \
  --config tests/eval/eval_config.yaml

The tempting shortcut at this point is to let the coding agent read its own output and decide whether it passed. An agent asked to judge its own reply grades it optimistically, and the failures that matter are exactly the kind it waves through.

此时诱人的捷径是让编码代理读取自己的输出并决定是否通过。被要求评判自己回复的代理会乐观地打分,而那些真正重要的失败恰恰是它放行的那种。

Grading breaks that circularity. Every trace is scored against your metric, a standard the coding agent cannot move, so a fix is judged by something other than what proposed it:

评分(Grading)打破了这种循环。每条追踪记录都依据你的度量标准进行打分,这是一个编码代理无法撼动的标准,因此修复方案是由提出它之外的东西来评判的:

uvx google-agents-cli setup

uvx google-agents-cli setup

Now the loop can improve on its own. Each failing case comes back with the metric's own reason, and that reason is the direction for the next attempt. The coding agent reads it, edits the agent's instructions, and re-runs. Then it compares the two runs to confirm the change helped without breaking anything else:

现在循环可以自行改进了。每个失败的案例都会返回度量标准自身的理由,而这个理由就是下一次尝试的方向。编码代理读取它,编辑代理的指令,然后重新运行。接着它比较两次运行结果,以确认这次改动有所帮助,且没有破坏其他任何东西:

agents-cli eval compare \
  artifacts/grade_results/results_baseline.json \
  artifacts/grade_results/results_after_fix.json

agents-cli eval compare \
  artifacts/grade_results/results_baseline.json \
  artifacts/grade_results/results_after_fix.json

That cycle (propose a fix, grade it, revise from the reason) is the entire optimization. It runs unattended between your checkpoints: you set the target and hold the held-out set, and everything the loop needs to steer by is already in the metric you wrote.

这个循环(提出修复、评分、根据理由修订)就是整个优化过程。 它在你的检查点之间无人值守地运行:你设定目标并保留留出集(held-out set),循环所需的一切导向都已在你编写的度量标准中。

The 7 rules for self-improving loops

自我改进循环的七条规则

Automating the loop was the easy part. The hard part was keeping humans in control of something designed to run without them. These seven rules are how, and they're now built into the agents-cli skills themselves.

自动化循环是容易的部分。困难的部分是让人类保持对某个设计为无人值守运行的事物的控制。这七条规则就是方法,而且它们现已内置于 agents-cli 的技能(skills)本身。

Rule 1: Start with one case, not a suite. One failing case tells you what to fix next. Twenty tell you nothing. Expect five to ten iterations before it passes. That's normal. Add the next case only once it holds.

规则 1:从一个案例开始,而非一套测试集。 一个失败的案例告诉你下一步该修复什么。二十个案例则什么都不会告诉你。预计需要五到十次迭代才能通过。这很正常。只有当它稳定通过后,才添加下一个案例。

Rule 2: Make judges explain themselves. A number says you failed. The reason says what to change, and the reason is what the next iteration gets written from. Deterministic checks are exempt, since the assertion is its own explanation.

规则 2:让评判者(judges)解释自己。 一个数字只说明你失败了。理由则说明该改什么,而理由正是下一次迭代编写的依据。确定性检查(deterministic checks)除外,因为断言本身就是解释。

Rule 3: Use code wherever the answer is deterministic. "Did it call the retention tool before confirming?" is a Python function. Exact, free, no judge variance. Save the judge for tone, completeness, whether an explanation holds up.

规则 3:只要答案是确定性的,就使用代码。 "它是否在确认前调用了挽留工具?" 这是一个 Python 函数。精确、免费、没有评判者方差(judge variance)。把评判者留给语气、完整性、解释是否站得住脚这些方面。

Rule 4: Score behavior, not paths. An agent that geocodes before checking the weather isn't wrong. Exact-match trajectories end up measuring how much the agent changed rather than how good it is.

规则 4:给行为打分,而非路径。 一个在查天气之前进行地理编码(geocodes)的代理并没有错。精确匹配轨迹(Exact-match trajectories)最终衡量的是代理改变了多少,而不是它有多好。

Rule 5: Treat a flaky case as a finding. A score that moves between identical runs means your agent is non-deterministic in a way you hadn't noticed, or your judge is. Run the case a few times and see which one moves. Deleting it removes the evidence, not the behavior.

规则 5:将不稳定的案例(flaky case)视为一项发现。 在完全相同的运行之间波动的分数意味着你的代理存在你未曾注意到的非确定性(non-deterministic),或者你的评判者存在。多运行几次该案例,看看是哪个在波动。删除它只是消除了证据,而非行为本身。

Rule 6: Never let the proposer move the bar. A bar moves three ways: lowered threshold, edited expected output, quietly dropped case. All three look like an improving score. This is what the held-out slice is for. A real gain shows up there too. A gamed one doesn't.

规则 6:永远不要让提出者(proposer)移动门槛。 门槛有三种移动方式:降低阈值、编辑预期输出、悄悄删除案例。这三种看起来都像是分数在提高。这正是留出切片(held-out slice)的用途。真正的提升也会在那里显现。而取巧的(gamed)提升则不会。

Rule 7: Auto-optimize once, at the end. Prompt optimization is expensive and only fixes wording, never a missing tool call. Looping on it spends hours rediscovering what the failure reasons already said.

规则 7:只在最后自动优化一次。 提示词优化(Prompt optimization)成本高昂,且只能修复措辞,永远无法修复遗漏的工具调用。围绕它循环会花费数小时,去重新发现失败理由已经说明的东西。

It compounds over time

它随时间复合增长

The payoff grows over time. The eval set turns into a durable record of what your organization means by quality, running on demand in development and in CI on every change, always against one definition of good.

回报随时间增长。评估集(eval set)变成了你组织所定义的质量的持久记录,在开发中按需运行,在每次变更的 CI 中运行,始终依据同一个"好"的定义。

Past deployment, the same definition keeps working. In development you call it eval. In production you call it monitoring. It's the same metric.

部署之后,同一个定义继续发挥作用。在开发中你称它为评估(eval)。在生产中你称它为监控(monitoring)。它是同一个度量标准。

A deployed agent already exports its execution traces. With prompt-response logging, its prompts and replies land in BigQuery, so running your metric over that table is the same grading step applied to real traffic instead of a written dataset.

已部署的代理已经会导出其执行追踪(execution traces)。通过提示词-响应日志记录(prompt-response logging),它的提示词和回复会进入 BigQuery,因此在该表上运行你的度量标准,就是将对真实流量而非书面数据集应用同样的评分步骤。

Eval and observability turn out to be one loop sampled two ways. Over the cases you wrote, and over the conversations you didn't.

评估(Eval)和可观测性(observability)原来是一个循环的两种采样方式。 一种采样于你编写的案例,一种采样于你不曾编写的对话。

Every production exchange that goes wrong becomes a new case, graded by the same metric, guarding against that regression from then on. Treat each grade as a signal about direction rather than ground truth, and trust the movement between runs more than any single score.

每个出错的生产交互都会变成一个新案例,由同一个度量标准打分,从此防范该回归(regression)。将每次评分视为关于方向的信号,而非真值(ground truth);相信运行之间的变化,胜过相信任何单次分数。

Get started today

立即开始

One rule sits above the other seven. The coding agent does the iterating. It writes the prompt, runs the agent, finds the gap, and closes it. What it cannot generate is the definition of good it optimizes toward.

有一条规则凌驾于其他七条之上。编码代理负责迭代。它编写提示词(prompt),运行代理,发现差距并弥合。但它无法生成的是它所优化朝向的"好"的定义。

Write that down before you start the loop. And keep it somewhere the loop cannot reach.

在启动循环之前,把它写下来。并把它存放在循环触及不到的地方。

Then start today with agents-cli, and start small:

然后今天就从 agents-cli 开始,从小处着手:

Pick one behavior your agent must get right. The retention rule. The compliance line. The thing you currently check by reading transcripts. Write it as a metric that returns pass or fail with a one-line reason. Add one failing case. Point your coding agent at it and let the loop run.

挑选一个你的代理必须做对的行为。挽留规则。合规底线。你目前通过阅读转录文本检查的东西。把它写成一个返回通过或失败并附带一句简短理由的度量标准。添加一个失败的案例。让你的编码代理指向它,然后让循环运行。

That's the whole first session: one metric, one case, one loop. Full docs at google.github.io/agents-cli.

这就是第一次完整的会话:一个度量标准,一个案例,一个循环。完整文档见 google.github.io/agents-cli。

Your agent doesn't have to be perfect. It has to be improvable.

你的代理不必完美。它只需要是可改进的(improvable)。

By @Saboo_Shubham_ and @secchi_elia

When coding agents write the code, defining what's good is the real engineering job.

Coding agents can now build and improve other agents. Write the instructions, run the agent, find where it fails, rewrite, repeat. That self-improving loop ships today. Automating it is most of what agents-cli, our open-source CLI and skills for building agents on Google Cloud, does.

But the loop has a blind spot.

Give it a shallow target and it will optimize your agent into something that scores well and works worse. Then it reports success. Because by its own measure, it succeeded.

The loop can automate everything except telling you what "better" means.

The metric is the artifact you now write. Defining what good means, and measuring it well enough that a loop can improve toward it, is where the engineering judgment went. This article covers how the loop runs, where humans stay in control of it, and the seven rules that keep it honest.

http://google.github.io/agents-cli

The metric is what you now author

Software teams have always known you get what you measure. The loop makes it literal. It improves whatever number you give it, and nothing inside it can tell the difference between a target that reflects what you want and one that merely scores well.

We kept relearning this while building the tool. The metric sits upstream of the prompt, the code, and the behavior. The loop will reshape all three to fit whatever it rewards.

Every tooling advance has moved effort up a level. Assembly to compilers. Compilers to frameworks. This one moves it from the artifact to the standard.

Quality is specific, and it belongs to you

The definition of good that matters is rarely the one a public benchmark measures. It's the refund policy. The escalation rule. The compliance line. The tone your customers recognize.

A general model does not know these things, and a general test will not check them.

Consider a support agent whose rule is to offer the retention path before confirming a cancellation. A model can follow that rule in its reasoning and still drop it from the final reply. We've watched agents fail in exactly this shape: internal state correct, right tool called, and the final message to the user echoing a stale value anyway. Nothing crashes. The output reads fine on a skim. The answer the user receives is wrong.

Only an evaluation that grades the reply, not the reasoning, catches this. And no public metric knows your retention rule exists. So you define your own: a custom metric, retention_offered, that returns 0 or 1 and a one-line reason for the verdict. Written down, that definition is yours to own, version, and sharpen as new failures come in.

The loop in practice

agents-cli turns the loop into a few commands, run over agents built with the Agent Development Kit (ADK). Install it into your coding agent:

agents-cli turns the measure-and-improve loop into a few commands, run over agents built with the Agent Development Kit (ADK). Install it into your coding agent:

https://google.github.io/agents-cli/

Then describe what you want measured.

Take the support agent from earlier. No public metric captures its retention rule, so you define your own: a custom metric, retention_offered, that returns 0 or 1 and a one-line reason for the verdict. That definition is the standard everything else is judged against.

The coding agent starts by running your agent over a set of cases to produce traces:

agents-cli eval grade \
  --traces artifacts/traces/ \
  --config tests/eval/eval_config.yaml

The tempting shortcut at this point is to let the coding agent read its own output and decide whether it passed. An agent asked to judge its own reply grades it optimistically, and the failures that matter are exactly the kind it waves through.

Grading breaks that circularity. Every trace is scored against your metric, a standard the coding agent cannot move, so a fix is judged by something other than what proposed it:

uvx google-agents-cli setup

Now the loop can improve on its own. Each failing case comes back with the metric's own reason, and that reason is the direction for the next attempt. The coding agent reads it, edits the agent's instructions, and re-runs. Then it compares the two runs to confirm the change helped without breaking anything else:

agents-cli eval compare \
  artifacts/grade_results/results_baseline.json \
  artifacts/grade_results/results_after_fix.json

That cycle (propose a fix, grade it, revise from the reason) is the entire optimization. It runs unattended between your checkpoints: you set the target and hold the held-out set, and everything the loop needs to steer by is already in the metric you wrote.

https://x.com/@secchi_elia

The 7 rules for self-improving loops

Automating the loop was the easy part. The hard part was keeping humans in control of something designed to run without them. These seven rules are how, and they're now built into the agents-cli skills themselves.

Rule 1: Start with one case, not a suite. One failing case tells you what to fix next. Twenty tell you nothing. Expect five to ten iterations before it passes. That's normal. Add the next case only once it holds.

Rule 2: Make judges explain themselves. A number says you failed. The reason says what to change, and the reason is what the next iteration gets written from. Deterministic checks are exempt, since the assertion is its own explanation.

Rule 3: Use code wherever the answer is deterministic. "Did it call the retention tool before confirming?" is a Python function. Exact, free, no judge variance. Save the judge for tone, completeness, whether an explanation holds up.

Rule 4: Score behavior, not paths. An agent that geocodes before checking the weather isn't wrong. Exact-match trajectories end up measuring how much the agent changed rather than how good it is.

Rule 5: Treat a flaky case as a finding. A score that moves between identical runs means your agent is non-deterministic in a way you hadn't noticed, or your judge is. Run the case a few times and see which one moves. Deleting it removes the evidence, not the behavior.

Rule 6: Never let the proposer move the bar. A bar moves three ways: lowered threshold, edited expected output, quietly dropped case. All three look like an improving score. This is what the held-out slice is for. A real gain shows up there too. A gamed one doesn't.

Rule 7: Auto-optimize once, at the end. Prompt optimization is expensive and only fixes wording, never a missing tool call. Looping on it spends hours rediscovering what the failure reasons already said.

It compounds over time

The payoff grows over time. The eval set turns into a durable record of what your organization means by quality, running on demand in development and in CI on every change, always against one definition of good.

Past deployment, the same definition keeps working. In development you call it eval. In production you call it monitoring. It's the same metric.

A deployed agent already exports its execution traces. With prompt-response logging, its prompts and replies land in BigQuery, so running your metric over that table is the same grading step applied to real traffic instead of a written dataset.

Eval and observability turn out to be one loop sampled two ways. Over the cases you wrote, and over the conversations you didn't.

https://x.com/@Saboo_Shubham_

Every production exchange that goes wrong becomes a new case, graded by the same metric, guarding against that regression from then on. Treat each grade as a signal about direction rather than ground truth, and trust the movement between runs more than any single score.

Get started today

One rule sits above the other seven. The coding agent does the iterating. It writes the prompt, runs the agent, finds the gap, and closes it. What it cannot generate is the definition of good it optimizes toward.

Write that down before you start the loop. And keep it somewhere the loop cannot reach.

Then start today with agents-cli, and start small:

Pick one behavior your agent must get right. The retention rule. The compliance line. The thing you currently check by reading transcripts. Write it as a metric that returns pass or fail with a one-line reason. Add one failing case. Point your coding agent at it and let the loop run.

That's the whole first session: one metric, one case, one loop. Full docs at google.github.io/agents-cli.

Your agent doesn't have to be perfect. It has to be improvable.

📋 讨论归档

讨论进行中…