Skip to content

chore(agent-core-v2): trim built-in tool descriptions - #4466

Closed
7Sageer wants to merge 5 commits into
mainfrom
chore/slim-cron-tool-prompts
Closed

7Sageer wants to merge 5 commits into
mainfrom
chore/slim-cron-tool-prompts

Conversation

@7Sageer

@7Sageer 7Sageer commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

精简内置工具描述,降低每次请求的固定 prompt 开销。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

分三个提交,每个提交一组工具,可以逐个审:

提交 工具 改前(字符) 改后(约)
1 CronCreate / CronList / CronDelete 10,518 1,132
2 Read / Bash / Agent 13,277 6,340
3 ExitPlanMode / CreateGoal / GetGoal / SetGoalBudget / UpdateGoal 7,316 3,316
合计 31,111 10,788

主 agent 每次请求少约 20k 字符(约 5k token)。

删减标准:

  1. 模型调用当下能从别处拿到的信息不在描述里重复:运行时报错、工具返回和状态块、参数说明、压缩后的 Context Recovery 提示、Plan 模式提醒、goal 提醒。
  2. 模型本来就会的常识删掉(cron 语法、shell 操作符、常用命令清单)。
  3. 跨工具重复的规则只留一处。
  4. 为具体问题加过的约束保留原句。我对被删的句子逐句查过来历:大部分来自初始导入或功能刚上线时;后来专门调过的句子(比如"只在用户明确要求时才启动子 agent"、"已知路径直接读"、"只读命令并行调用"、goal 的完成 / 阻塞判定)要么原样保留,要么在每回合注入的提醒里逐字保留。

1. Cron

只改描述文本。保留的是模型推断不出来的产品规定:任务只在当前会话里存活、用户无法自己管理任务、时间说得模糊时避开 :00/:30、多次错过的触发会合并成一次、周期任务 7 天后过期。

2. Read / Bash / Agent

Bash 的描述改为用模板变量生成,不再做字符串替换:

 get description()
-  rendered = renderPrompt(bash.md, 超时数字, SHELL_NAME)
-  if 不支持后台: return withoutBackgroundDescription(rendered)   // 按原文正则 / 精确匹配替换
-  if 超时不自动转后台: return withoutAutoBackgroundOnTimeout(rendered)
-  return rendered
+  return renderPrompt(bash.md, {
+    SHELL_NAME,
+    TIMEOUT_GUIDANCE:    不支持后台 ? 超时即终止 : 自动转后台 ? 超时转后台 : 超时即终止(可手动转后台),
+    BACKGROUND_GUIDANCE: 支持后台 ? 后台用法 : "本 agent 不能后台运行",
+  })

原来的替换按 bash.md 原文精确匹配:只要改了 md 里那几句,替换就会悄悄失效,不支持后台的 agent(比如 TaskList 等工具被禁用时)会被告知可以用 run_in_background。现在改为模板变量生成;工具描述的具体文案不作为稳定测试契约。

3. Plan / Goal

依据:这几个工具的长规则只在特定状态下才用得上,而在那些状态下,系统已经会注入内容相同的提醒:

  • Goal:goal 进行中时,goal-active-reminder.md 在每个新回合都会注入(goalInjection.ts 里 isNewTurn 时返回)。里面逐字包含完成判定、阻塞判定(包括"同一阻塞连续 3 轮")、"大多数回合不调用 UpdateGoal",以及"先检查有没有明确的预算、不要编造预算"。UpdateGoal 的 status 参数说明里也写了阻塞规则。
  • Plan:Plan 模式开启时,完整提醒会在每条新用户消息、以及每隔 5 个 assistant 回合发送一次(planModeInjection.ts),中间发简短提醒。里面包含"计划不确定时先用 AskUserQuestion"、"auto 模式下不能用 AskUserQuestion,要把决定写进 Assumptions"、"不要用文字或 AskUserQuestion 问计划行不行"、"多个方案要传 options"、"用户问的是问题时直接回答"。

所以工具描述里只留提醒里没有的内容。

测试改动

  • 通用流程快照在 test/harness/snapshots.ts 统一归一化:工具表只保留名称,toolsHash 使用占位符;完整工具表与 hash 的对应关系仍由 llmRequester.test.ts 覆盖。
  • fullCompaction.test.ts:固定 token 数改为类型断言;pre-shrink 使用 80k 窗口和大余量 fixture,额外 overhead 由测试自行注入,不再跟随内置 prompt 长度调整。
  • bash.test.ts:删除四个直接断言工具描述文案的用例,保留后台执行、超时和权限等运行行为测试。

Behavior Changes and Affected Users

受影响人群:所有主 agent 会话(TUI、print 模式、desktop 与 web、VS Code、ACP、SDK),因为工具描述随每次请求下发;能用 Bash / Read 的子 agent(coder、explore、plan、Tower worker)也受影响。Cron 和 Goal 工具只对主 agent 开放。

1. Cron

句子 / 段落 改前约束了什么 现在由什么约束
CronCreate「One-shot tasks」小节(含两个例子) 一次性提醒要固定 分/时/日/月,并设 recurring: false 参数 recurring 的说明("Use false for 'remind me at X' one-shot requests with pinned minute/hour/dom/month")和 cron 的说明(固定日期不设 false 会每年重复)
CronCreate「Recurring jobs」小节 周期任务的写法示例 参数 cron 的说明自带 */5 * * * * 示例;模型本来就会写 cron
CronCreate「避开 :00 / :30」小节 时间模糊时避开整点、半点,防止全网同时打 API 保留,压成一句加两个例子
CronCreate「Coalesce semantics」+「Cron-fire envelope」 只在空闲时投递;coalescedCount > 1 时只按最新状态处理一次;<cron-fire> 的格式 保留语义,压成一句;格式样例删掉,模型在触发时会直接看到这段 XML
CronCreate「7-day stale behavior」、CronList 的 stale 字段说明、CronDelete「Refresh pattern」 周期任务 7 天后过期,最后一次触发带 stale="true",要继续就用同样的 cron 和 prompt 重新创建 只在 CronCreate 保留一处;CronList 保留一句 stale 的含义
CronCreate「Jitter behavior」 随机延迟的具体幅度 删除。CronList / CronCreate 返回的 nextFireAt 已经包含延迟
CronCreate「One-shot vs recurring」 什么时候选哪种 参数 recurring 的说明
CronCreate「Session lifetime」 任务属于当前会话,恢复同一会话时还在,新会话里没有;因此一次性任务别排得太远 保留,压成一句
CronCreate「Limits」 50 个任务上限、prompt 长度上限、5 年内必须能触发 运行时报错(Cron job cap reached、Prompt exceeds、has no fire within 5 years);prompt 上限也写在参数说明里
CronCreate「Returned fields」 返回字段列表 返回结果本身是 key: value 格式,一看就懂
CronCreate「Tell the user how to cancel or modify」、CronList 和 CronDelete 里「用户无法自己管理任务」 用户没有自助管理入口,创建后要告诉用户任务 id,并说明可以让模型来取消或修改 只在 CronCreate 保留一处。这条是 ee69d0ac29 特意加的,行为不变
CronList 逐字段说明(id / cron / humanSchedule / prompt / nextFireAt / recurring / ageDays / stale) 解释输出格式 输出本身已经能看懂;只保留 stale 的含义
CronList「只读,plan 模式也能调用」 提示模型可以放心调用 保留 "Read-only"
CronList / CronDelete「上下文压缩后先调 CronList,不要猜 id」 压缩后避免用失效的 id 保留在 CronList 和 CronDelete 各一句
CronDelete「一次性任务触发后已经删除,会报 not found」 遇到 not found 时改去调 CronList,而不是重试 保留,压成一句
CronDelete「Cron deletion is irreversible」 删除不可撤销 删除。模型本来就知道,system prompt 的 Risky actions 段也有覆盖
CronDelete「代用户删除时确认并如实汇报结果」 汇报删除结果 删除。删除工具的返回会写明结果,汇报结果是默认行为

2. Read / Bash / Agent

Read

句子 / 段落 改前约束了什么 现在由什么约束
「已知路径直接 Read,不要先 Glob / ls」「不要 Read 目录」「Grep 只用于找未知内容」 避免多余的探查调用 保留原句
「多个文件并行读」 并行调用 保留原句
「写完不要为了确认再读一遍」 避免多余的读 保留原句
「需要全文时首次就调大 max_chars」「范围不完整时照 Next Read 续读,不要拿半页作答」 大文件完整读取 保留,压成两句(来自 #3645)
kimi-file:// 附件那一段(存储来源、fork 后续读、二进制附件的服务端路径、ReadMediaFile 也接受) 附件的读取细节 第一句保留"也可以读本会话的 kimi-file:// 附件";参数 path 的说明已写明;二进制附件的情况由报错说明。按 #3046 的约定,Read 描述不再点名 ReadMediaFile
相对路径和绝对路径的规则 路径解析 参数 path 的说明
字符预算按 JS 字符串长度算、不会被通用输出上限二次截断、没有固定行数上限 实现细节 删除;状态块会写明实际生效的 max_chars
line_offset / n_lines 翻页、负数 line_offset 倒着读的取舍、column_offset 的边界规则 续读机制 参数说明(line_offset 写了负数用法,column_offset 写了"从上一次结果里复制续读参数");越界、拆开 Unicode 字符、倒着读时带 column_offset 都有专门的报错
读 wire.jsonl 事件日志的方法 压缩后回查历史 压缩后附加的 Context Recovery 提示(context-recovery-footer.md)有完整的读法说明,而且只在需要时出现;读到事件日志时状态块也会提示
敏感文件会被拒绝及豁免清单 不要尝试读密钥文件 system prompt 的 Environment 段("dedicated tools refuse well-known secret files")和拒绝时的报错
UTF-16 检测、有损解码警告、Edit/Write 需要 UTF-8、GBK / 二进制被拒绝 编码处理 第一句写明支持 UTF-8 和 UTF-16;检测到的编码、有损解码、"Edit/Write 需要先转成 UTF-8" 都会出现在状态块里;GBK 等编码的报错会建议用 iconv
纯 CRLF 显示为 LF、Edit 会保留 CRLF;混合 / 单独的 \r 显示为 \r Edit 时怎么写换行 纯 CRLF 时模型按显示的 LF 写 Edit 本来就能匹配;混合的情况状态块会提示
「输出格式 <行号>\t<内容>,后面附 <system> 状态块,不属于文件内容」 解析输出 保留,压成一句
「当任务依赖确切的文件 / API / 输出格式时,收尾前检查最终的外部契约」 收尾前做验证 system prompt 的 Delivering work 段("verify the deliverable in the form the user will receive it")

Bash

句子 / 段落 改前约束了什么 现在由什么约束
「改用专用工具」对照表及理由 优先用 Read / Edit / Write / Glob / Grep 保留原文
输出格式、非零退出码那一行 解读输出 保留,压成一句
后台运行段(返回 task ID、必须给 description、disable_timeout、自动通知、不要立刻等、TaskOutput 只看快照、TaskStop 只用来取消) 后台任务用法 保留,压成 BACKGROUND_GUIDANCE 一段
后台运行段里的超时数字 默认值和上限 参数 timeout 的说明(前台和后台的默认值、上限都写了)
「用户想自己看后台任务时,指给他们后台任务面板」 告诉用户去哪看 删除;启动后台任务的返回结果里有 human_shell_hint: The task is visible in the background-task panel.
每次调用都是新 shell、cd 不保留、用 cwd 工作目录 保留,压成一句
不要跑交互式命令或不会退出的命令、超时会转后台 / 被终止、用户可以手动转后台 超时行为 保留,按三种情况由 TIMEOUT_GUIDANCE 插入,文字和原来的替换结果一致
不要用 .. 访问工作目录之外、不要改工作目录之外的文件、不要用超级用户权限、git 写操作只在用户要求时执行 安全约束 保留,压成两条
&& 串联有依赖的命令;独立的只读命令分开并行调用,不要用 echo 拼接输出 并行调用(#1296 加的) 保留
;、||、管道、重定向、路径加引号、用 if/for 写多步逻辑 shell 常识 删除
「常用命令」清单(约 900 字符) 告诉模型有哪些命令 删除;保留"命令是否可用取决于主机,用之前先 which"和"GitHub 相关优先用 gh"(#1296 加的)
「不支持后台时:不要设 run_in_background=true;后台任务管理工具不可用」 不支持后台的 agent 不要尝试 保留,由 NO_BACKGROUND_GUIDANCE 插入

Agent

句子 / 段落 改前约束了什么 现在由什么约束
「子 agent 以同进程 loop 实例运行,有自己的上下文和 wire 文件」 实现细节 压成"在它自己的上下文里处理任务"
「除非用户明确要求,否则不要启动子 agent」整段 主 agent 自己乱启动子 agent(10 月 24 日修的问题) 原句不动;system prompt 里那句也保留
写 prompt 的建议、resume 优先、结果只有你能看到、启动后别重复它的工作 子 agent 用法 原句不动
后台运行段(两段,约 790 字符) 结果会自动到达、不要轮询、不要编造结果;需要结果时用前台 保留全部要点,压成一段

3. Plan / Goal

ExitPlanMode

句子 / 段落 改前约束了什么 现在由什么约束
「How This Tool Works」三条(计划先写进文件、工具不接收计划内容、用户在任何权限模式下都会审阅) 调用方式 保留,压成一段
「If rejected, revise based on feedback and call ExitPlanMode again」 被拒后重来 保留,并入第一段
「What a good plan contains」整段 计划的结构 原文保留。Plan 模式提醒写的是"按 ExitPlanMode 描述里的结构",所以必须留在这里
「When to Use:只用于需要规划实现步骤的任务,研究类任务不要用」 不要对纯研究请求提交计划 Plan 模式完整提醒和简短提醒都有:"When the user's message calls for an answer rather than a plan … answer in text"
「Multiple Approaches:多个方案用 options 传」 多方案要可选 Plan 模式提醒("you MUST pass them as the options parameter"),以及参数 options 的说明
「Before Using」:偏好未定先 AskUserQuestion;auto 模式不可用时把决定写进 Assumptions;不要用 AskUserQuestion 问"计划行不行" 提问和审批的分工 Plan 模式完整提醒的 Questions 段、末尾两句,以及简短提醒

UpdateGoal

句子 / 段落 改前约束了什么 现在由什么约束
active:用户明确要求时恢复暂停或阻塞的 goal 恢复 goal 保留。暂停 / 阻塞时的提醒里没有这一条
complete 的判定(验证每一条要求、证据不足不算完成、不能因为预算快用完就标完成) 防止过早完成(#1456) goal-active-reminder.md 的 Completion audit,逐字保留,每回合注入
blocked 的判定(真正的僵局、同一阻塞连续 3 轮、恢复后重新计数、目标本身不可能时当轮标记、哪些情况不算阻塞) 防止过早放弃(#1481) goal-active-reminder.md 的 Blocked audit,逐字保留,每回合注入;参数 status 的说明也有
「大多数回合不调用 UpdateGoal,做完一段就正常结束回合」 不要每轮都改状态 goal-active-reminder.md;描述里保留一句"不要因为做完一段工作就调用"
「调用 blocked 后下一条消息要解释阻塞原因」 收尾说明 保留

SetGoalBudget

句子 / 段落 改前约束了什么 现在由什么约束
只在用户明确给出上限时设置(含三个例子)、不要编造、模糊说法不算 不编造预算 保留
复合时间先换算成一个单位 参数格式 保留
时间至少 1 秒、轮数和 token 数取正整数 取值范围 删除;不合理的值会返回 "Goal budget not set: … is not a reasonable goal budget."
支持的单位列表 参数取值 参数 unit 的 enum

GetGoal

句子 / 段落 改前约束了什么 现在由什么约束
返回内容、没有 goal 时返回 { "goal": null } 解读结果 保留
「在决定继续、完成、报阻塞或遵守暂停之前先调用 GetGoal」 决策前先查状态 goal 进行中时,每回合的提醒已经带着目标、状态、进度和预算;暂停 / 阻塞时也有对应提醒

CreateGoal

句子 / 段落 改前约束了什么 现在由什么约束
全部规则(只在用户明确要求或宿主提示要求时创建、模糊请求先问完成标准、用户坚持就照做、completionCriterion、objective 要简洁、replace) 何时创建、怎么填 全部保留,只合并成两段

其他可观测变化

  • 工具列表的 hash 变了:升级后已有会话的下一次请求会错过一次 prompt 缓存,之后恢复正常。
  • 不涉及配置键、环境变量、wire / 状态契约文件、kap-server API 快照。bashAutoBackgroundOnTimeout 配置和"TaskList / TaskOutput / TaskStop 任一被禁用时就不能后台运行"的判断没变,只是 Bash 描述的生成方式变了。
  • <cron-fire> 消息格式、cron 调度、参数 schema 都没变。

覆盖

  • AgentGym(Node 24-bookworm,普通 node 用户)执行 pnpm exec vitest run --maxWorkers=15:17,926 条通过、31 skipped、0 failed;908 个测试文件通过、7 skipped。
  • agent-core-v2 build / typecheck 与仓库 pnpm lint 通过(0 errors,既有 warnings)。
  • 与 chore(agent-core-v2): trim remaining tool descriptions #4476 合并后的 tree 额外执行 prompt 独立性验证:临时修改 agent.md 后,相关 6 个测试文件 544 条通过、1 skipped,未产生快照更新。
  • 描述文本的行为影响需要评测验证,重点看:
    • cron:创建一次性和周期提醒、取消、过期后重建;
    • Read / Bash:已知路径直接读、并行读、大文件续读、后台任务不被立刻等待、只读命令并行调用;
    • goal:是否过早标记 complete / blocked;
    • Plan:计划结构和 options 的使用是否不变。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • Updated existing tests to cover behavior changes without coupling them to prompt wording or length.
  • 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.

Keep only the product rules the model cannot infer: session-scoped lifetime, no user self-service, avoiding :00/:30 for approximate times, coalesced fires, and the 7-day stale refresh. Runtime errors, tool output, and parameter descriptions already cover the rest.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 09:30
@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e102726

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Drop details the status block, error messages, parameter schemas, or the context recovery footer already give the model at the moment they apply. Render Bash's background and timeout guidance from template variables instead of rewriting the description with string replacements that silently stop matching when the text changes.
The goal reminder injected on every active goal turn already carries the complete and blocked audits and the budget rule, and the plan mode reminder already carries the question, approval, and options rules. Keep only what those reminders do not: the plan structure, resuming a paused or blocked goal, and when to create a goal or set a budget.
@7Sageer 7Sageer changed the title chore(agent-core-v2): trim cron tool descriptions chore(agent-core-v2): trim built-in tool descriptions Oct 27, 2026
@7Sageer
7Sageer marked this pull request as ready for review October 27, 2026 11:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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 🔄 Running since 2026-10-28T04:23:35.067347Z e102726 Manual request
ℹ️ 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.

@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: b9c27f800d

ℹ️ 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".

Schedule a prompt to be enqueued later in this session, recurring or once. `cron` is 5-field cron in the user's local time (`0 9 * * *` = 9am local).

Uses standard 5-field cron in the user's local timezone: minute hour day-of-month month day-of-week. `0 9 * * *` means 9am local — no timezone conversion needed.
When the requested time is approximate, avoid minute 0 and 30 so fires from many users do not land at once: "around 9" → `57 8 * * *`, "hourly" → `7 * * * *`.

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 Disclose jitter for exact-time cron schedules

For users requesting an exact recurring time—or a one-shot at :00 or :30—this guidance only addresses approximate times, so the model can schedule 0 9 * * * as if it will fire at 9:00. Jitter remains enabled by default (noJitter: false): recurring fires can shift forward by up to 15 minutes, and affected one-shots can shift earlier by up to 90 seconds (cronService.ts:131-135, jitter.ts:10-13, 48-57, 69-84). The old description disclosed these offsets; retain a brief warning so users are not promised a time the schedule may miss.

AGENTS.md reference: AGENTS.md:L119-L121

Useful? React with 👍 / 👎.

# Conflicts:
#	packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts
@pkg-pr-new

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

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

commit: e102726

@7Hanrui

7Hanrui commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@codex review

@7Sageer

7Sageer commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

已由统一 PR #4521 收拢,目标分支为 release/2026-10-29;保留原分支与历史,不再单独合并此 PR。

@7Sageer 7Sageer closed this Oct 29, 2026
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