首页 / 文章 / 实用笔记:以评估为导向的开发——一种软件工程方法

实用笔记:以评估为导向的开发——一种软件工程方法

《实用笔记:以评估为导向的开发——一种面向合同、检查项以及适用于采用该模式的团队的即插即用代码模块的软件工程方法》的操作指南。

3101 词

本指南将逐步构建从原始材料到可运行系统的完整流程,用于实现:评估驱动开发:面向生产级人工智能智能体的软件工程方法。重点在于可操作的步骤、明确的检查点,以及可直接放入代码仓库的代码,无需猜测其用途。 在概览阶段,应在修改代码之前明确输入参数、各步骤的负责人以及完成标准。操作人员应能够从已知的检查点重新运行相应步骤,而无需推测隐藏状态。 除了功能结果外,还需记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在流程从演示环境过渡到共享环境时出现意外费用。

总结

在处理总结阶段时,首先写下合约的详细内容:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 将配置信息与应用程序代码分开存放。环境文件、密钥存储以及功能开关应集中于一个位置,这样操作人员无需查看整个流程就能进行审计。 在耗时较高的步骤之后设置检查点。当操作人员重新执行后续节点时,恢复流程不应再次计费相同的大型语言模型调用。

简介

在完成入门阶段时,首先写下合同规范:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 同时记录正常流程和异常恢复流程。重试机制、人工审核环节以及死信处理都是产品本身的组成部分,而非后续需要补充的功能。 在成本较高的步骤之后设置检查点。当操作员重新尝试某个后续节点时,恢复流程不应再次调用相同的大型语言模型。

生产流水线:整体流程

在处理“生产流水线”阶段时,首先写下契约:所需的输入、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 优先选择小型、可测试的单元,而非庞大的脚本。当某个步骤失败时,故障应指向单一的责任模块,而非复杂的流水线结构。 在成本较高的步骤之后设置检查点。当操作员重新尝试后续节点时,恢复流程不应再次调用相同的大型语言模型。

1. 契约:解耦提示词并实现版本控制

在完成“1. 合同解耦”阶段时,首先写下合同内容:所需的输入参数、成功信号以及部分失败时的处理方式。这样的清单能确保后续的代码修改保持一致性。 将此阶段视为输入与经过验证的输出之间的契约。为相关产物命名,明确成功判定标准,杜绝无声的半完成状态。 缓存稳定的系统指令和工具架构。重复发送相同的开头信息是导致资源浪费的常见原因。

[
  {
    "agent_id": "financial_market_headlines",
    "version": 1,
    "agent_model": "openai:gpt-4",
    "prompt": "What are today's major financial market headlines?",
    "eval": {
      "contains": ["market"],
      "max_model_requests": 3,
      "min_tool_calls": 1,
      "max_tool_calls": 5,
      "judge_rubric": "The answer should be a useful response to the user's financial markets question. It should summarize market-relevant information, avoid obviously unrelated content, avoid investment advice, and avoid claiming certainty beyond what the retrieved information supports."
    }
  }
]

2. 运行时:执行引擎

在处理“运行时”阶段时,首先需明确相关约定:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改始终符合预期。 在功能结果旁记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外费用。 在耗时较高的步骤之后设置检查点。当操作员重新尝试后续节点时,恢复流程不应再次收取相同的LLM调用费用。

3. 可观测性层:杜绝盲区

在完成“可观测性层”的三个阶段时,首先需明确相关约定:所需的输入参数、成功标志,以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 应将配置信息与应用程序代码分开存放。环境文件、密钥存储以及功能开关应集中于一个位置,这样操作人员无需查看整个系统结构即可进行审计。 在耗时较高的步骤之后设置检查点。当操作人员重新执行后续节点时,恢复流程不应再次计费相同的大型语言模型调用。

4. 评估层:AI的CI/CD体系

在处理“评估层”这四个阶段时,首先需写下相关契约:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 同时记录正常流程与异常恢复流程。重试机制、人工审核环节以及死信处理都是产品本身的组成部分,而非后续需要补充的功能。 在成本较高的步骤之后设置检查点。当操作员重新尝试某个后续节点时,恢复流程不应再次调用相同的大型语言模型。

评估:为非确定性系统强制引入确定性

在逐步实现“强制确定性评估”功能时,首先需明确相关规范:所需输入、成功信号以及部分失败时的处理方式。这份清单能确保后续的代码修改保持一致性。 优先选择小型、可测试的单元,而非庞大的脚本。当某个步骤失败时,故障应指向单一责任模块,而非复杂的流程链。 在成本较高的步骤之后设置检查点。当操作员重新尝试后续节点时,恢复流程不应再次调用相同的大型语言模型。 在逐步实现“强制确定性评估”功能时,首先需明确相关规范:所需输入、成功信号以及部分失败时的处理方式。这份清单能确保后续的代码修改保持一致性。 在功能结果旁记录执行时间以及token或查询成本。提前了解成本情况,可避免从演示环境过渡到共享环境时出现意外费用。

第一层:实时确定性测试

将第一层的实时确定性阶段视为可测量的界面使用效果最佳。在扩大测试范围之前,先记录一份理想运行结果、一个故障案例以及回滚说明。 将配置置于应用程序代码之外。环境文件、密钥存储和功能标志应集中存放,以便操作人员无需查看整个系统结构即可进行审计。 保持系统状态的结构简洁且具有类型定义。嵌套的数据块会掩盖哪个节点修改了哪个字段的信息,还会在中断后导致测试无法继续。

uv run python tests/unittest_eval_agent.py
evaluators=[
    *[Contains(value, case_sensitive=False) for value in case.eval.contains],
    MaxModelRequests(case.eval.max_model_requests),
    MinToolCalls(case.eval.min_tool_calls),
    MaxToolCalls(case.eval.max_tool_calls),
]
(financial-agent2) alex@pop-os:/ssd/ai_works/financial_agent2$ uv run python tests/unittest_eval_agent.py
Running each eval case 3 time(s)
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
                               Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID                             ┃ Metrics               ┃ Assertions ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_headlines_v1 [1/3] │ tool_calls: 1         │ ✔✔✔✔       │    18.8s │
│                                     │ requests: 2           │            │          │
│                                     │ input_tokens: 1,325   │            │          │
│                                     │ output_tokens: 278    │            │          │
│                                     │ cost: 0.0564          │            │          │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ financial_market_headlines_v1 [2/3] │ tool_calls: 1         │ ✔✔✔✔       │     8.8s │
│                                     │ requests: 2           │            │          │
│                                     │ input_tokens: 1,195   │            │          │
│                                     │ output_tokens: 82     │            │          │
│                                     │ cost: 0.0408          │            │          │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ financial_market_headlines_v1 [3/3] │ tool_calls: 1         │ ✔✔✔✔       │    13.5s │
│                                     │ requests: 2           │            │          │
│                                     │ input_tokens: 1,292   │            │          │
│                                     │ output_tokens: 388    │            │          │
│                                     │ cost: 0.0620          │            │          │
├─────────────────────────────────────┼───────────────────────┼────────────┼──────────┤
│ Averages                            │ requests: 2.00        │ 100.0% ✔   │    13.7s │
│                                     │ output_tokens: 249.3  │            │          │
│                                     │ tool_calls: 1.00      │            │          │
│                                     │ cost: 0.0531          │            │          │
│                                     │ input_tokens: 1,270.7 │            │          │
└─────────────────────────────────────┴───────────────────────┴────────────┴──────────┘

第二层:基于追踪数据的确定性回归测试

将第二层确定性回归阶段视为可测量的表面时,其效果最佳。在扩大范围之前,先记录一个成功的测试用例、一个失败案例以及回滚说明。同时记录正常流程和恢复流程的文档。重试机制、人工审核环节以及死信处理都是产品本身的一部分,而非后续需要补充的内容。保持图结构简洁且类型明确,嵌套的数据块会掩盖哪个节点编写了哪个字段的信息,并且在中断后会导致无法继续执行。

uv run python tests/regression_eval_traces.py
Trace: ff5a53e3392dc26cd0a2890782be70ec
Eval case: financial_market_headlines v1
Status: PASS
Model requests: 2
Tool calls: 1
contains('market'): PASS
MaxModelRequests: PASS
MaxToolCalls: PASS

第三层:非确定性测试——以大语言模型作为评判标准

将第三层非确定性阶段视为可测量的对象来处理时,其效果最佳。在扩大范围之前,先记录一份理想的操作日志、一个故障案例以及回滚说明。 相较于庞大的脚本,应优先选择小型且可测试的单元。当某个步骤出现故障时,故障点应指向单一责任主体,而非复杂的流程链。 需为每轮操作和每次会话设定令牌预算。智能工具往往会大量消耗上下文资源,设置上限可避免演示过程变成意外的费用账单。 将第三层非确定性阶段视为可测量的对象来处理时,其效果最佳。在扩大范围之前,先记录一份理想的操作日志、一个故障案例以及回滚说明。 除了功能结果外,还需记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外账单。

[
  {
    "agent_id": "financial_market_headlines",
    "version": 1,
    "agent_model": "openai:gpt-4",
    "prompt": "What are today's major financial market headlines?",
    "eval": {
      "contains": ["market"],
      "max_model_requests": 3,
      "min_tool_calls": 1,
      "max_tool_calls": 5,
      "judge_rubric": "The answer should be a useful response to the user's financial markets question. It should summarize market-relevant information, avoid obviously unrelated content, avoid investment advice, and avoid claiming certainty beyond what the retrieved information supports."
    }
  }
]
LLMJudge(
    rubric=case.eval_case.eval.judge_rubric,
    model=args.judge_model,
    include_input=True,
    score={"evaluation_name": "judge_score", "include_reason": True},
    assertion={"evaluation_name": "judge_pass", "include_reason": True},
)
uv run python tests/regression_llm_judge_traces.py   --sample-percent 50
Trace selection: fetched=1 sampled=1 judging=1 lookback_minutes=1440 sample_percent=50 max_traces=5
Trace case: trace_id=3891f0b8432c9bbcb00e5e8adce1600b agent_id=financial_market_headlines prompt_version=1 answer_chars=207
Judging 1 trace(s) with openai:gpt-5.4
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
                                                   Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID              ┃ Inputs               ┃ Outputs              ┃ Scores               ┃ Assertions          ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_he… │ {'trace_id':         │ Today's major        │ judge_score: 0.000   │ judge_pass: ✗       │    469µs │
│                      │ '3891f0b8432c9bbcb00 │ financial market     │   Reason: The        │   Reason: The       │          │
│                      │ e5e8adce1600b',      │ headlines can be     │ response does not    │ response does not   │          │
│                      │ 'agent_id':          │ found on major       │ summarize any actual │ summarize any       │          │
│                      │ 'financial_market_he │ business and finance │ market headlines or  │ actual market       │          │
│                      │ adlines',            │ news outlets         │ provide              │ headlines or        │          │
│                      │ 'prompt_version': 1, │ including CNBC,      │ market-relevant      │ provide             │          │
│                      │ 'agent_model':       │ Yahoo Finance,       │ information; it only │ market-relevant     │          │
│                      │ 'openai:gpt-4',      │ Reuters, and         │ redirects the user   │ information; it     │          │
│                      │ 'judge_model':       │ Bloomberg. For more  │ to news websites. It │ only redirects the  │          │
│                      │ 'openai:gpt-5.4',    │ specific stories,    │ avoids investment    │ user to news        │          │
│                      │ 'prompt': "What are  │ please visit their   │ advice, but it is    │ websites. It avoids │          │
│                      │ today's major        │ websites.            │ not a useful answer  │ investment advice,  │          │
│                      │ financial market     │                      │ to the user's        │ but it is not a     │          │
│                      │ headlines?"}         │                      │ question.            │ useful answer to    │          │
│                      │                      │                      │                      │ the user's          │          │
│                      │                      │                      │                      │ question.           │          │
│                      │                      │                      │                      │                     │          │
│                      │                      │                      │                      │                     │          │
├──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼─────────────────────┼──────────┤
│ Averages             │                      │                      │ judge_score: 0.000   │ 0.0% ✔              │    469µs │
└──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴─────────────────────┴──────────┘
uv run python tests/regression_llm_judge_traces.py  --sample-percent 10 --lookback-minutes 30
Trace selection: fetched=1 sampled=1 judging=1 lookback_minutes=30 sample_percent=10 max_traces=5
Trace case: trace_id=38fa3a54134d8818c7d7a5afbf50967e agent_id=financial_market_headlines prompt_version=1 answer_chars=654
Judging 1 trace(s) with openai:gpt-5.4
Evaluating task ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
                                             Evaluation Summary: task
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID            ┃ Inputs             ┃ Outputs           ┃ Scores             ┃ Assertions        ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ financial_market_… │ {'trace_id':       │ Here are today's  │ judge_score: 0.450 │ judge_pass: ✗     │    441µs │
│                    │ '38fa3a54134d8818c │ major financial   │   Reason: The      │   Reason: The     │          │
│                    │ 7d7a5afbf50967e',  │ market headlines: │ response is        │ response is       │          │
│                    │ 'agent_id':        │                   │ market-related and │ market-related    │          │
│                    │ 'financial_market_ │ 1. Wall Street's  │ avoids investment  │ and avoids        │          │
│                    │ headlines',        │ riskiest trades   │ advice, but it     │ investment        │          │
│                    │ 'prompt_version':  │ are suddenly back │ mostly lists       │ advice, but it    │          │
│                    │ 1, 'agent_model':  │ on top: Chart of  │ article headlines  │ mostly lists      │          │
│                    │ 'openai:gpt-4',    │ the Day - Yahoo   │ and links rather   │ article headlines │          │
│                    │ 'judge_model':     │ Finance           │ than providing a   │ and links rather  │          │
│                    │ 'openai:gpt-5.4',  │ [Link](https://fi │ useful summary of  │ than providing a  │          │
│                    │ 'prompt': "What    │ nance.yahoo.com/) │ the key financial  │ useful summary of │          │
│                    │ are today's major  │ 2. S&P 500        │ market             │ the key financial │          │
│                    │ financial market   │ notches           │ developments.      │ market            │          │
│                    │ headlines?"}       │ record-high close │                    │ developments.     │          │
│                    │                    │ as rate-hike      │                    │                   │          │
│                    │                    │ worries ease -    │                    │                   │          │
│                    │                    │ Reuters           │                    │                   │          │
│                    │                    │ [Link](https://ww │                    │                   │          │
│                    │                    │ w.reuters.com/mar │                    │                   │          │
│                    │                    │ kets/us/)         │                    │                   │          │
│                    │                    │ 3. Treasury       │                    │                   │          │
│                    │                    │ yields rise as    │                    │                   │          │
│                    │                    │ U.S. threatens    │                    │                   │          │
│                    │                    │ Iran with more    │                    │                   │          │
│                    │                    │ economic          │                    │                   │          │
│                    │                    │ sanctions - CNBC  │                    │                   │          │
│                    │                    │ [Link](https://ww │                    │                   │          │
│                    │                    │ w.cnbc.com/)      │                    │                   │          │
│                    │                    │ 4. Latest stock   │                    │                   │          │
│                    │                    │ market, financial │                    │                   │          │
│                    │                    │ and business news │                    │                   │          │
│                    │                    │ - MarketWatch     │                    │                   │          │
│                    │                    │ [Link](https://ww │                    │                   │          │
│                    │                    │ w.marketwatch.com │                    │                   │          │
│                    │                    │ /)                │                    │                   │          │
│                    │                    │ 5. Latest finance │                    │                   │          │
│                    │                    │ and stock market  │                    │                   │          │
│                    │                    │ news covering the │                    │                   │          │
│                    │                    │ Dow, S&P 500,     │                    │                   │          │
│                    │                    │ banking,          │                    │                   │          │
│                    │                    │ investing and     │                    │                   │          │
│                    │                    │ regulation - WSJ  │                    │                   │          │
│                    │                    │ [Link](https://ww │                    │                   │          │
│                    │                    │ w.wsj.com/finance │                    │                   │          │
│                    │                    │ )                 │                    │                   │          │
├────────────────────┼────────────────────┼───────────────────┼────────────────────┼───────────────────┼──────────┤
│ Averages           │                    │                   │ judge_score: 0.450 │ 0.0% ✔            │    441µs │
└────────────────────┴────────────────────┴───────────────────┴────────────────────┴───────────────────┴──────────┘mar
  {
    "id": "financial_market_headlines",
    "version": 2,
    "agent": "websearch",
    "prompt": "Use the web-search tool to find and verify today's major financial-market headlines. Report the 3 to 5 most consequential developments across equities, rates, currencies, commodities, or macroeconomic policy. For each item, state what happened, identify the affected market or region, explain briefly why it matters, and name the source with a link when available. Include the relevant date and units for numerical claims. Cross-check any surprising index level, percentage move, policy decision, or economic release against a second reliable source; if it cannot be verified, omit it or clearly label it as unconfirmed. State when the information was current, distinguish facts from developing reports or interpretation, and say when reliable current information is insufficient. Do not invent facts, present stale information as today's news, or give personalized investment advice.",
    "contains": ["market"],
    "max_model_requests": 4,
    "min_tool_calls": 1,
    "max_tool_calls": 7,
    "judge_rubric": "The response should provide 3 to 5 current, consequential financial-market developments based on web research. Each item should identify what happened, the affected market or region, why it matters, and its source, preferably with a link. Numerical claims should include meaningful dates and units; surprising figures should be corroborated by a second reliable source or explicitly marked unconfirmed. The answer should state when the information was current, distinguish verified facts from developing reports or interpretation, and acknowledge insufficient evidence rather than inventing details. It must stay relevant, avoid stale news presented as current, avoid unsupported certainty, and avoid personalized investment advice. A polished but uncited answer containing an implausible or unverifiable market figure should fail."
  },

将模式转化为CI/CD流程

在将模式转变为具体阶段时,需先明确输入参数、各步骤的负责人以及结束标准,然后再进行代码修改。操作人员应能够从已知的检查点重新运行相应步骤,而无需猜测其中的隐藏状态。 配置信息应与应用程序代码分开存放。环境文件、密钥存储以及功能标志都应集中管理,这样操作人员只需查看这些内容即可,无需浏览整个流程图。 对于涉及资金支出或修改生产数据的操作,必须经过人工审批。仅靠编译时的配置并不足以确保业务流程的完整性。

参考资料

在“参考阶段”,在修改代码之前需明确输入内容、该步骤的负责人以及终止标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 需同时记录正常流程和异常恢复路径。重试机制、人工审核环节以及错误处理都是产品本身的组成部分,而非后续需要补充的内容。 对于涉及资金支出或修改生产数据的操作,必须经过人工审批。编译时的连接方式并不等同于业务功能的完整性。

操作检查清单

将“操作检查清单阶段”视为可衡量的工作面,能更好地发挥其作用。在扩大范围之前,需记录一份标准操作流程、一个故障案例以及回滚说明。 应将此阶段视为输入与已验证输出之间的契约。为相关文档命名,明确成功标准,杜绝默许的半完成状态。

保持图结构简洁且类型明确。嵌套的数据块会掩盖是哪个节点修改了哪个字段,还会在中断后导致流程无法继续。

分别对单轮回复和多轮对话的得分进行统计。将所有聊天内容的得分汇总起来会掩盖工具循环中的故障。

编写一份简短的操作手册:说明如何轮换密钥、如何清空队列、以及如何回滚最近的导入操作。

同时记录正常流程和故障恢复流程。重试机制、人工审核环节以及死信处理都是产品不可或缺的部分,而非后续需要补充的功能。

在升级技术栈之前,先冻结现有版本,为关键流程保存一份标准记录,并确认好回滚步骤。共享环境需要设置速率限制、进行租户检查,同时要明确负责密钥轮换的人员。与其展示花哨的一次性演示,不如追求扎实的可靠性。

关于4a86f3fd2d9a的批处理说明:不要将提供者密钥放入代码仓库,为每个会话设置令牌上限,并将转录内容存储在评估测试用例的旁边,以便后续更换模型时仍能保持可比性。