Lesson 03

TodoWrite 任务追踪

Agent 能追踪自己的进度,而且我能看到

// Agent Loop + TodoManager State

AGENT LOOP User Input 用户输入 LLM 模型 Tools 工具执行 tool_result TODOMANAGER STATE [x] 读取项目结构 completed [x] 分析依赖关系 completed [>] 实现核心功能 in_progress [ ] 编写测试用例 pending [ ] 更新文档 pending STATE MACHINE pending in_progress completed NAG: rounds >= 3 未更新? todo_write Round Counter roundsSinceUpdate: 3 → inject nag reminder

Key Concepts 核心概念

01

结构化状态 Structured State

TodoManager 不是普通文本,是可验证的数据结构。每个 todo 有 id、内容、状态三个字段,状态只能是 pending / in_progress / completed。

TodoManager is not plain text but a verifiable data structure with id, content, and status fields. Status transitions are enforced.

02

Nag Reminder 提醒机制

如果 Agent 连续 3 轮没有更新 todo,系统自动注入提醒消息。但只是提醒,不强制——模型可以选择忽略。

If 3 rounds pass without a todo update, a reminder is injected into the conversation. It's a nudge, not a mandate.

03

可见性 Visibility

用户能实时看到 Agent 在干什么、完成了多少、卡在哪里。不再是"黑盒"等待。

Users can see what the agent is working on, how much is done, and where it's stuck. No more black-box waiting.

State Transitions 状态转换

From To 说明
pending [ ] in_progress [>] Agent 开始处理此任务
in_progress [>] completed [x] 任务完成
pending [ ] completed [x] 简单任务可以直接完成
any state pending [ ] 任务回退(极少使用)

试一试 Try It Out

1

"重构 Hello.java:添加类型提示、文档注释和 main 方法保护"

"Refactor the file Hello.java: add type hints, docstrings, and a main guard"

2

"创建一个 Java 包,包含 App.java、Utils.java 和 tests/UtilsTest.java"

"Create a Java package with App.java, Utils.java, and tests/UtilsTest.java"

3

"审查所有 Java 文件并修复任何风格问题"

"Review all Java files and fix any style issues"