Skip to content

fix(agent-core-v2): nudge the agent to keep its todo list current - #4239

Merged
RealKai42 merged 2 commits into
mainfrom
fix/todo-list-keep-current
Oct 15, 2026
Merged

RealKai42 merged 2 commits into
mainfrom
fix/todo-list-keep-current

Conversation

@RealKai42

@RealKai42 RealKai42 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

模型在多步任务中经常不更新 todo 列表,回合结束后面板仍停在过期状态;现有的过期提醒几乎不起作用。

Bug Reproduction Steps

  1. 让 agent 做一个 3~4 步的任务,例如"把配置解析从 JSON 换成 TOML,更新调用方,再补上测试"。
  2. 模型用 TodoList 建表(第 1 项进行中,其余待办)后开始干活,之后不再调用 TodoList。
  3. 回合结束,todo 面板仍显示"第 1 项进行中、其余待办",并一直保持到列表被清空。
  4. 过期提醒要在上次写入之后第 10 个 assistant step 才会出现:第 k 步开始前,写入之后只有 k−2 个 step,所以最早在第 12 步。10 步以内结束的回合里,它一次都不会出现。

Root Cause

  • 触发时机:提醒按固定步数(≥10)触发,和"某一项刚做完""准备写最终回复"这两个真正需要更新的时刻无关;短回合里根本不出现,长回合里多半落在某一项的中途。
  • 不看列表状态:空列表、全部完成的列表照样提醒;提醒在首次访问 todo 服务后才启用,而任意一次 compaction 和 TUI 的 /undo 也算访问,会把它意外启用。无关的提醒多了,模型就学会忽略。
  • 每一层都允许"不更新":提醒文案沿用了 Claude Code 的温和措辞("This is a gentle reminder; ignore it if not applicable");工具描述里继承自 kimi-cli SetTodoList 的三条 Avoid churn 在劝模型少调用;system prompt 里没有任何 todo 规则。
  • 写入后的回显只有一句通用的话,没有告诉模型下一步具体该做什么。

这是提示层面的缓解,不是根本修复:模型最终是否更新仍取决于模型本身。本 PR 同时加了埋点,用来衡量改动效果、决定后续方向。

Code Changes

文件职责:

 packages/agent-core-v2/src/
 ├── features/todo/
 │   ├── todoItem.ts              # + todoProgress():总数 / 完成数 / 未完成数 / 进行中的项
 │   ├── todoListReminder.ts      # 只在有未完成项时提醒,阈值 10 → 5,新文案;+ todoListWriteStatsBefore()
 │   ├── todoService.ts           # 去掉"首次访问才启用";提醒与回合结束的埋点
 │   └── tools/todo-list/
 │       ├── todo-list.md         # 工具描述:删掉劝阻更新的说法,新增 "Keeping it current"
-│       ├── todo-list-write-reminder.md
 │       └── todoListTool.ts      # 写入回显改为按状态给出下一步;todo_list_written 埋点
 ├── app/agentProfileCatalog/
 │   ├── system.md                # Delivering work 一节新增 ${todo_list_guidance}
 │   ├── profile-shared.ts        # TODO_LIST_GUIDANCE,只在 TodoList 可用时渲染
 │   └── agentProfileCatalog.ts   # AgentProfileContext.todoListActive
 ├── agent/profile/profileService.ts  # 和 notifyUserActive 一样计算 todoListActive
 └── app/telemetry/events.ts      # 三个新事件

过期提醒的判断:

 todoListStaleReminder(history, todos)
   if TodoList is not active → skip
+  if no item is pending or in_progress → skip
-  if steps since last write < 10 or steps since last reminder < 10 → skip
+  if steps since last write < 5 or steps since last reminder < 5 → skip
-  "has not been updated recently … consider … gentle reminder; ignore it if not applicable"
+  "has not been updated in the last N steps (k/n done, "X" still in_progress). If an item is
+   finished, mark it done now … If the list no longer matches the current work, rewrite or clear it."

todo actor 的状态机:

-beforeRestore ──restore──▶ active ──first get/replace/clear──▶ reminding (register reminder)
+beforeRestore ──restore──▶ active (main agent: register reminder, track TurnStarted / TurnEnded)

TodoList 写入后的回显:

 Todo list updated.
 <list>
-Ensure that you continue to use the todo list to track progress. Mark tasks done immediately …
+<按状态给出下一步>
+  有进行中的项、后面还有待办 → When "X" is finished, mark it done and set the next item in_progress; …
+  只剩最后一项在进行中      → "X" is the last open item. Once it is finished, mark it done before you write
+                              your final message; if it stays blocked or unfinished, keep it in_progress and
+                              say what remains in your reply.
+  没有进行中的项            → No item is in_progress. Mark the one you are working on as in_progress.
+  多个项在进行中            → Several items are in_progress. Keep only the one you are working on now in_progress.
+  全部完成                  → (不加)

新增的埋点(agent 级事件,只记数字,不记标题或内容):

事件 时机 字段
todo_list_written TodoList 写入或清空 item_count、open_count、steps_since_write(上下文里没有更早的写入时省略)、after_reminder
todo_reminder_shown 过期提醒注入 steps_since_write、item_count、open_count
todo_turn_ended 主 agent 回合结束,且列表非空或本回合内改动过(包括清空) reason、item_count、open_count、updated_in_turn

衡量这次改动的主指标:在 updated_in_turn = true 的 todo_turn_ended 中,open_count > 0 所占的比例,也就是本回合用过列表、结束时仍有未完成项的回合占比。本回合内清空列表的回合以 item_count = 0 计入分母。updated_in_turn = false 的是上一个请求遗留下来的列表,单独看。注意 open_count = 0 并不代表列表准确,模型也可能误标完成,这部分要靠离线抽样核对。

Behavior Changes and Affected Users

行为 之前 之后 谁依赖旧行为 退路
过期提醒何时启用(主 agent) 首次访问 todo 服务后才启用;任意一次 compaction、TUI /undo 也会启用 主 agent restore 后就注册,是否提醒只看列表状态 无:从没用过 TodoList 的会话列表为空,前后都不提醒 无
列表为空或全部完成时的提醒 提醒启用后照样每 10 步提醒"consider using TodoList" 不提醒 无已知依赖,这类提醒本身就是噪音 无
提醒阈值 距上次写入 ≥10 个 assistant step,且距上次提醒 ≥10 步 两者都改为 ≥5 步 无,阈值是内部常量,不可配置 无
上一请求遗留、仍有未完成项的列表 提醒已启用时,新回合里满 10 步提醒 满 5 步提醒;文案建议与当前工作不符时重写或清空 无 模型可以用 todos: [] 清空列表
TodoList 写入成功后的回显 固定附一句 "Ensure that you continue to use the todo list…" 按列表状态附一句下一步;全部完成时不附 无 无
system prompt 没有 todo 规则 "Delivering work" 一节多一段 TodoList 规则 无 在 [tools] 里禁用 TodoList 后不会出现
遥测 无 todo 相关事件 新增上面三个事件 关闭遥测的用户照常不上报 KIMI_DISABLE_TELEMETRY

提示词逐句变化:

工具描述 todo-list.md(受众:所有能用 TodoList 的会话,即默认 agent、coder 子 agent、Tower worker)

句子 之前约束了什么 现在由什么约束
删除 "Do not re-call this tool when nothing meaningful has changed since the last call — update the list only after real progress." 防止没有进展时反复调用(kimi-cli SetTodoList 时代的循环问题);副作用是劝模型少更新 新增 "Do not re-send an unchanged list.";完全相同的重复调用还有 toolDedupe 的 repeat breaker
删除 "When unsure of the current state, call query mode first (omit todos) to check the list before deciding what to update." 让模型先查再改,使每次更新变成两步 过期提醒和写入回显都带着当前列表;query 模式本身仍在 How to use 里说明
"If no available tool can move any task forward, tell the user where you are stuck instead of repeatedly re-ordering the same todos." 改为 "If you are stuck and no available tool can move any task forward, tell the user instead of re-ordering the same todos." 卡住时不要反复重排 约束不变,并入同一条
"Before starting a tracked task, mark exactly one item as in_progress" 和 "Immediately after finishing a tracked task, mark it done; do not batch completions at the end" 从 When to use 移到新的 "Keeping it current",并补上 "before you start the next one" 状态更新的时机 约束不变,表述更具体
删除 "Update statuses as you make progress." 和 "When work is underway, keep exactly one task in_progress." 同上 并入 "Keeping it current" 的前两条
新增 "The list is shown to the user as a live progress panel, so keep it in step with what you have actually done." — 告诉模型列表对用户可见,过期会误导用户
新增 "Before you write your final message, make sure the list matches what you actually did." — 最终回复前把列表补齐,避免回合结束后面板过期
新增 "An update can go in the same response as your next tool call; it does not need a step of its own." — 降低更新成本,不必为更新单独多走一步

删除 todo-list-write-reminder.md(受众:每次成功写入非空列表的所有 agent)

句子 之前约束了什么 现在由什么约束
"Ensure that you continue to use the todo list to track progress. Mark tasks done immediately after finishing them, and keep exactly one task in_progress when work is underway." 继续用列表、做完即标、只保留一个进行中 回显按状态给出具体下一步(包括多个进行中时的提示);其余由工具描述的 "Keeping it current" 约束

过期提醒文案 todoListReminder.ts(受众:主 agent,列表有未完成项且 ≥5 步未更新)

句子 之前约束了什么 现在由什么约束
删除 "If you are working on tasks that benefit from progress tracking, consider using TodoList to update task status." / "Only use it if relevant." / "This is a gentle reminder; ignore it if not applicable." 允许模型在提醒不相关时忽略 提醒只在有未完成项时出现,不再需要"可以忽略";改为写明未更新的步数、进度和进行中的项,并要求做完就标 done
"Also consider clearing or rewriting the todo list if it has become stale and no longer matches the current work." 改为 "If the list no longer matches the current work, rewrite or clear it." 过期列表的清理 约束不变
"Make sure that you NEVER mention this reminder to the user." 改为 "Never mention this reminder to the user." 不向用户提及提醒 约束不变

system.md(受众:渲染内置模板、且 TodoList 可用的 profile,即默认 agent 和 coder 子 agent;explore 子 agent 没有 TodoList,不受影响)

句子 之前约束了什么 现在由什么约束
新增 "When you track work in TodoList, keep it in step with what you have actually done: mark an item done as soon as it is finished, before you start the next one, and make sure the list matches what you did before you write your final message." — 和工具描述一致的主 prompt 规则,参照 Codex 把行为规则放在主 prompt、并绑定到具体动作的做法

受影响模块与测试覆盖:

  • 提醒的启用条件、阈值、间隔、列表状态判断:test/features/todo/todoListReminder.test.ts、test/features/todo/sessionTodo.test.ts。子 agent 不提醒的旧行为由 sessionTodo.test.ts 继续覆盖。
  • 写入回显的各种状态、todo_list_written:test/features/todo/tools/todo-list.test.ts
  • todo_reminder_shown、todo_turn_ended:test/features/todo/sessionTodo.test.ts,包括本回合清空列表时上报、列表为空且本回合未改动时不上报
  • system prompt 槽位:test/app/agentProfileCatalog/profile-shared.test.ts
  • 事件注册表的通用约束:test/app/telemetry/events.test.ts
  • 内联快照更新:test/agent/loop/loop.test.ts、test/tool/tool.test.ts,只有 TodoList 描述和随之变化的 hash
  • 没有改动契约文件:docs/ 下的 manifest、kap-server API 快照、node-sdk 导出、apps/kimi-code/src/cli/ 都没动。

本地完整测试中有两个失败与本 PR 无关,CI 上均通过:test/tool/tool.test.ts 的 "returns the spawned agent id when a foreground subagent times out" 在本地未改动的 main 上同样超时;test/mcpCore/connection-manager.test.ts 的 OAuth 401 用例在全量并发下不稳定,单独运行通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

- Remind only while the list still has pending or in_progress items, and
  drop the first-use arming gate so compaction and /undo no longer arm the
  reminder for agents that never used TodoList.
- Remind after 5 steps without an update (was 10) with text that names the
  step count, progress, and the item still in progress, instead of the
  gentle "ignore it if not applicable" wording.
- Replace the static TodoList write echo with a next step for the current
  list state.
- Drop the churn warnings that discouraged updates from the TodoList
  description, say the list is a live progress panel, and add a TodoList
  paragraph to the system prompt when the tool is active.
- Track todo_list_written, todo_reminder_shown, and todo_turn_ended.
Copilot AI balanced review requested due to automatic review settings October 15, 2026 08:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T08:54:32.549517Z 91d692c New commits
🔒 Security Review ✅ Completed 2026-10-15T08:41:20.312786Z 8d55fb4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 91d692c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@91d692c
npx https://pkg.pr.new/@moonshot-ai/kimi-code@91d692c

commit: 91d692c

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

最后一项的回显需保留未完成或阻塞状态,避免无条件要求标记完成而误导用户及遥测。

1 open finding
What changed in this PR

本 PR 在 agent-core-v2 中加强 TodoList 更新提示,减少进度面板过期,并增加遥测衡量效果。

Changes:

  • 仅对未完成列表提醒,将提醒间隔从 10 步缩短为 5 步。
  • 增加系统提示规则和按列表状态生成的写入回显。
  • 新增写入、提醒和回合结束遥测,并补充相关测试。
File Description
packages/​agent-core-v2/​test/​features/​todo/​tools/​todo-list.test.ts 覆盖状态回显和写入遥测
packages/​agent-core-v2/​test/​features/​todo/​todoListReminder.test.ts 覆盖提醒阈值及写入统计
packages/​agent-core-v2/​test/​features/​todo/​sessionTodo.test.ts 覆盖提醒启用和回合遥测
packages/​agent-core-v2/​test/​app/​agentProfileCatalog/​profile-shared.test.ts 验证提示词条件渲染
packages/​agent-core-v2/​test/​agent/​loop/​loop.test.ts 更新工具描述快照及哈希
packages/​agent-core-v2/​src/​features/​todo/​tools/​todo-list/​todoListTool.ts 添加状态回显和写入遥测
packages/​agent-core-v2/​src/​features/​todo/​tools/​todo-list/​todo-list.md 强化进度更新规则
packages/​agent-core-v2/​src/​features/​todo/​tools/​todo-list/​todo-list-write-reminder.md 删除固定写入提示
packages/​agent-core-v2/​src/​features/​todo/​todoService.ts 调整提醒注册并跟踪回合状态
packages/​agent-core-v2/​src/​features/​todo/​todoListReminder.ts 调整提醒条件、文案及统计
packages/​agent-core-v2/​src/​features/​todo/​todoItem.ts 增加列表进度汇总
packages/​agent-core-v2/​src/​app/​telemetry/​events.ts 定义三个 TodoList 遥测事件
packages/​agent-core-v2/​src/​app/​agentProfileCatalog/​system.md 添加 TodoList 指导槽位
packages/​agent-core-v2/​src/​app/​agentProfileCatalog/​profile-shared.ts 按工具可用性渲染指导
packages/​agent-core-v2/​src/​app/​agentProfileCatalog/​agentProfileCatalog.ts 增加工具可用性上下文字段
packages/​agent-core-v2/​src/​agent/​profile/​profileService.ts 计算 TodoList 可用性
.changeset/​todo-list-keep-current.md 记录用户可见行为变化

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d55fb4bae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +7 to +8
const TODO_LIST_REMINDER_STEPS_SINCE_WRITE = 5;
const TODO_LIST_REMINDER_STEPS_BETWEEN_REMINDERS = 5;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate the new five-step reminder behavior

For every main-agent session with an unfinished TodoList, these constants unconditionally replace the previous ten-step cadence with a more frequent five-step prompt, while the accompanying prompt changes also remove the old gentle/ignore behavior. There is no config, environment variable, or flag that preserves the previous model behavior, and the commit does not contain the alternative explicit maintainer sign-off required for an un-gated removal/default change; add an escape hatch or obtain and record that approval.

AGENTS.md reference: AGENTS.md:L101-L103

Useful? React with 👍 / 👎.

- Ask the agent to mark the last open item done only once it is finished;
  if it stays blocked or unfinished, keep it in_progress and say what
  remains in the reply.
- Emit todo_turn_ended for turns that cleared the list, so cleared lists
  count toward the stale-list ratio instead of being dropped.
@RealKai42
RealKai42 merged commit da5918c into main Oct 15, 2026
17 checks passed
@RealKai42
RealKai42 deleted the fix/todo-list-keep-current branch October 15, 2026 09:14
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Oct 22, 2026
…onshotAI#4239)

Ported from MoonshotAI/kimi-code 2.3.0 (da5918c).

Kept this fork's richer todo model (ids, milestones, progress) and its tree
renderer, so the port only adds upstream's TodoProgress/todoProgress helper next
to computeTodoProgress.
Rendered the new reminder wording through renderTodoList instead of upstream's
flat renderTodoItems, and kept todoActiveReminder beside the new stale reminder.
Rebuilt the todo tests on the fork's TodoItem shape (todoItem helper rather than
title/status literals) and moved the step thresholds from 10 to 5.
Reworked the todo-list tool prompt: our granularity, milestone and progress
sections stay and upstream's keep-it-current bullets fold into the churn
section; the write-time hint replaces the deleted todo-list-write-reminder.md.
Rebaselined the llm.tools_snapshot inline snapshots in loop.test.ts and
tool.test.ts for the new tools hash and TodoList description.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants