Every step, in an order that works每一步,按可行的顺序排列
This is one valid order for all steps: each comes after everything it uses. Tick steps as you finish them. Your progress is kept in this browser.这是全部步骤的一种可行顺序:每一步都排在它所依赖的步骤之后。完成一步就勾选一步。进度保存在当前浏览器里。
Before step 1第 1 步之前
Clone the repository and run every lab once against the fake model. This takes about 20 seconds and proves your Python works before any model is involved.克隆仓库,用假模型把所有 lab 运行一遍。大约需要 20 秒,可以在涉及任何模型之前先确认 Python 环境正常。
git clone <your repository url> aitutor && cd aitutor
python3 -m labs.run_all --checkWrite the memory budget before you choose models先写内存预算,再选模型
The budget decides the lineup. A lineup chosen first often cannot be resident together, and you find out in production as reload delays.预算决定阵容。先选模型的话,常常发现它们无法同时驻留,而且是在生产环境里通过加载延迟才发现。
Produces产出 A budget table: sizes, pairs that fit, cold-load cost.一张预算表:大小、可共存的组合、冷加载耗时。
python3 -m labs.m01_inference.budgetInstall the engine and put weights on a dedicated volume安装引擎,把权重放到专用卷上
It follows the budget because you now know which models to pull. Weights are large and reproducible, so they live apart from the boot disk and from backups.它排在预算之后,因为现在才知道该下载哪些模型。权重很大且可以重新下载,所以要和系统盘、备份分开存放。
Uses用到 which models to pull要拉取哪些模型 ← Inference engineering推理工程 1
Produces产出 A running engine with models on the data volume.一个运行中的引擎,模型存放在数据卷上。
Set the serving parameters on purpose有意识地设定服务参数
Defaults assume one user and one model. An agent makes many calls per question, so defaults cause evictions and queueing that look like a slow model.默认值假设只有一个用户、一个模型。智能体每回答一个问题要调用很多次,默认值会导致模型被换出和排队,看起来像模型慢。
Uses用到 how many models may be resident允许同时驻留几个模型 ← Inference engineering推理工程 1 · the engine to configure要配置的引擎 ← Inference engineering推理工程 2
Produces产出 An environment file that every start script sources.一个环境变量文件,所有启动脚本都引用它。
Call the endpoint the way every later layer will用后续各层都会用的方式调用端点
The OpenAI-compatible chat endpoint is the contract for the whole stack. Fix it now and you can swap engines, machines, or providers later by changing a URL.OpenAI 兼容的 chat 接口是整个系统的契约。现在把它定下来,以后换引擎、换机器、换供应商都只需要改一个 URL。
Uses用到 a running engine运行中的引擎 ← Inference engineering推理工程 2
Produces产出 A verified base URL and model name. This is what every later module calls.一个验证过的 base URL 和模型名。后面每个模块都调用它。
Write one client function and use it everywhere写一个客户端函数,全系统共用
It comes right after the contract because it is the contract in code. One function means one place to change the URL, the timeout, or the provider.它紧跟在契约之后,因为它就是契约的代码形式。只有一个函数,改 URL、超时或供应商时就只需改一处。
Uses用到 the request and response shape请求和响应的格式 ← Inference engineering推理工程 4
Produces产出 `chat()` and `embed()`: the only model calls in the stack.`chat()` 和 `embed()`:全系统唯一的模型调用入口。
Measure time to first token and tokens per second测量首 token 时间和每秒 token 数
Measure before tuning. These two numbers explain almost every latency complaint, and each has a different fix.先测量再优化。这两个数字能解释几乎所有延迟问题,而且各自的解法不同。
Uses用到 the endpoint to measure要测量的端点 ← Inference engineering推理工程 4
Produces产出 Per-model rate and first-token numbers. Round budgets and timeouts are set from these.每个模型的速率和首 token 数据。轮次预算和超时都据此设定。
python3 -m labs.m01_inference.benchAdd a second runtime only where it earns its place只在值得的地方增加第二个运行时
A small fast model handles cheap jobs such as triage, question writing, and judging. It must not compete with the workhorse for a resident slot, which is why it comes after the budget and the measurements.小而快的模型处理分流、出题、裁判这类便宜的任务。它不能和主力模型抢驻留名额,所以要在预算和测量之后再加。
Uses用到 memory left for a small model留给小模型的内存 ← Inference engineering推理工程 1 · proof the workhorse is too slow for cheap jobs主力模型做便宜任务太慢的证据 ← Inference engineering推理工程 6
Produces产出 A second base URL for fast, cheap calls.第二个 base URL,用于快速、便宜的调用。
Route by task type, and fail safe按任务类型路由,并且失败时不出错
Routing comes after the endpoints exist and are measured. A router over unmeasured models sends work to the wrong place with confidence.路由要等端点都存在并测量过之后再做。对没测过的模型做路由,只会自信地把任务送错地方。
Uses用到 which model is fast enough for which task哪个模型对哪类任务足够快 ← Inference engineering推理工程 6 · the base URL of the fast model快速模型的 base URL ← Inference engineering推理工程 7
Produces产出 `resolve_for_request()`: called by the gateway before forwarding.`resolve_for_request()`:网关转发前调用它。
python3 -m labs.m01_inference.routerCut latency where it is actually spent在真正耗时的地方降低延迟
This needs logs from real requests, so it comes after measurement. Tuning earlier usually targets model speed, which is rarely the problem.这一步需要真实请求的日志,所以排在测量之后。过早优化往往盯着模型速度,而那很少是问题所在。
Uses用到 the baseline to beat要超越的基线 ← Inference engineering推理工程 6
Produces产出 Default output cap and keep-alive values used by the harness.Harness 使用的默认输出上限和 keep-alive 值。
Keep the engine private让引擎保持私有
The engine has no authentication. Anything outside your machine must go through the gateway, which is the next module.引擎本身没有身份验证。机器外部的任何访问都必须经过网关,也就是下一个模块。
Uses用到 the port to protect要保护的端口 ← Inference engineering推理工程 4
Produces产出 A rule: the only public door is the gateway.一条规则:唯一对外的门是网关。
Decide the public surface确定对外接口
The surface is what callers depend on. Fix it first, because every later change behind it is free and every change to it breaks someone.对外接口是调用方依赖的东西。要先把它定下来,因为之后改它背后的东西没有代价,而改接口本身一定会影响到别人。
Uses用到 the request and response format to preserve需要保持不变的请求和响应格式 ← Inference engineering推理工程 4
Produces产出 A written contract: two paths, one format, four key attributes.一份书面契约:两个路径、一种格式、四个密钥属性。
Build the key store建立密钥库
Identity comes before the handler, because the handler's first act is to ask who is calling.身份在处理函数之前,因为处理函数做的第一件事就是问“谁在调用”。
Uses用到 the four key attributes四个密钥属性 ← API and gatewayAPI 与网关 1
Produces产出 `KeyStore` with issue, revoke, and authenticate.`KeyStore`:签发、吊销、验证。
Write the gateway handler编写网关处理函数
It needs the key store to exist and the engine contract to forward to. It is the first piece that joins two modules.它需要密钥库已经存在,也需要引擎的契约作为转发目标。这是第一个把两个模块连起来的部件。
Uses用到 authenticate()authenticate() ← API and gatewayAPI 与网关 2 · chat() as the upstream作为上游的 chat() ← Inference engineering推理工程 5
Produces产出 `serve()`: a running gateway and its base URL.`serve()`:一个运行中的网关及其 base URL。
Prove each rule with a request用请求逐条验证规则
A gateway is a list of refusals. Each one is tested before anything is built on top.网关本质上是一组拒绝规则。在其上构建任何东西之前,要逐条测试。
Uses用到 the running gateway运行中的网关 ← API and gatewayAPI 与网关 3
Produces产出 Evidence that authentication, scope, rate, and revoke each work alone.身份验证、权限、限流、吊销各自独立生效的证据。
python3 -m labs.m02_gateway.demoIssue one key per application每个应用签发一个密钥
Now that the rules hold, give every caller its own identity. Doing this before building callers means none of them ever shares a key.规则都成立之后,给每个调用方一个独立身份。在开发调用方之前就这么做,就不会出现共用密钥的情况。
Uses用到 confidence that scopes and revoke work对权限和吊销机制的信心 ← API and gatewayAPI 与网关 4
Produces产出 One key per caller. The harness reads the scope to decide who gets tools.每个调用方一个密钥。Harness 读取权限范围来决定谁能用工具。
Apply the model router in the gateway在网关里应用模型路由
The gateway is the one place every request passes, so model choice belongs here and callers stay unaware of it.网关是所有请求的必经之路,所以选模型的逻辑放在这里,调用方不需要知道。
Uses用到 resolve_for_request()resolve_for_request() ← Inference engineering推理工程 8 · the upstream function to wrap要包装的上游函数 ← API and gatewayAPI 与网关 3
Produces产出 Callers send no model name and still reach the right model.调用方不写模型名,也能到达正确的模型。
python3 -m labs.m02_gateway.routeOpen one public door只开一个对外入口
Exposure is last. Only a gateway that already refuses correctly should be reachable from outside.对外暴露放在最后。只有已经能正确拒绝请求的网关,才应该从外部可达。
Uses用到 keys for the outside callers给外部调用方的密钥 ← API and gatewayAPI 与网关 5 · an engine that is not reachable directly一个无法被直接访问的引擎 ← Inference engineering推理工程 10
Produces产出 A public base URL that other machines and hosted apps can call.一个公网 base URL,供其他机器和托管应用调用。
Fix the folder taxonomy and file names确定目录分类和文件命名
Path is the first signal every later step uses: the tier rules match on it, and search results cite it. It cannot be added afterward without re-filing everything.路径是后续每一步都会用到的第一个信号:等级规则靠它匹配,检索结果引用它。事后再补就得把所有文件重新归档。
Produces产出 A folder layout whose paths carry meaning.一个路径本身带有含义的目录结构。
Validate files by content按内容校验文件
It comes before filing because a bad file that reaches the bank will be chunked, embedded, and returned with confidence. On the reference build 15 files named .pdf were HTML error pages that passed a size check.它排在归档之前,因为坏文件一旦进入知识库,就会被切块、向量化,并被自信地返回。参考系统里有 15 个 .pdf 文件其实是 HTML 错误页,它们通过了文件大小检查。
Produces产出 `validate()`: None when good, a reason when not.`validate()`:正常返回 None,异常返回原因。
Write the authority rules编写权威等级规则
Tiers depend on the taxonomy and are needed by the ledger, so they sit between the two. Retrieval later uses the tier as a small ranking bonus and to choose between duplicate passages.等级依赖目录分类,又是台账需要的字段,所以排在两者之间。之后检索会用等级做小幅排序加分,并在重复段落中做选择。
Uses用到 folder names to match on用于匹配的目录名 ← Knowledge management知识管理 1
Produces产出 `authority()`: path to tier and kind.`authority()`:由路径得到等级和类别。
Create the ledger建立台账
The ledger is the single record of what exists. Indexing, retirement, and audits all read it, so it has to exist before any of them.台账是“有哪些文档”的唯一记录。索引、退役和审计都读它,所以必须先于它们存在。
Uses用到 tier and kind for each row每一行的等级和类别 ← Knowledge management知识管理 3
Produces产出 `Ledger`: the list the indexer reads.`Ledger`:索引程序读取的清单。
Run intake: scan the bank and process the inbox执行入库:扫描知识库并处理收件箱
This is the first step that uses all three earlier pieces together. It is also the routine you will repeat every week.这是第一个同时用到前面三个部件的步骤,也是你以后每周要重复的例行操作。
Uses用到 validate()validate() ← Knowledge management知识管理 2 · Ledger.record()Ledger.record() ← Knowledge management知识管理 4
Produces产出 A bank folder and a ledger that agree with each other.内容一致的知识库目录和台账。
python3 -m labs.m03_knowledge.demoRetire, do not delete退役,而不是删除
Retirement needs ledger rows to act on. Keeping the row lets the system explain why a passage vanished and recognize the same file if it is downloaded again.退役需要台账里已有记录。保留这一行,系统就能解释某段内容为什么消失,并在同一文件被再次下载时认出它。
Uses用到 ledger rows to change要修改的台账记录 ← Knowledge management知识管理 5
Produces产出 A status the indexer and the learner both respect.一个索引程序和学习任务都会遵守的状态。
Add collectors with a relevance filter加入带相关性过滤的采集器
Automation comes after the manual path works, because a collector only feeds the inbox. Without a filter it fills the bank with off-topic documents that then compete in retrieval.自动化要等手工流程跑通之后再做,因为采集器只是往收件箱送文件。没有过滤的话,它会把跑题的文档塞满知识库,然后在检索中抢位置。
Uses用到 the inbox routine that receives downloads接收下载文件的收件箱流程 ← Knowledge management知识管理 5
Produces产出 A scheduled source of new files, already filtered.一个定时运行、已经过滤的新文件来源。
Add a curated tier for judgment为经验判断增加一个人工整理层
It is last because it is built from the bank. Source documents state rules. They do not contain your judgment about how the rules apply, and that is often what a question needs.它排在最后,因为它是从知识库里提炼出来的。原始文档陈述规则,但不包含你对规则如何适用的判断,而问题往往需要的正是这个。
Uses用到 source documents to distill用于提炼的原始文档 ← Knowledge management知识管理 5
Produces产出 Reviewed concept pages that retrieval can return ahead of raw text.经过审核的概念页,检索时可以排在原文之前返回。
Name each kind of state and its owner给每种状态命名,并确定归属
Decide ownership before creating a single table. A table with two owners is where concurrent-write bugs and privacy leaks start.在建任何一张表之前先确定归属。一张表有两个所有者,正是并发写入问题和隐私泄露的起点。
Produces产出 An ownership table: prefix, writer, readers, lifetime.一张归属表:前缀、写入方、读取方、生命周期。
Open the database so concurrent access works以支持并发访问的方式打开数据库
Connection settings come before schema because they decide whether a second writer waits or fails. Fixing this after jobs exist means finding it as a corrupted file.连接设置排在建表之前,因为它决定第二个写入方是等待还是失败。等任务都跑起来再改,往往是通过文件损坏才发现问题。
Uses用到 the list of jobs that will write at the same time会同时写入的任务清单 ← State and storage状态与存储 1
Produces产出 `connect()`: the only way the stack opens its database.`connect()`:全系统打开数据库的唯一方式。
Create the schema, grouped by owner按归属分组建表
Schema follows ownership. Every later module writes into one of these tables, so they are created once here and never altered ad hoc.表结构由归属决定。后面每个模块都会往其中某张表里写数据,所以在这里一次建好,之后不做临时修改。
Uses用到 prefixes and owners前缀和归属 ← State and storage状态与存储 1 · a connection数据库连接 ← State and storage状态与存储 2
Produces产出 Tables for chunks, edges, claims, memory, turns, and cursors.文本块、边、论断、记忆、对话轮次和游标的表。
python3 -m labs.m04_state.demoDefine merge rules for run state定义运行状态的合并规则
This must exist before any code runs two nodes at once. Without it, the second tool result silently replaces the first.在任何代码同时运行两个节点之前,这套规则就必须存在。否则第二个工具的结果会悄悄覆盖第一个。
Produces产出 `merge_state()`: used by the wave executor in the harness.`merge_state()`:Harness 里的波次执行器会用到它。
Test concurrent writers before you depend on them在依赖并发写入之前先测试
It needs the connection and the schema. It is here, and not in operations, because a failure changes the storage choice.它需要连接和表结构都就绪。放在这里而不是运维模块,是因为一旦失败就要改变存储方案。
Uses用到 WAL and busy timeoutWAL 和 busy timeout ← State and storage状态与存储 2 · a table to write to可写入的表 ← State and storage状态与存储 3
Produces产出 Proof that a chat, a nightly job, and an eval can write at the same time.证明聊天、夜间任务和评估可以同时写入。
Give every background job a cursor给每个后台任务一个游标
Jobs that read logs come later, in evaluation and self-evolution. The cursor is built now because it is storage, and those jobs assume it.读取日志的任务在后面的评估和自进化模块才出现。游标现在就建好,因为它属于存储层,而那些任务默认它已存在。
Uses用到 the job_cursors tablejob_cursors 表 ← State and storage状态与存储 3
Produces产出 `read_new_lines()` and `append_log()`.`read_new_lines()` 和 `append_log()`。
Check that learned state can be dropped alone确认学到的状态可以单独清除
Do this before any learning job exists. It is the test of the ownership boundary, and it is your recovery plan when a learner writes something wrong.要在任何学习任务出现之前做这件事。它检验归属边界是否成立,也是学习任务写错内容时的恢复方案。
Uses用到 prefixes that mark ownership标明归属的前缀 ← State and storage状态与存储 3
Produces产出 A tested answer to: how do I delete everything the agent taught itself?一个经过验证的答案:如何删除智能体自己学到的一切?
Move to Postgres when the workload asks for it当负载需要时迁移到 Postgres
It is last because the lab database is enough to learn every later module. Move when you have several writers under load, need a vector index over many rows, or need point-in-time recovery.它排在最后,因为 lab 用的数据库足够学完后面所有模块。当你有多个高负载写入方、需要对大量数据建向量索引,或需要按时间点恢复时,再迁移。
Uses用到 the test that tells you the move worked用来确认迁移成功的测试 ← State and storage状态与存储 5
Produces产出 A production store with the same layout.一个结构相同的生产级存储。
PG_RUN_AS=<ordinary user, only when running as root> python3 -m labs.m05_rag.pgChunk with a context line切块时带上上下文行
Chunking decides what a hit can contain, and the embedding is of the chunk text. It is first because changing it later means re-embedding everything.切块决定一次命中能包含什么,而向量是对块文本计算的。它排第一,因为以后再改就得全部重新向量化。
Uses用到 validated files in a known layout已校验、目录结构明确的文件 ← Knowledge management知识管理 5
Produces产出 `chunk_markdown()`: a list of (context, text).`chunk_markdown()`:返回 (上下文, 正文) 列表。
Embed and load, driven by the ledger由台账驱动,向量化并入库
Loading joins three earlier modules: the ledger says which files, the embedder turns text into vectors, the schema says where rows go.入库把前面三个模块连在一起:台账决定处理哪些文件,embedding 把文本变成向量,表结构决定数据写到哪里。
Uses用到 chunks to embed待向量化的文本块 ← RAG and knowledge graphRAG 与知识图谱 1 · which files to index and their tier要索引哪些文件及其等级 ← Knowledge management知识管理 4 · kb_chunks and kb_fts tableskb_chunks 和 kb_fts 表 ← State and storage状态与存储 3 · embed()embed() ← Inference engineering推理工程 5
Produces产出 An indexed collection: rows with text, context, vector, tier.一个已索引的集合:每行包含正文、上下文、向量、等级。
python3 -m labs.m05_rag.demoDense search向量检索
Each side of hybrid search is built and inspected alone before fusion, so you can see what each one finds and misses.混合检索的两路要先各自搭好、单独检查,再做融合,这样才能看清每一路能找到什么、会漏掉什么。
Uses用到 stored vectors已存储的向量 ← RAG and knowledge graphRAG 与知识图谱 2
Produces产出 A ranked list of chunk ids from meaning.一个基于语义的块 id 排序列表。
Lexical search关键词检索
Built next to dense search for comparison. It finds exact tokens that vectors blur: policy numbers, section numbers, rare terms.紧挨着向量检索搭建,便于对比。它能找到向量会模糊掉的精确词:规定编号、章节号、罕见术语。
Uses用到 the full-text table全文索引表 ← RAG and knowledge graphRAG 与知识图谱 2
Produces产出 A ranked list of chunk ids from exact words.一个基于精确词的块 id 排序列表。
Fuse the two lists by rank按名次融合两个列表
Fusion needs both lists. It uses positions and never scores, because cosine similarity and BM25 are on unrelated scales.融合需要两个列表都就绪。它只用名次、不用分数,因为余弦相似度和 BM25 的量纲毫不相干。
Uses用到 the dense list向量检索列表 ← RAG and knowledge graphRAG 与知识图谱 3 · the lexical list关键词检索列表 ← RAG and knowledge graphRAG 与知识图谱 4
Produces产出 One fused score per chunk.每个块一个融合得分。
Add the authority nudge and collapse duplicates加入权威度微调并合并重复
Both act on the fused list. They fix two failures you only see once search works: a summary outranking the rule, and one paragraph filling the results.两者都作用于融合后的列表。它们解决的是检索跑通之后才会暴露的两个问题:摘要排在规定原文前面,以及同一段话占满结果。
Uses用到 fused scores, and the size of one rank step融合得分,以及一个名次差的大小 ← RAG and knowledge graphRAG 与知识图谱 5 · the tier on every chunk每个块上的等级 ← Knowledge management知识管理 3
Produces产出 `search()`: ranked, deduplicated, tier-aware results.`search()`:已排序、已去重、考虑等级的结果。
Build graph edges at index time在索引阶段建立图的边
Edges are built after loading because they are derived from chunk text. They come after baseline search because you need failing questions to know which edges are worth building.边要在入库之后建,因为它们是从块的正文中提取的。又排在基础检索之后,因为你需要先有答不好的问题,才知道哪些边值得建。
Uses用到 chunk text and context块的正文和上下文 ← RAG and knowledge graphRAG 与知识图谱 2 · the kb_edges tablekb_edges 表 ← State and storage状态与存储 3
Produces产出 Typed edges: defines, section, cites.带类型的边:defines、section、cites。
Expand results along the edges沿着边扩展检索结果
Expansion starts from a hit list, so it follows search. It is bounded, because every added passage costs context.扩展从命中列表出发,所以排在检索之后。它必须有上限,因为每多一个段落都要占用上下文。
Uses用到 the hit list to expand from用于扩展的命中列表 ← RAG and knowledge graphRAG 与知识图谱 6 · the edges to follow要沿着走的边 ← RAG and knowledge graphRAG 与知识图谱 7
Produces产出 Results that include passages reached by structure.包含按结构关系找到的段落的结果。
Explain empty results and write a trace解释空结果,并记录追踪信息
This finishes the search function. The agent will call it as a tool next, and an empty result with no explanation is where fabrication starts.这一步让检索函数完整。接下来智能体会把它当工具调用,而没有解释的空结果正是编造的起点。
Uses用到 the complete search path完整的检索路径 ← RAG and knowledge graphRAG 与知识图谱 8
Produces产出 A search result shape with results, trace, and diagnostic. The tools module wraps it.包含 results、trace 和 diagnostic 的检索结果结构。工具模块会对它做封装。
Production form: Postgres with pgvector生产形态:Postgres 加 pgvector
Same stages, different engine. It is last because the lab version is enough to build and evaluate everything after it.阶段相同,引擎不同。它排在最后,因为 lab 版本足够搭建和评估后面的所有内容。
Uses用到 a Postgres database with the vector extension带向量扩展的 Postgres 数据库 ← State and storage状态与存储 8 · the fusion logic, now in SQL融合逻辑,现在用 SQL 实现 ← RAG and knowledge graphRAG 与知识图谱 5
Produces产出 The same search contract over millions of rows.同样的检索接口,支撑百万级数据。
PG_RUN_AS=<ordinary user, only when running as root> python3 -m labs.m05_rag.pgDecide the tool list on paper先在纸上确定工具清单
Every tool's schema is sent on every turn, and every extra tool is another way to answer with the wrong instrument. Decide the list before writing any of them.每个工具的 schema 每一轮都要发送,每多一个工具就多一种用错工具的可能。动手写之前先把清单定下来。
Produces产出 A tool list: name, when to use, arguments.一份工具清单:名称、使用时机、参数。
Build the registry搭建注册表
The registry comes before the tools so every tool is born with a schema, a log record, and a size cap. Adding those later to tools that already exist is how some get missed.注册表先于工具,这样每个工具从一开始就有 schema、日志记录和大小上限。等工具都写好了再补,总会有漏掉的。
Uses用到 what a tool needs: name, description, arguments一个工具需要的东西:名称、描述、参数 ← Tools and MCP工具与 MCP 1
Produces产出 `Registry`: schemas(), call(), call_as_text(), log.`Registry`:schemas()、call()、call_as_text()、log。
Write the tools, with diagnostics for empty results编写工具,并为空结果提供诊断
Tools are written against the registry and wrap the modules below: search from retrieval, and a data source. The diagnostic is written now because the harness and the learner both depend on it.工具基于注册表编写,封装的是下层模块:来自检索模块的 search,以及一个数据源。诊断信息现在就要写,因为 Harness 和学习任务都依赖它。
Uses用到 the decorator and call path装饰器和调用路径 ← Tools and MCP工具与 MCP 2 · search() and its result shapesearch() 及其结果结构 ← RAG and knowledge graphRAG 与知识图谱 9
Produces产出 `build_registry()`: two tools the agent can call.`build_registry()`:智能体可调用的两个工具。
python3 -m labs.m06_tools.demoCheck errors, caps, and cost检查错误处理、截断和开销
These are the properties the loop will rely on without checking. Verify them here, where a failure is one line of output and not a broken conversation.这些是循环会直接依赖而不再检查的特性。在这里验证,出问题只是一行输出;到了循环里,就是一次失败的对话。
Uses用到 tools to exercise可供测试的工具 ← Tools and MCP工具与 MCP 3
Produces产出 A measured schema cost and a call log format. Self-observation reads this log.一个实测的 schema 开销和一种调用日志格式。自我观察任务会读这份日志。
Serve the same tools over MCP通过 MCP 提供同一批工具
It follows the local tools because it wraps them. One implementation then serves every harness, which is what makes the rest of this curriculum portable.它排在本地工具之后,因为它是对本地工具的封装。这样一套实现就能服务所有 Harness,这也是整套课程可以移植的基础。
Uses用到 the registry to wrap要封装的注册表 ← Tools and MCP工具与 MCP 3
Produces产出 An MCP server any client can start from a command.一个任何客户端都能通过命令启动的 MCP 服务。
Call the server the way a client does像客户端那样调用服务
Test the protocol path before handing the server to a client you do not control.在把服务交给你无法控制的客户端之前,先测试协议这条路径。
Uses用到 the server module to launch要启动的服务模块 ← Tools and MCP工具与 MCP 5
Produces产出 Proof the tools work over the protocol.工具可以通过协议正常工作的证据。
python3 -m labs.m06_tools.mcp_checkRegister the server in each client在各个客户端里注册这个服务
Last, because each client needs only a config entry pointing at a server that is already tested.放在最后,因为每个客户端只需要一条指向已测试服务的配置。
Uses用到 a server known to work一个确认可用的服务 ← Tools and MCP工具与 MCP 6
Produces产出 The same tools available in a coding agent or editor.同一批工具在编程智能体或编辑器里可用。
Build the flat loop and bound it搭建扁平循环并设上限
The flat loop is the smallest thing that is an agent. It joins the model client and the tool registry. Get it correct and bounded before adding concurrency, because every later feature is a refinement of it.扁平循环是能称为智能体的最小形态。它把模型客户端和工具注册表连在一起。先把它做对、设好上限,再加并发,因为后面的每项功能都是在它之上的改进。
Uses用到 chat()chat() ← Inference engineering推理工程 5 · schemas() and call_as_text()schemas() 和 call_as_text() ← Tools and MCP工具与 MCP 2
Produces产出 `flat_loop()`: the correctness reference for everything after.`flat_loop()`:后续所有实现的正确性参照。
python3 -m labs.m07_harness.demoWrite the wave executor编写波次执行器
It follows the flat loop because it is the same behavior with two additions: tool calls in one turn run concurrently, and their results merge safely. It needs the merge rules from the state module.它排在扁平循环之后,因为行为相同,只多了两点:同一轮的工具调用并发执行,结果安全合并。它需要状态模块里的合并规则。
Uses用到 merge_state()merge_state() ← State and storage状态与存储 4
Produces产出 `run_graph()`: also used by the multi-agent module.`run_graph()`:多智能体模块也会用到。
Express the loop as planner and tool nodes把循环表达为规划节点和工具节点
Now the two pieces meet: the flat loop's logic, run by the wave executor.现在两部分汇合:扁平循环的逻辑,交给波次执行器来运行。
Uses用到 the logic to preserve需要保持的逻辑 ← Harness engineeringHarness 工程 1 · the executor执行器 ← Harness engineeringHarness 工程 2
Produces产出 An agent whose tool calls in one turn run in parallel.同一轮工具调用可以并行执行的智能体。
Handle a spent budget as a designed outcome把预算耗尽当作设计内的结果来处理
It depends on the round counter in the planner. Without it, hitting the limit returns nothing after the user has waited the longest.它依赖规划节点里的轮次计数。没有它的话,达到上限时什么都不返回,而此时用户已经等了最久。
Uses用到 the planner node规划节点 ← Harness engineeringHarness 工程 3
Produces产出 A bounded run that always returns something, and a logged signal for the learner.一个有上限且总有返回的运行过程,以及一条供学习任务使用的日志信号。
Compose the system prompt from parts分部分组装系统提示词
Composition has to exist before skills and memory can plug in. It is kept short because the prompt is charged on every turn.先要有组装这一步,技能和记忆才有地方接入。它要保持简短,因为提示词每一轮都计费。
Uses用到 the agent class to extend要扩展的智能体类 ← Harness engineeringHarness 工程 3
Produces产出 `compose_system_prompt()`: the plug point for the skills and memory modules.`compose_system_prompt()`:技能和记忆模块的接入点。
Add hooks before tool execution在工具执行前加入钩子
Hooks sit inside the tool node, so that node must exist. They enforce policy in code, which holds whatever the model was told.钩子位于工具节点内部,所以工具节点必须先存在。它们用代码强制执行策略,不管模型被告知了什么都有效。
Uses用到 the tool node工具节点 ← Harness engineeringHarness 工程 3
Produces产出 `pre_tool_hooks`: the plug point for the guardrails module.`pre_tool_hooks`:护栏模块的接入点。
Assemble run(): guard, retry, log, record组装 run():护栏、重试、日志、记录
This is the last piece because it orders everything else: compose, execute, check, respond, record.这是最后一块,因为它给其余部分排好顺序:组装、执行、检查、响应、记录。
Uses用到 the system prompt系统提示词 ← Harness engineeringHarness 工程 5 · a run that always ends一个总会结束的运行过程 ← Harness engineeringHarness 工程 4 · the hook path钩子路径 ← Harness engineeringHarness 工程 6 · append_log() for JSON-lines logs用于 JSON Lines 日志的 append_log() ← State and storage状态与存储 6
Produces产出 `Agent.run()` and two logs: requests.jsonl and tool_calls.jsonl.`Agent.run()` 以及两份日志:requests.jsonl 和 tool_calls.jsonl。
Put cheap deterministic gates in front of the planner在规划节点前放置便宜的确定性关卡
Triage runs before the planner, so add it once the planner path is stable. It removes whole classes of slow requests.分流在规划节点之前运行,所以等规划路径稳定后再加。它能直接消除几类慢请求。
Uses用到 the request log, to find which requests waste tool rounds请求日志,用来找出哪些请求在浪费工具轮次 ← Harness engineeringHarness 工程 7
Produces产出 Fewer model calls on requests that never needed tools.对那些本来就不需要工具的请求,减少了模型调用。
python3 -m labs.m07_harness.triageWrite one skill from a real failure从一次真实的失败出发写一个技能
A skill encodes a correction. Start from a request the agent handled badly in the harness logs, so every line has a reason.技能是把一次纠正固化下来。从 Harness 日志里智能体处理得不好的请求入手,这样每一行都有来由。
Uses用到 the request log that shows what went wrong显示出错情况的请求日志 ← Harness engineeringHarness 工程 7
Produces产出 A skill file: description plus body.一个技能文件:描述加正文。
Load skill files加载技能文件
Parsing comes before matching. Keep it trivial so a skill stays a file anyone can edit.先解析,再匹配。解析要足够简单,让技能始终只是一个人人都能编辑的文件。
Uses用到 skill files to parse待解析的技能文件 ← Skills技能(Skills) 1
Produces产出 `load_skills()`: a dict of skills by name.`load_skills()`:按名称索引的技能字典。
python3 -m labs.m08_skills.demoWrite routing examples, including a list for no skill编写路由示例,包括“不需要技能”的列表
Examples are written before the matcher because the matcher is only as good as they are. The `_none` list is what stops small talk from loading the least-bad skill.先写示例再写匹配器,因为匹配器的效果完全取决于示例。`_none` 列表的作用是防止闲聊时加载“最不差”的那个技能。
Uses用到 the skill names to route to要路由到的技能名 ← Skills技能(Skills) 2
Produces产出 `routing.json`: examples per skill and for `_none`.`routing.json`:每个技能和 `_none` 的示例。
Match a request to at most one skill把请求匹配到至多一个技能
Matching needs skills and examples. It returns one skill or nothing, because stacking skills dilutes each and raises prompt cost.匹配需要技能和示例都就绪。它只返回一个技能或空,因为叠加多个技能会相互稀释,还会增加提示词开销。
Uses用到 the examples to compare with用于比较的示例 ← Skills技能(Skills) 3 · embed()embed() ← Inference engineering推理工程 5
Produces产出 `Router.match()`: text to one skill or None.`Router.match()`:输入文本,返回一个技能或 None。
Plug the router into the harness把路由器接入 Harness
This is the join. The harness already has the plug point, so this step is one argument.这是两个模块的连接点。Harness 已经留好了接入点,所以这一步只是传一个参数。
Uses用到 Router.matchRouter.match ← Skills技能(Skills) 4 · the skills plug point技能接入点 ← Harness engineeringHarness 工程 5
Produces产出 An agent whose instructions depend on the request.指令随请求而变的智能体。
Share the same files with a coding agent让编程智能体共用同一批文件
Once skills are plain files they can serve more than one harness. Do it after the router works so you know the files are sound.技能既然是普通文件,就能服务多个 Harness。等路由器跑通、确认文件没问题之后再做这一步。
Uses用到 skills known to work确认可用的技能 ← Skills技能(Skills) 5
Produces产出 One source of instructions for two surfaces.两个入口共用的同一份指令来源。
Fix the partition rule确定分区规则
Decide where the partition comes from before writing any memory code. Every function takes it as its first argument, and retrofitting it is how leaks happen.在写任何记忆代码之前,先确定分区从哪里来。每个函数都把它作为第一个参数,事后再补正是泄露的来源。
Uses用到 an authenticated identity to derive the partition from用于推导分区的已认证身份 ← API and gatewayAPI 与网关 2
Produces产出 A rule: partition comes from authentication.一条规则:分区来自身份认证。
Store facts and build the briefing保存事实并生成摘要
Facts are the simplest memory and the only kind that goes into every prompt, so they are built first and kept small.事实是最简单的记忆,也是唯一会进入每次提示词的那种,所以先做它,并保持精简。
Uses用到 the partition argument分区参数 ← Memory记忆 1 · the mem_facts tablemem_facts 表 ← State and storage状态与存储 3
Produces产出 `remember()` and `briefing()`.`remember()` 和 `briefing()`。
Write the record pipeline, after the answer编写记录流程,放在回答之后
It needs the fact store. It runs after the answer because the user is waiting for the answer and no one is waiting for the notes.它依赖事实存储。它在回答之后运行,因为用户等的是回答,没有人在等笔记。
Uses用到 remember()remember() ← Memory记忆 2 · proof that a background writer is safe后台写入安全的证据 ← State and storage状态与存储 5
Produces产出 `record_async()`: what the harness calls after responding.`record_async()`:Harness 在响应之后调用它。
Add recall over past turns加入对历史对话的回忆
Recall needs stored turns, so it follows the pipeline. History is searched on demand because putting it all in the prompt costs every turn.回忆需要已保存的对话,所以排在记录流程之后。历史按需检索,因为全放进提示词的话每一轮都要付费。
Uses用到 stored turns已保存的对话 ← Memory记忆 3 · embed()embed() ← Inference engineering推理工程 5
Produces产出 `recall()`: this user's earlier turns that match.`recall()`:该用户之前与查询匹配的对话。
Plug memory into the harness and test isolation把记忆接入 Harness 并测试隔离性
This joins memory to the loop. Isolation is tested here, with two users, before any real user exists.这一步把记忆接到循环上。隔离性就在这里用两个用户测试,赶在任何真实用户出现之前。
Uses用到 record_async()record_async() ← Memory记忆 3 · the memory plug point记忆接入点 ← Harness engineeringHarness 工程 5 · the place run() hands off the exchangerun() 交出对话的位置 ← Harness engineeringHarness 工程 7
Produces产出 An agent that briefs itself per user and records after answering.一个按用户生成摘要、在回答之后做记录的智能体。
python3 -m labs.m09_memory.demoTest the three boundaries of recall测试回忆的三条边界
Each boundary is a line of output. Test them now so a later change that breaks one is caught by the same demo.每条边界对应一行输出。现在就测好,以后哪次改动破坏了其中一条,同一个 demo 就能发现。
Uses用到 recall()recall() ← Memory记忆 4
Produces产出 Four checks that double as a regression test.四项检查,同时可作为回归测试。
Prove a memory failure cannot break an answer证明记忆故障不会破坏回答
The pipeline claims to be fire and forget. Test the claim by making it fail.记录流程声称自己“发出即不管”。通过让它故意失败来验证这个说法。
Uses用到 memory attached to the agent已接到智能体上的记忆 ← Memory记忆 5
Produces产出 Evidence that memory is best effort and never load-bearing.证明记忆是尽力而为的附加能力,系统不依赖它才能正常工作。
Offer recall as a tool bound to one user把回忆做成绑定到单个用户的工具
Last, because it combines recall with the tool registry. The partition is bound when the tool is created, so the model has no argument through which to ask for another user's history.放在最后,因为它把回忆和工具注册表结合起来。分区在创建工具时就绑定了,所以模型没有任何参数可以用来索取别人的历史。
Uses用到 recall()recall() ← Memory记忆 4 · the registry decorator注册表的装饰器 ← Tools and MCP工具与 MCP 2
Produces产出 A recall tool with no way to cross users.一个无法跨用户的回忆工具。
python3 -m labs.m09_memory.tool_checkStart from logged failures从日志里的失败案例出发
A guard written from imagination blocks the wrong things. Start with real answers that were wrong, so each rule has a case it must catch and you can find the cases it must allow.凭想象写的护栏会拦错东西。从真实的错误回答入手,这样每条规则都有它必须拦住的案例,你也能找到它必须放行的情况。
Uses用到 the request log请求日志 ← Harness engineeringHarness 工程 7
Produces产出 Two lists: must catch, must allow.两份清单:必须拦住的、必须放行的。
Write the grounding check编写依据检查
The check is the core and has no dependencies, so it is written and tested alone before it touches the loop.这项检查是核心,而且没有任何依赖,所以先单独写好、测好,再接入循环。
Uses用到 the kinds of figures to extract需要提取的数字类型 ← Guardrails and verification护栏与验证 1
Produces产出 `check()`: answer and messages to a verdict.`check()`:输入回答和消息,输出裁定。
python3 -m labs.m10_guard.demoWrap the check in review(), with modes and exemptions用 review() 封装检查,加入模式和豁免
The loop needs one function that also knows when not to judge. The exemptions come from your must-allow list.循环需要的是一个函数,它还得知道什么时候不该判断。豁免规则来自你的“必须放行”清单。
Uses用到 check()check() ← Guardrails and verification护栏与验证 2 · the skill name, which marks a data turn技能名,用来标识数据轮次 ← Skills技能(Skills) 5
Produces产出 `review()`: the function the harness calls.`review()`:Harness 调用的函数。
Run in observe mode first先以观察模式运行
Before the guard changes any answer, measure how often it would fire on real traffic and what it would wrongly block.在护栏改变任何回答之前,先测量它在真实流量上会触发多少次、会误拦什么。
Uses用到 the mode switch模式开关 ← Guardrails and verification护栏与验证 3
Produces产出 A list of would-block cases reviewed by a person.一份经人工审阅的“本应拦截”案例清单。
Enforce: corrective retry, then fallback强制执行:先纠正重试,再兜底
This joins the guard to the loop. It follows observation because now you know the guard's false positives.这一步把护栏接到循环上。它排在观察之后,因为此时你已经了解了护栏的误报情况。
Uses用到 confidence in the exemptions对豁免规则的信心 ← Guardrails and verification护栏与验证 4 · the guard plug point and retry path护栏接入点和重试路径 ← Harness engineeringHarness 工程 7
Produces产出 An agent that cannot return an unsupported figure on a data turn.一个在数据轮次上无法返回无依据数字的智能体。
Add streaming last最后再加流式输出
Streaming changes how output leaves the loop and interacts with the guard. Add it when the loop and guard are stable.流式输出会改变结果离开循环的方式,并与护栏相互影响。等循环和护栏稳定后再加。
Uses用到 a stable loop稳定的循环 ← Harness engineeringHarness 工程 7 · the guard, which decides when tokens may be released护栏,由它决定何时可以放出 token ← Guardrails and verification护栏与验证 5
Produces产出 A streamed response path with the same guarantees.一条具有同样保障的流式响应路径。
python3 -m labs.m07_harness.streamAdd a pre-tool hook for writes为写操作加一个工具前置钩子
Hooks are the other half: they act before a tool runs. This one is independent of the answer guard and can be built at any point after the harness has its hook list.钩子是另一半:它们在工具运行之前起作用。这一个与回答护栏无关,只要 Harness 有了钩子列表,随时可以搭建。
Uses用到 the hook list钩子列表 ← Harness engineeringHarness 工程 6
Produces产出 `write_path_guard()`: a hook factory.`write_path_guard()`:钩子工厂函数。
Keep one regression test per rule每条规则保留一个回归测试
Last, because every rule now exists. A guard grows one rule at a time, and without tests a new rule breaks an old exemption.放在最后,因为此时所有规则都已存在。护栏是一条一条规则加出来的,没有测试的话,新规则会破坏旧的豁免。
Uses用到 the two case lists两份案例清单 ← Guardrails and verification护栏与验证 1 · the functions under test被测试的函数 ← Guardrails and verification护栏与验证 3
Produces产出 A test file that grows with the guard.一个随护栏一起增长的测试文件。
python3 -m labs.m10_guard.run_testsWrite the human baseline questions编写人工基线问题
These come first because they must predate your own tooling. Questions written before any learning existed are the only true pre-learning baseline you will ever have.它们排第一,因为必须早于你自己的任何工具。在任何学习发生之前写下的问题,是你唯一能拥有的真正“学习前”基线。
Uses用到 real requests to draw questions from用来提炼问题的真实请求 ← Harness engineeringHarness 工程 7
Produces产出 `frozen_questions.json`: the headline metric.`frozen_questions.json`:最核心的指标。
Build a retrieval gold set构建检索标准集
Retrieval is scored before end-to-end quality because it is deterministic, fast, needs no judge, and is the most common root cause.先给检索打分,再看端到端质量,因为它确定、快速、不需要裁判,而且是最常见的根本原因。
Uses用到 chunk ids to point at要指向的 chunk id ← RAG and knowledge graphRAG 与知识图谱 2
Produces产出 `gold_v1.json`: question, gold chunk id, type.`gold_v1.json`:问题、标准 chunk id、类型。
python3 -m labs.m11_eval.demoSeal the test material before anything learns在任何学习发生之前封存测试材料
Sealing must precede the learning loop and cannot be done afterward. Once a learner has read a chunk or seen a question, that item no longer measures generalization.封存必须先于学习循环,而且事后无法补做。学习任务一旦读过某个文本块或见过某道题,它就不再能衡量泛化能力。
Uses用到 the question file to seal待封存的问题文件 ← Evaluation评估 1 · the gold file to seal待封存的标准集文件 ← Evaluation评估 2 · the heldout column on chunks文本块上的 heldout 列 ← State and storage状态与存储 3
Produces产出 `SEAL.json`, `assert_sealed()`, and `studiable()`. The learner depends on all three.`SEAL.json`、`assert_sealed()` 和 `studiable()`。学习任务依赖这三样。
Score routing with examples the router never saw用路由器没见过的例子给路由打分
It is last because it needs the router, and it belongs with the evaluation module's sealed sets. Routing is a separate layer, so it gets its own number.它排在最后,因为需要路由器已就绪,而且要和评估模块的封存集放在一起。路由是独立的一层,所以要有自己的指标。
Uses用到 the router to score要评分的路由器 ← Skills技能(Skills) 4 · the sealing mechanism封存机制 ← Evaluation评估 3
Produces产出 A routing accuracy number that moves when exemplars change.一个会随示例变化而变化的路由准确率。
python3 -m labs.m08_skills.route_evalWrite the rank metrics编写排名指标
Metric code follows the gold set because the definitions depend on what a gold item identifies: a chunk, its neighbors, its document.指标代码排在标准集之后,因为指标的定义取决于标准条目标识的是什么:一个文本块、它的相邻块、它所在的文档。
Uses用到 the chunk id formatchunk id 的格式 ← Evaluation评估 2
Produces产出 `score()`: one question's metrics.`score()`:单个问题的各项指标。
Run variants and append history运行变体并追加历史
This needs the seal, the score function, and the flags built into retrieval. It is the mechanism that turns every later change into an experiment.这一步需要封存、评分函数,以及检索模块里内置的开关。正是这个机制把之后的每次改动变成一次实验。
Uses用到 assert_sealed()assert_sealed() ← Evaluation评估 3 · score()score() ← Evaluation评估 4 · the flags on each ranking feature各项排序功能上的开关 ← RAG and knowledge graphRAG 与知识图谱 6
Produces产出 `retrieval_history.jsonl` and a comparison table.`retrieval_history.jsonl` 和一张对比表。
Read the table and decide what stays读懂表格,决定保留什么
A table is not a decision. This step is the discipline: keep a feature only if a number moved.有表格不等于有决定。这一步是纪律:只有指标真的变了,才保留一项功能。
Uses用到 the comparison table对比表 ← Evaluation评估 5
Produces产出 A keep or drop decision per feature, with a number behind it.每项功能保留或去掉的决定,背后都有数字。
Evaluate the whole agent with mechanical checks用代码检查评估整个智能体
End-to-end evals come after the layer evals, so when the full score drops you already know which layer to check.端到端评估排在分层评估之后,这样总分下降时你已经知道该检查哪一层。
Uses用到 the sealed questions已封存的问题 ← Evaluation评估 3 · Agent.run() and its result fieldsAgent.run() 及其结果字段 ← Harness engineeringHarness 工程 7 · check(), reused to grade figurescheck(),复用来给数字评分 ← Guardrails and verification护栏与验证 2
Produces产出 `agent_eval.run()`: the gate the learning loop must pass.`agent_eval.run()`:学习循环必须通过的关卡。
Repeat, and report the spread重复运行,并报告波动范围
This is what makes the earlier steps worth doing. It needs a working agent eval, and it comes before you trust any single result.正是这一步让前面的工作有价值。它需要智能体评估已经可用,并且要在你相信任何单次结果之前完成。
Uses用到 the agent eval to repeat要重复运行的智能体评估 ← Evaluation评估 7
Produces产出 A measured noise floor. A change must beat it to count.一个实测的噪声基线。改动必须超过它才算数。
Write down what the split is for写下拆分的目的
Decide before building. A second agent is justified by one of two needs, and each has a test.动手之前先决定。增加第二个智能体只有两种正当理由,每种都有对应的检验方法。
Uses用到 a way to tell a real gain from noise区分真实提升与噪声的方法 ← Evaluation评估 8
Produces产出 A stated reason and a test for it.一个明确的理由和对应的检验方法。
Create narrow workers创建专职子智能体
Workers come before the orchestrator. A worker is defined by what it cannot reach.先有子智能体,再有编排器。子智能体由“它接触不到什么”来定义。
Uses用到 the reason for the split拆分的理由 ← Multi-agent patterns多智能体模式 1 · the Agent classAgent 类 ← Harness engineeringHarness 工程 7 · a registry to take a subset of用来取子集的注册表 ← Tools and MCP工具与 MCP 2
Produces产出 `split()` and a registry subset per role.`split()` 以及每个角色的注册表子集。
python3 -m labs.m12_multi.demoFan out, fan in, synthesize扇出、扇入、汇总
Now the wave executor does for agents what it did for tools. This step reuses it unchanged.现在波次执行器对智能体做的事,和它之前对工具做的一样。这一步原样复用它。
Uses用到 workers and the split子智能体和拆分函数 ← Multi-agent patterns多智能体模式 2 · run_graph()run_graph() ← Harness engineeringHarness 工程 2 · an append key for findings用于结论的追加键 ← State and storage状态与存储 4
Produces产出 `orchestrate()`: one answer from several isolated agents.`orchestrate()`:由多个相互隔离的智能体得出的一个回答。
Measure what the split cost测量拆分的代价
Right after it works, measure it. This is the test you wrote down in the first step.一跑通就测量。这正是第一步里写下的检验。
Uses用到 both paths to compare可供比较的两条路径 ← Multi-agent patterns多智能体模式 3
Produces产出 A measured cost and benefit for this split.这次拆分的实测成本和收益。
Build two independent judges搭建两个相互独立的裁判
The second pattern is independence. It is built here because the learning loop and the evaluation module both call it.第二种模式是独立性。它放在这里搭建,因为学习循环和评估模块都会调用它。
Uses用到 embed(), and chat() when a judge is a modelembed();裁判是模型时还需要 chat() ← Inference engineering推理工程 5
Produces产出 `verify()`: a verdict with both votes and reasons.`verify()`:包含两票及其理由的裁定。
Add model judges with two votes and calibration加入模型裁判:双票制加校准
Judges are needed for free-text fidelity, and they are models with their own errors. They come late because you calibrate them against the deterministic checks you already have.判断自由文本是否忠实需要裁判,但裁判也是会出错的模型。它们放在后面,因为要用你已有的确定性检查来校准。
Uses用到 the habit of measuring before trusting先测量、再相信的习惯 ← Evaluation评估 8 · the two-vote implementation双票制的实现 ← Multi-agent patterns多智能体模式 5
Produces产出 Calibrated judges for what code cannot grade.经过校准的裁判,用于代码无法评分的部分。
python3 -m labs.m12_multi.calibrateCalibrate the judges before they remove anything在裁判移除任何内容之前先校准
A judge that acts is a guard on stored knowledge. Like the answer guard, it runs in report mode first.会执行动作的裁判,就是针对已存储知识的护栏。和回答护栏一样,它要先以只报告的模式运行。
Uses用到 verify()verify() ← Multi-agent patterns多智能体模式 5 · the observe-first practice先观察再执行的做法 ← Guardrails and verification护栏与验证 4
Produces产出 Judges trusted enough to act in the learning loop.可信度足以在学习循环中执行动作的裁判。
python3 -m labs.m12_multi.calibrateCheck the four preconditions检查四项前提条件
This module joins more earlier work than any other. Starting without one of these produces a loop that looks like it is learning.这个模块衔接的前序工作比其他任何模块都多。缺了其中任何一项就开始,得到的只是一个“看起来在学习”的循环。
Uses用到 the two log files两份日志文件 ← Harness engineeringHarness 工程 7 · read_new_lines()read_new_lines() ← State and storage状态与存储 6 · the sealed agent eval封存的智能体评估 ← Evaluation评估 7 · the tested way to undo learning经过验证的撤销学习的方法 ← State and storage状态与存储 7
Produces产出 Confidence that the loop can be measured and undone.对“这个循环可以被测量、也可以被撤销”的信心。
Observe: find failures that prove themselves观察:找出能自我证明的失败
Observation is first in the loop. It looks only for shapes that code can confirm, because a loop that learns from a model's opinion of its own answers amplifies its own mistakes.观察是循环的第一步。它只找代码能够确认的模式,因为如果循环从模型对自己回答的看法中学习,只会放大它自己的错误。
Uses用到 logs and a cursor日志和游标 ← Self-evolving agents自进化智能体 1 · the call log's empty flag, and a registry to re-run calls调用日志里的 empty 标记,以及用来重新执行调用的注册表 ← Tools and MCP工具与 MCP 4
Produces产出 `observe()`: findings with a signal, a key, a day, and a proof.`observe()`:带有信号、键、日期和证明的发现。
Record evidence so repetition cannot pose as support记录证据,不让重复冒充支持
Evidence is stored before any gate reads it. The key design is the reason this step exists: one row per claim, origin, and day.证据要先存好,关卡才有东西可读。主键的设计正是这一步存在的原因:每个论断、来源、日期只有一行。
Uses用到 findings发现 ← Self-evolving agents自进化智能体 2 · brain_claims and brain_evidencebrain_claims 和 brain_evidence 表 ← State and storage状态与存储 3
Produces产出 `add_evidence()`, `ready_for_promotion()`, `standing()`.`add_evidence()`、`ready_for_promotion()`、`standing()`。
Assemble the nightly loop with the eval gate组装夜间循环,并加上评估关卡
This joins observation, evidence, and the sealed eval. The eval sits between the gate and the write, so a change that passes the day count can still be stopped.这一步把观察、证据和封存评估连在一起。评估位于关卡和写入之间,所以即使天数达标,改动仍然可以被拦下。
Uses用到 the gate关卡 ← Self-evolving agents自进化智能体 3 · agent_eval.run()agent_eval.run() ← Evaluation评估 7 · the base prompt the rules are appended to规则所附加到的基础提示词 ← Harness engineeringHarness 工程 5
Produces产出 `nightly()`: one call per night that returns a report.`nightly()`:每晚调用一次,返回一份报告。
Run in report mode and read three days以报告模式运行,查看三天的情况
Report mode first, for the same reason the guard ran in observe mode: see what it would do before it does it.先用报告模式,理由和护栏先用观察模式一样:在它真正动手之前,先看它会做什么。
Uses用到 nightly() in report mode报告模式下的 nightly() ← Self-evolving agents自进化智能体 4
Produces产出 A report you can review before allowing any write.一份在允许任何写入之前可供审阅的报告。
python3 -m labs.m13_evolve.demoSwitch to apply and confirm the change切换到应用模式并确认改动
Only after reading reports. The change is confirmed three ways: the rules file, the sealed eval, and the behavior on the original question.只有在看过报告之后才做。改动通过三种方式确认:规则文件、封存评估,以及原问题上的行为。
Uses用到 a reviewed pending change一个经过审阅的待定改动 ← Self-evolving agents自进化智能体 5
Produces产出 One learned rule, gated by evidence and by a sealed eval.一条学到的规则,经过证据和封存评估的双重把关。
Know what the lab does not prove明确 lab 没有证明什么
Read this before running the loop on a real model. The lab proves the plumbing. It cannot prove the learning.在真实模型上运行循环之前先读这一步。lab 证明了管道是通的,但证明不了学习本身。
Uses用到 the demo result to interpret需要解读的 demo 结果 ← Self-evolving agents自进化智能体 6 · the noise floor of the agent eval智能体评估的噪声基线 ← Evaluation评估 8
Produces产出 An honest boundary around what was demonstrated.对“已演示了什么”划出的一条诚实的边界。
Extend the loop to learn from documents把循环扩展到从文档中学习
Log-based learning comes first because it is mechanically checkable. Document learning adds a model that reads, so it adds the two-vote check and the held-out exclusion.先做基于日志的学习,因为它可以机械验证。从文档学习多了一个负责阅读的模型,所以要加上双票核查和留出排除。
Uses用到 studiable(), the exclusion liststudiable(),即排除清单 ← Evaluation评估 3 · verify(), the two-vote checkverify(),即双票核查 ← Multi-agent patterns多智能体模式 5 · tiers to order the reading queue用于给阅读队列排序的等级 ← Knowledge management知识管理 3
Produces产出 Claims with sources, which a recall tool can return.带来源的论断,可由回忆类工具返回。
Keep rollback one command away让回滚只需一条命令
Last, and required before the loop runs unattended. Every applied change must be reversible without touching anything else.这是最后一步,也是让循环无人值守运行之前的必要条件。每个已应用的改动都必须可以撤销,且不影响其他任何东西。
Uses用到 applied rules to undo要撤销的已应用规则 ← Self-evolving agents自进化智能体 6 · dropping learned tables删除学到的表 ← State and storage状态与存储 7
Produces产出 A loop you can leave running.一个可以放心让它持续运行的循环。
Map SDK features to parts you built把 SDK 的功能对应到你搭建过的部件
Read before you install. The map tells you which defaults to check and what to keep outside.先读再装。这张对照表告诉你该检查哪些默认值,以及哪些东西要留在框架之外。
Uses用到 the list of parts to map要对应的部件清单 ← Harness engineeringHarness 工程 7
Produces产出 A mapping table for one SDK.一张针对某个 SDK 的对照表。
Give every SDK the same endpoint给每个 SDK 同一个端点
Hold the model constant so differences come from the loop. The gateway from module 2 serves that purpose unchanged.让模型保持不变,这样差异就只来自循环。第 2 模块的网关无需改动就能承担这个角色。
Uses用到 serve()serve() ← API and gatewayAPI 与网关 3 · a key with the tools scope带 tools 权限的密钥 ← API and gatewayAPI 与网关 2
Produces产出 A base URL and key that any OpenAI-compatible SDK accepts.任何 OpenAI 兼容 SDK 都能接受的 base URL 和密钥。
Port the agent to LangGraph把智能体移植到 LangGraph
First port, because a graph framework is closest to the wave executor you wrote.第一个移植对象选它,因为图框架和你写的波次执行器最接近。
Uses用到 base URL and keybase URL 和密钥 ← SDKs and frameworksSDK 与框架 2 · build_registry()build_registry() ← Tools and MCP工具与 MCP 3 · which settings to look for需要关注哪些设置 ← SDKs and frameworksSDK 与框架 1
Produces产出 `langgraph_agent.make()` and `ask()`.`langgraph_agent.make()` 和 `ask()`。
Port the agent to the OpenAI Agents SDK把智能体移植到 OpenAI Agents SDK
Second port, to see the same parts under different names. Two ports show what is common to SDKs and what is one vendor's choice.第二个移植对象,用来看同样的部件换了名字是什么样子。做两次移植,才能看出哪些是各 SDK 的共性,哪些是某家厂商自己的选择。
Uses用到 base URL and keybase URL 和密钥 ← SDKs and frameworksSDK 与框架 2 · build_registry()build_registry() ← Tools and MCP工具与 MCP 3
Produces产出 `openai_agents_agent.make()` and `ask()`.`openai_agents_agent.make()` 和 `ask()`。
Run all three and compare三个都跑一遍并比较
Now there are three loops over the same tools and endpoint. Compare what each did.现在同样的工具和端点上有了三个循环。比较它们各自做了什么。
Uses用到 the LangGraph portLangGraph 移植版 ← SDKs and frameworksSDK 与框架 3 · the Agents SDK portAgents SDK 移植版 ← SDKs and frameworksSDK 与框架 4 · the hand-built loop as reference作为参照的手写循环 ← Harness engineeringHarness 工程 7
Produces产出 Evidence that the loop is the replaceable part.证明循环是可以替换的那部分。
python3 -m labs.m14_sdk.demoPort to the Claude Agent SDK through MCP通过 MCP 移植到 Claude Agent SDK
This port reuses the MCP server from module 6 with no wrapper functions, which shows the second way tools travel. It was not executed in the lab run.这个移植直接复用第 6 模块的 MCP 服务,不需要包装函数,展示了工具迁移的第二种方式。它没有在 lab 运行中实际执行。
Uses用到 the MCP server moduleMCP 服务模块 ← Tools and MCP工具与 MCP 5
Produces产出 A port that shares tools through the protocol.一个通过协议共享工具的移植版本。
Decide what stays outside any SDK决定哪些东西留在任何 SDK 之外
Last, because the ports show it. What you did not have to rewrite is what you own.放在最后,因为移植过程已经说明了答案。那些不需要重写的东西,就是真正属于你的。
Uses用到 the three versions side by side并排的三个版本 ← SDKs and frameworksSDK 与框架 5
Produces产出 A boundary: your assets on one side, the loop on the other.一条边界:一边是你的资产,另一边是循环。
List every service, its port, and its interpreter列出每个服务、它的端口和解释器
You cannot supervise what you have not listed. The list also exposes two services sharing a port or needing different environments.没列出来的东西无法守护。这份清单还能暴露两个服务共用端口或需要不同运行环境的情况。
Uses用到 the engine process引擎进程 ← Inference engineering推理工程 2 · the gateway process网关进程 ← API and gatewayAPI 与网关 3
Produces产出 A service inventory.一份服务清单。
Put each service under the supervisor把每个服务交给守护进程
Supervision is the first operational step because everything after it assumes services come back by themselves.守护是运维的第一步,因为之后的一切都默认服务会自己恢复。
Uses用到 paths, ports, and environments路径、端口和运行环境 ← Operations and deployment运维与部署 1
Produces产出 Services that survive crashes and reboots.能扛住崩溃和重启的服务。
Write one status command写一条状态命令
After supervision, you need to see state in one place. This is also what the watchdog calls.有了守护之后,你需要在一个地方看到全部状态。看门狗调用的也是它。
Uses用到 the unauthenticated health path无认证的健康检查路径 ← API and gatewayAPI 与网关 3
Produces产出 `report()`: the daily driver.`report()`:日常最常用的命令。
python3 -m labs.m15_ops.demoAdd the busy marker to the server给服务加上忙碌标记
The marker has to exist before any background job, because it is the only way a job learns that a user is waiting.在任何后台任务出现之前,这个标记就得存在,因为它是任务得知“有用户在等”的唯一途径。
Uses用到 the request path to wrap要包裹的请求路径 ← Harness engineeringHarness 工程 7
Produces产出 `busy()` and `is_busy()`.`busy()` 和 `is_busy()`。
Schedule background work with preemption and a duty cycle用抢占和占空比来调度后台任务
It needs the marker. It is what lets evals and the learning loop share one machine with live users.它依赖忙碌标记。正是它让评估和学习循环能与在线用户共用一台机器。
Uses用到 is_busy()is_busy() ← Operations and deployment运维与部署 4
Produces产出 `run_window()`: used to run evals and the nightly loop.`run_window()`:用来运行评估和夜间循环。
Schedule the evals and print one line each给评估排上日程,每项输出一行
Automation comes after the evals are trusted. Scheduling an eval you do not believe produces a dashboard nobody reads.等评估值得信任之后再自动化。把一个你自己都不信的评估排上日程,只会得到一个没人看的仪表盘。
Uses用到 the history file to read from要读取的历史文件 ← Evaluation评估 5 · a scheduler that yields to live traffic一个会给实时流量让路的调度器 ← Operations and deployment运维与部署 5
Produces产出 A regression signal you see without asking.一个不用主动去查就能看到的回归信号。
python3 -m labs.m15_ops.nightly_evalsBack up what cannot be reproduced, and test the restore备份无法重新生成的东西,并测试恢复
Backups come once there is state worth keeping. The restore test is part of the same step because an untested backup is a hope.有了值得保留的状态,就该做备份。恢复测试属于同一步,因为没有测试过的备份只是一种希望。
Uses用到 the tables to count要统计行数的表 ← State and storage状态与存储 3 · the key store, which is irreplaceable密钥库,它是不可替代的 ← API and gatewayAPI 与网关 2
Produces产出 `backup()` and `restore_test()`.`backup()` 和 `restore_test()`。
Rotate logs and keep signal apart from noise轮转日志,并把信号与噪音分开
Other jobs read your logs: self-observation reads them every night. Noise in a log that a job reads is how a signal stops being seen.别的任务会读你的日志:自我观察每晚都读。任务要读的日志里混进噪音,信号就会被淹没。
Uses用到 the two structured logs两份结构化日志 ← Harness engineeringHarness 工程 7 · cursors that must survive rotation需要在轮转后依然有效的游标 ← State and storage状态与存储 6
Produces产出 Logs that stay readable by people and by jobs.人和任务都能持续读懂的日志。
python3 -m labs.m15_ops.logsWire the nightly window把夜间时间窗串起来
This joins operations to evaluation and self-evolution. It is last among the runtime steps because it schedules everything built before it.这一步把运维与评估、自进化连在一起。它在运行时步骤里排最后,因为它调度的是之前搭建的一切。
Uses用到 run_window()run_window() ← Operations and deployment运维与部署 5 · the backup unit备份单元 ← Operations and deployment运维与部署 6 · the retrieval eval unit检索评估单元 ← Evaluation评估 5 · the learning loop unit学习循环单元 ← Self-evolving agents自进化智能体 4
Produces产出 A system that measures and maintains itself every night.一个每晚自我测量、自我维护的系统。
Adopt a change discipline建立改动纪律
Last, because it governs every change you make from now on to all fifteen modules.放在最后,因为从现在起你对全部十五个模块的每次改动都受它约束。
Uses用到 flags and the history file开关和历史文件 ← Evaluation评估 5 · the post-deploy check部署后的检查 ← Operations and deployment运维与部署 3
Produces产出 A history in which every change has a reason and a measurement.一份历史记录,其中每次改动都有理由和测量结果。