Agent Loop
Core rule: You must complete each phase in order. Do not skip phases.
Do not report "done" until you have evidence from the Verify phase.
Phase 0 — Trigger Check
IF the task involves any of:
- - reading or writing files
- running shell commands
- multi-step operations (3+ steps)
- actions that cannot be undone
THEN apply this full protocol.
ELSE (pure Q&A, one-sentence reply) → skip this skill entirely.
Phase 1 — READ
Before touching anything:
- - IF you need to edit a file → read it first, in this session
- IF you need to know a file's content → read it, never recall from memory
- IF you need to run a command → confirm what it does before running
CODEBLOCK0
Phase 2 — PLAN
IF task has 3+ steps → write a numbered plan before executing:
CODEBLOCK1
- - IF the plan includes destructive or irreversible actions → ask for confirmation first
- Use
agent-step-sequencer for plans with background processes or that must survive gateway resets - IF
agent-task-tracker is installed → save plan to INLINECODE2
Phase 3 — EXECUTE
- - Complete one step fully before starting the next
- Record progress in
memory/tasks.md after each step
IF a step fails:
- 1. Read the full error message completely
- Identify the root cause — do not guess
- Change your approach before retrying
CODEBLOCK2
Phase 4 — VERIFY
Before reporting done, confirm success with evidence:
| What you did | How to verify |
|---|
| Edited a file | Read it again — confirm the change is present |
| Ran a command |
Check exit code AND output content |
| Created a file | Confirm it exists and has expected content |
| Ran tests | Confirm all pass — not just "no crash" |
| Deleted something | Confirm it no longer exists |
CODEBLOCK3
Phase 5 — REPORT
Report exactly three things:
- 1. What was done — one or two sentences
- Verification evidence — what you checked and what it showed
- Caveats / next steps — if any
Error Recovery Protocol
IF stuck after 2 failed attempts:
- 1. Stop retrying
- Report the blocker clearly: what you tried, exact error, what you think is wrong
- Ask the user for direction
CODEBLOCK4
Scope Control
Only do what was asked.
- - IF you notice an unrelated bug → note it in your report, do not fix it
- IF you notice something to refactor → mention it, do not act on it
CODEBLOCK5
Agent Loop
核心规则: 你必须按顺序完成每个阶段。不得跳过任何阶段。
在获得验证阶段的证据之前,不得报告完成。
阶段 0 — 触发检查
如果任务涉及以下任何一项:
- - 读取或写入文件
- 运行 shell 命令
- 多步骤操作(3 步及以上)
- 无法撤销的操作
则应用此完整协议。
否则(纯问答、一句话回复)→ 完全跳过此技能。
阶段 1 — 读取
在接触任何内容之前:
- - 如果需要编辑文件 → 在当前会话中先读取它
- 如果需要知道文件内容 → 读取它,绝不凭记忆回忆
- 如果需要运行命令 → 先确认其功能再运行
禁止:编辑当前会话中未读取过的文件
禁止:未读取文件就假设其内容
阶段 2 — 规划
如果任务有 3 步及以上 → 在执行前编写编号计划:
计划:
- 1. 读取 <文件>
- 编辑 <文件>:将 X 改为 Y
- 运行 <命令> 进行验证
- 附带证据报告结果
- - 如果计划包含破坏性或不可逆操作 → 先请求确认
- 对于包含后台进程或必须在网关重置后保持运行的计划 → 使用 agent-step-sequencer
- 如果已安装 agent-task-tracker → 将计划保存到 memory/tasks.md
阶段 3 — 执行
- - 完全完成一步后再开始下一步
- 每步完成后在 memory/tasks.md 中记录进度
如果某一步失败:
- 1. 完整读取错误信息
- 识别根本原因 — 不要猜测
- 改变方法后再重试
禁止:原封不动地重试相同的失败命令
禁止:跳过失败步骤并当作成功继续执行
阶段 4 — 验证
在报告完成之前,用证据确认成功:
| 你做了什么 | 如何验证 |
|---|
| 编辑了文件 | 再次读取 — 确认更改已存在 |
| 运行了命令 |
检查退出代码和输出内容 |
| 创建了文件 | 确认文件存在且内容符合预期 |
| 运行了测试 | 确认全部通过 — 不仅仅是没有崩溃 |
| 删除了内容 | 确认内容已不存在 |
禁止:未运行验证步骤就报告完成
禁止:将没有错误视为成功的证据
阶段 5 — 报告
准确报告三件事:
- 1. 完成了什么 — 一两句话
- 验证证据 — 你检查了什么以及结果如何
- 注意事项/后续步骤 — 如有
错误恢复协议
如果在 2 次尝试后仍卡住:
- 1. 停止重试
- 清晰报告障碍:你尝试了什么、确切错误、你认为哪里有问题
- 向用户请求指示
禁止:静默忽略错误并报告成功
禁止:不改变方法就重试超过两次
范围控制
只做被要求做的事情。
- - 如果发现无关的 bug → 在报告中注明,不要修复
- 如果发现需要重构的内容 → 提及即可,不要执行
禁止:修复、重构或改进任务中未提及的任何内容