docs: add s21 workflow runtime & s22 goal loop#384
Conversation
|
@Bill-Billion is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
… goal loop Across s01-s20, rewrite the trilingual chapter prose (zh/en/ja) to read like an engineer talking rather than a generated summary, normalize the product name to "Claude Code", and fix the hand-drawn architecture diagrams. s08 is rewritten most heavily: its prose now walks the reader through each compaction layer by what it leaves unsolved. Two new chapters postdate the source leak and are reconstructed from the cc_workflow and cc_goal_loop reverse-engineering rather than file:line citations: - s21 workflow runtime: the Workflow tool launches a deterministic, resumable background runtime that fans out subagents. - s22 goal loop: the /goal command as a host-owned turn-completion gate, where a separate evaluator judges trusted transcript evidence after each turn and blocks the stop until the goal is met. Each ships a runnable code.py, trilingual READMEs, and house-style diagrams; web docs and course assets regenerated via npm run extract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f056414 to
d6ccd65
Compare
| @@ -0,0 +1,305 @@ | |||
| # s08: Context Compact — 上下文总会满,要有办法腾地方 | |||
There was a problem hiding this comment.
| # s08: Context Compact — 上下文总会满,要有办法腾地方 | |
| # s08: Context Compact — 上下文总会满,要想办法腾地方 |
| [中文](README.zh.md) · [English](README.md) · [日本語](README.ja.md) | ||
|
|
||
| s01 → s02 → s03 → s04 → s05 → s06 → s07 → `s08` → [s09](../s09_memory/) → s10 → ... → s20 | ||
| > *"上下文总会满, 要有办法腾地方"* — 四层压缩策略, 便宜的先跑贵的后跑。 |
There was a problem hiding this comment.
| > *"上下文总会满, 要有办法腾地方"* — 四层压缩策略, 便宜的先跑贵的后跑。 | |
| > *"上下文总会满, 要有办法腾地方"* — 四层压缩管线,便宜的先跑,贵的后跑。 |
| s01 → s02 → s03 → s04 → s05 → s06 → s07 → `s08` → [s09](../s09_memory/) → s10 → ... → s20 | ||
| > *"上下文总会满, 要有办法腾地方"* — 四层压缩策略, 便宜的先跑贵的后跑。 | ||
| > | ||
| > **Harness 层**: 压缩 — 上下文超限时自动摘要,保持会话可持续。 |
There was a problem hiding this comment.
| > **Harness 层**: 压缩 — 上下文超限时自动摘要,保持会话可持续。 | |
| > **Harness 层**:压缩 — 上下文接近上限时先整理、再摘要,让长任务能持续跑下去。 |
|
|
||
| ## 问题 | ||
|
|
||
| 上一章给 Agent 加了 Skills,它开始有了一点"领域经验":遇到 PDF、MCP、代码审查,会先加载对应的操作说明再动手。 |
There was a problem hiding this comment.
| 上一章给 Agent 加了 Skills,它开始有了一点"领域经验":遇到 PDF、MCP、代码审查,会先加载对应的操作说明再动手。 | |
| 上一章给 Agent 加了 Skills。它开始有了一点“领域经验”:遇到 PDF、MCP server 或代码审查任务,会先加载对应的操作说明,再开始动手。 |
|
|
||
| 上一章给 Agent 加了 Skills,它开始有了一点"领域经验":遇到 PDF、MCP、代码审查,会先加载对应的操作说明再动手。 | ||
|
|
||
| 但 Agent 越会做事,另一个问题越明显。它读一个 1000 行的文件就是 ~4000 token,又读了 30 个文件,跑了 20 条命令。每条命令的输出、每个文件的内容,都被塞回 `messages` 列表,一点点堆起来。 |
There was a problem hiding this comment.
| 但 Agent 越会做事,另一个问题越明显。它读一个 1000 行的文件就是 ~4000 token,又读了 30 个文件,跑了 20 条命令。每条命令的输出、每个文件的内容,都被塞回 `messages` 列表,一点点堆起来。 | |
| 但 Agent 越能干,另一个问题就越明显。它读一个 1000 行文件,可能就是约 4000 个 token;再读 30 个文件、跑 20 条命令,上下文很快就会被堆满。每条命令的输出、每个文件的内容,都被塞回 `messages` 列表,一点点堆起来。 |
|
|
||
| ### 合起来跑 | ||
|
|
||
| 把这些挂回 Agent Loop:每轮调用 LLM 之前,先跑三层本地整理,不够再摘要;调用真报错了,再走应急。 |
There was a problem hiding this comment.
| 把这些挂回 Agent Loop:每轮调用 LLM 之前,先跑三层本地整理,不够再摘要;调用真报错了,再走应急。 | |
| 把这些机制接回 Agent Loop:每轮调用 LLM 之前,先跑三层本地整理;如果还不够,再做摘要;如果调用时真的报错,再走应急路径。 |
| # ... 工具执行 ... | ||
| ``` | ||
|
|
||
| **顺序不能换。** L3(budget)必须在 L2(micro)前面:micro 会把旧的大 `tool_result` 换成一行占位符,要是它先跑,budget 就没机会把完整内容落盘了。先 budget 把大内容存好,再做占位和裁剪。这也是 Claude Code 源码把 `applyToolResultBudget` 放在最前面的原因。 |
There was a problem hiding this comment.
| **顺序不能换。** L3(budget)必须在 L2(micro)前面:micro 会把旧的大 `tool_result` 换成一行占位符,要是它先跑,budget 就没机会把完整内容落盘了。先 budget 把大内容存好,再做占位和裁剪。这也是 Claude Code 源码把 `applyToolResultBudget` 放在最前面的原因。 | |
| **顺序不能换。** L3(budget)必须在 L2(micro)前面,`micro_compact` 会把旧的大 `tool_result` 替换成一行占位符。如果它先跑,`tool_result_budget` 就拿不到完整内容,也就没机会把它落盘。先 budget 把大内容存好,再做占位和裁剪。这也是 Claude Code 源码中 `applyToolResultBudget` 要放在最前面的原因。 |
|
|
||
| ### compact 工具:让模型也能主动请求 | ||
|
|
||
| 除了自动压缩,模型自己也能要求整理:当它觉得上下文太长、或任务阶段切换了,可以主动调 `compact` 工具。在教学版里,这个工具触发 `compact_history`,然后结束当前 turn,用压缩后的上下文重新开一轮。和手动 `/compact` 的感觉很像,区别是这次是模型自己意识到要整理。 |
There was a problem hiding this comment.
| 除了自动压缩,模型自己也能要求整理:当它觉得上下文太长、或任务阶段切换了,可以主动调 `compact` 工具。在教学版里,这个工具触发 `compact_history`,然后结束当前 turn,用压缩后的上下文重新开一轮。和手动 `/compact` 的感觉很像,区别是这次是模型自己意识到要整理。 | |
| 除了自动压缩,模型自己也能要求整理,当模型觉得上下文太长,或者任务已经切到新阶段时,可以主动调用 `compact` 工具。在教学版里,这个工具触发 `compact_history`,然后结束当前 turn,用压缩后的上下文重新开始下一轮。和手动 `/compact` 的感觉很像,区别在于,这次是模型自己意识到该整理上下文了。 |
| | 新函数 | — | snip_compact, micro_compact, tool_result_budget, compact_history, reactive_compact | | ||
| | 工具 | bash, read, write, edit, glob, todo_write, task, load_skill (8) | 8 + compact (9) | | ||
| | 循环 | LLM 调用 → 工具执行 | 每轮前跑三层预处理器 + 阈值触发 compact_history | | ||
| | 设计原则 | 让 Agent 会做事 | 让 Agent 做久一点也不崩 | |
There was a problem hiding this comment.
| | 设计原则 | 让 Agent 会做事 | 让 Agent 做久一点也不崩 | | |
| | 设计原则 | 让 Agent 会做事 | 让 Agent 运行久一点也不崩 | |
| | 循环 | LLM 调用 → 工具执行 | 每轮前跑三层预处理器 + 阈值触发 compact_history | | ||
| | 设计原则 | 让 Agent 会做事 | 让 Agent 做久一点也不崩 | | ||
|
|
||
| 这一步不算给 Agent 加"能力",更像加"体力":s07 让它更会做专业任务,s08 让它在长任务里不被自己的历史拖垮。 |
There was a problem hiding this comment.
| 这一步不算给 Agent 加"能力",更像加"体力":s07 让它更会做专业任务,s08 让它在长任务里不被自己的历史拖垮。 | |
| 这一步不算是在给 Agent 加“能力”,更像是在加“体力”。s07 让它更会做专业任务,s08 让它在长任务里不被自己的历史拖垮。 |
dethan3
left a comment
There was a problem hiding this comment.
Reviewed the s08 English and Chinese READMEs.
The English tutorial is clear and technically sound. The Chinese version is accurate and readable, but it still feels a bit too closely aligned to the English paragraph structure. I’d suggest one more non-blocking polish pass to make the Chinese read more like a native Chinese tutorial, especially around punctuation, headings, and a few translated phrases.
Adopt dethan3's inline review suggestions on README.zh.md: sentence-flow polish, full-width colons, backticks on code identifiers, and a few more accurate wordings (压缩管线, 裁掉中间的旧对话). A few were adjusted rather than taken verbatim: keep "用满" instead of the suggested "撑满", drop a stray double period, leave the chapter title unchanged, and preserve the L3-to-L4 transition sentence that one suggestion had removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Apply the same narrative upgrade s08 got. The problem section now opens by
carrying over from s05's todo_write; the solution leads with a why-not and an
anchor ("把脏活外包出去,只收一句结论"); the code block is sandwiched with a
"key points" recap after it; and the "three key design decisions" header is
corrected to "four" (the table always had four rows).
Word-level de-AI-toning per the user's review: 跟踪 over the clipped 追,
"实际改动" over the opaque 副作用, "无限循环" over the slangy 跑飞, and
"被填满" over 爆了. All three languages synced to v2; web docs regenerated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The problem section now opens by carrying over from s06's sub-Agent (a sub-Agent taking over needs the task's rules; where do those rules come from). The solution leads with a why-not (let the Agent read_file the docs itself, but it doesn't know what files exist) and an anchor: 目录常驻, 内容按需 / catalog always resident, content on demand. Level 1's code block now ends with a cascade hook (you only get the name and one-line description, the full content is still out of reach -> Level 2). `messages` and `tool_result` get backticks; one stray dash becomes a comma. All three languages synced to v3; web docs regenerated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
A trilingual review pass across all 20 chapters (s01–s20).
READMEs
README.mdthe English default, addREADME.zh.md, keepREADME.ja.md; drop the oldREADME.en.md.code.pycomments (all 20 chapters, 0 residual).Diagrams (SVG)
*.en.svg/*.ja.svginto a singleimages/*.svgper diagram.task(4)→task(5),dispatch_by_type→dispatch_message), redundant legends, loop-back routing.Tooling
web/scripts/extract-content.tslocale mapping (zh→README.zh.md,en→README.md).web/public/course-assets/**andweb/src/data/generated/{docs,versions}.json.Merge with upstream
Merged the latest
mainto resolve conflicts. Upstream fixes that landed after this branch forked were carried into the new trilingual layout:reactive_compactreorder (refactor: summarize only trimmed history in reactive_compact #364) andsnip_compact/reactive_compactguard alignmentVerification
code.py.