cleanup.mdmarkdown1## MANDATORY: 1. FIND DOCUMENTED TODOs and FIXMEs23You SHALL use the `grep` tool piped with `head` to find the first `10` documented TODOs and FIXMEs in the repository.45Command: grep -r -n -E "TODO|FIXME" . | head -n 10
cleanup.mdmarkdown 1The outputs are in the following format. 2 3```shell 4[file]:[line]:[content] 5``` 6 7You SHALL READ around each [line] in [file] and EXTRACT the [content] from all the found TODOs and FIXMEs, filtering out the ones cannot be applied apply with the restrictions of the platform, operating system, and required tools, then convert into a JSON object of the following format, using [incomplete_item_list] as the mnemonic: 8 9```json10[11 {12 "type": "todo",13 "id": "TODO_1",14 "file": [todo_1_file],15 "line": [todo_1_line],16 "content": [todo_1_content]17 },18 {19 "type": "todo",20 "id": "TODO_2",21 "file": [todo_2_file],22 "line": [todo_2_line],23 "content": [todo_2_content]24 },25 {26 "type": "fixme",27 "id": "FIXME_1",28 "file": [fixme_1_file],29 "line": [fixme_1_line],30 "content": [fixme_1_content]31 },32 {33 "type": "fixme",34 "id": "FIXME_2",35 "file": [fixme_2_file],36 "line": [fixme_2_line],37 "content": [fixme_2_content]38 }39]40```4142You SHALL NOTE a JSON object with and empty "items" array as [completed_item_list]:4344```json45[]46```4748You SHALL NOTE a JSON object with and empty "items" array as [postponed_item_list]:4950```json51[]52```
3.4用提示词强制贯彻协议
这里的协议直接写在提示词里——没有任何隐藏技巧,而是用清晰的命令一遍遍强调,直到模型完全照做。下面这段展示了 main agent 如何在循环开始时拉起 cleanup-evaluator:
cleanup.mdmarkdown 1## MANDATORY: 2. SPAWN A CLEANUP-EVALUATOR TO EVALUATE INCOMPLETE TODOs and FIXMEs 2 3You MUST spawn a cleanup-evaluator subagent to evaluate the gap between the incomplete TODOs and FIXMEs and the existing situation. 4 5You SHALL ALWAYS send the cleanup-evaluator with a JSON object of the following format: 6 7```json 8{ 9 "incomplete_items": [incomplete_item_list],10 "completed_items": [completed_item_list],11 "postponed_items": [postponed_item_list]12}13```
cleanup-evaluator 一侧也必须执行协议:
cleanup-evaluator.mdmarkdown 1## MANDATORY: PARSE THE RECEIVED JSON OBJECT 2 3YOU WILL RECEIVE a JSON object of the following format: 4 5```json 6{ 7 "incomplete_items": [incomplete_item_list], 8 "completed_items": [completed_item_list], 9 "postponed_items": [postponed_item_list]10}11```
当 cleanup-evaluator 完成评估后,它会按照协议准备回给 main agent 的响应。这个例子里,next_action 只有两种:拉起 cleanup-executor,或者宣布 "mission complete"。
cleanup-evaluator.mdmarkdown 1## MANDATORY: RESPOND TO THE MAIN AGENT 2 3You SHALL RESPOND with the [reordered_incomplete_item_list], [completed_item_list], [postponed_item_list] to the main agent with the JSON object of the following format: 4 5```json 6{ 7 "incomplete_items": [reordered_incomplete_item_list], 8 "completed_items": [completed_item_list], 9 "postponed_items": [postponed_item_list],10 "next_action": "spawn(cleanup-executor)|mission_complete"11}12```1314The `next_action` field SHALL BE `mission_complete` when NO ITEMS ARE LEFT in [reordered_incomplete_item_list].1516Otherwise, the `next_action` field SHALL BE `spawn(cleanup-executor)`.
回到 main agent,它会依据 cleanup-evaluator 的反馈拉起 cleanup-executor subagent,并把三个列表传过去:
cleanup.mdmarkdown 1## MANDATORY: 3. UNDERSTAND THE CLEANUP-EVALUATOR'S RESPONSE 2 3The cleanup-evaluator subagent is ALWAYS the core of the workflow. 4 5YOU MUST OBEY THE DECISION OF THE CLEANUP-EVALUATOR IN [next_action]. 6You SHALL NEVER CHANGE THE DECISION OF THE CLEANUP-EVALUATOR in [next_action]. 7 8The [next_action] COULD BE: `spawn(cleanup-executor)` | `mission_complete`: 910The [next_action_details] COULD BE:1112```json13{14 "type": "todo|fixme",15 "id": [next_item_id],16 "file": [next_item_file],17 "line": [next_item_line],18 "content": [next_item_content]19}20```2122OR2324```json25{26 "type": "mission_complete"27}28```2930The cleanup-evaluator subagent SHALL NEVER know if it is the last time to evaluate until the [next_action] of a spawned cleanup-evaluator turns out to be `mission_complete`.3132### MANDATORY: ALWAYS TRANSFER [incomplete_items], [completed_items], [postponed_items] FROM THE CLEANUP-EVALUATOR'S RESPONSE TO THE NEXT SUBAGENT3334YOU MUST transfer the [incomplete_items], [completed_items], [postponed_items] from the cleanup-evaluator's response to the next subagent with the JSON object of the following format:3536```json37{38 "incomplete_items": [incomplete_item_list],39 "completed_items": [completed_item_list],40 "postponed_items": [postponed_item_list],41}42```
此时协议允许 main agent 拉起 cleanup-executor 来执行下一条 TODO/FIXME。不过我们还需要告诉 main agent 如何处理 cleanup-evaluator 之外的 subagent 的反馈:
cleanup.mdmarkdown 1## MANDATORY: 4. UNDERSTAND THE RESPONSE FROM OTHER SUBAGENTS 2 3All the subagents other than the cleanup-evaluator subagent SHALL ALWAYS respond with a JSON object of the following format: 4 5```json 6{ 7 "incomplete_items": [next_incomplete_item_list], 8 "completed_items": [next_completed_item_list], 9 "postponed_items": [next_postponed_item_list],10 "next_action": "spawn(cleanup-evaluator)",11}12```1314### MANDATORY: ALWAYS READ Subagent’s Response to Decide Next Action1516The [next_action] is ALWAYS to spawn a cleanup-evaluator subagent.1718You MUST SEND the cleanup-evaluator a JSON object of the following format:1920```json21{22 "incomplete_items": [next_incomplete_item_list],23 "completed_items": [next_completed_item_list],24 "postponed_items": [next_postponed_item_list],25}26```
最后,让 main agent 知道何时应该收尾:
cleanup.mdmarkdown1## MANDATORY: 5. HANDLING MISSION COMPLETE23If `next_action` in the response from the cleanup-evaluator subagent is `mission_complete`, then the mission is completed.45You SHALL STOP ALL THE SUBAGENTS AND EXIT THE WORKFLOW.
到这里,我们已经用整套协议驱动的提示词搭好了第一个 agent 循环。
4试一试
当你把这个循环跑在 llama.cpp 项目上时,会发生以下情况:循环会精确处理 10 条 TODO 和 FIXME 后结束——无需宏大目标,只需一次专注的清理循环,就能让核心机制完整跑通。试一试
5让循环 7x24 运作
要让循环全天候运行,重点是持续供给“饲料”,而不仅仅是持续时间。循环靠把 A 持续变成 B 活下去:把一种产出不断转换成另一种。假如 A 是点子、B 是程序(或修复、测试、发布),那么想要 7x24 地运转,就需要源源不断的点子。现实里,我们不可能拥有无限点子。更实际的做法是:让循环承担足够大、值得托付的工作,为你腾出思考时间。当 agent 在完成 A→B(例如编译、测试、打包、部署)时,你就能利用空档决定下一个 A。像 TODO/FIXME 扫描器或 issue 跟踪器这样的“饲料器”可以提供候选项,但无法代替你的判断。循环负责落实有意义的任务,你负责策展输入,这就是维持 7x24 节奏的正确姿势。
具备这些条件,就能让 Claude Code(或 Codex)在循环里持续工作,即便你已经入睡。今晚就动手试试看吧。明早醒来,也许成果已经在等你。https://github.com/WeZZard/agentic-loop-playground.githttps://github.com/WeZZard/agentic-loop-playground[2]