Repository navigation
refactor: deliver subagent model choices via system reminder - #5190
Merged
Merged
Conversation
Keep the optional `model` parameter static on `Agent`, `AgentSwarm`, and `TowerSpawn` instead of stripping it or appending available model lists to top-level tool descriptions. Inject available subagent models via `<system-reminder>` for bound profiles with active subagent tools (deduplicated via `origin.disclosure` and updated on `setModel`, `[secondary_model]` reloads, and compaction), and explicitly reject invalid or resume-time `model` arguments.
🦋 Changeset detectedLatest commit: 37611da The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
- Extract SubagentTool.parseSubagentInput so resolveExecution and execution share argument validation without triggering jscpd clones. - Add prepareForReload and notifyAllChanges on IAgentChangeNotifierService so kap-server and node-sdk session reload flows delegate change-notifier lifecycle handling to the service. - Include the baseline subagent_models <system-reminder> marker alongside date_change in klient's invalid-input-matrix helper while keeping interruption reminder assertions intact.
Skip the subagent model reminder without a [secondary_model] pool, send a one-time withdrawal notice when the pool is removed mid-session, and keep rejecting any explicit model when no pool is configured. Also simplify the reminder disclosure typing, Agent resume parsing, and reload failure recovery.
sailist
approved these changes
Nov 20, 2026
6 tasks done
Merged
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 25, 2026
Remove the experimental `fork` parameter from the Agent and AgentSwarm tools (MoonshotAI#5254): the subagent_fork flag and its /experiments entry, the schema parameters and flag-gated parameter sets, the lifecycle fork spawn path and its reminder notice, the `fork` plan field, the subagent_created telemetry field, the fork-only backend compatibility rule, and the pending changeset that announced the feature. Docs drop the env var and the parameter text in both locales; six changesets describe the removal for the CLI, engine, desktop, migration, SDK and VS Code packages. Fork adaptations: the external-backend parameter, the subagent depth labels and the fork's DI shapes stay. The unrelated model-with-resume-only rejection that the merge resolution had carried from the still-pending MoonshotAI#5190 is dropped, so the fork keeps ignoring `model` when resuming without items. The port also fixes two defects in that resolution which the tests exposed: planSpawn reads the caller profile through IAgentProfileService, and spawn passes the computed labels so the subagentDepth label survives. Verified: agent-core-v2 affected files 285 pass / 2 fail, both failures pre-existing at 2fa1821 (tool.test registered-user-tools wire snapshot, forkParity TaskStop timeout); swarm 32, sessionSwarm 50, spawn 22, experiments 13, node-sdk flags 1, node-sdk prompt events 18, kap-server meta 10; typecheck clean for agent-core-v2, kap-server, node-sdk and kimi-code; check:no-comments and the locale gates green.
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 25, 2026
Port upstream MoonshotAI#5190 (1ef139e). The available [secondary_model] choices are announced through a scoped reminder service instead of being rendered into the Agent / AgentSwarm / TowerSpawn tool descriptions, so tool definitions stay static when the pool changes mid-session. Resume-time and no-pool model arguments are rejected explicitly. Fork adaptations: - the reminder service injects IAgentProfileService (the fork's data() owner) instead of upstream IAgentLoopService; - the Agent tool keeps the fork-only subagent backend parameter handling while parseSubagentInput owns the shared resume/model validation; - reload paths keep the fork's reloadWorkspaceCatalogs and refreshPluginSessionStarts methods behind prepareForReload/notifyAllChanges; - reminder tests await restorePersisted() because the fork harness does not auto-restore the reminder actor. Verification: - agent-core-v2 typecheck passes; bun scripts/check-no-comments.mjs OK. - bun test --isolate on tool, changeNotifier, apply-profile, binding, swarm and spawnTool: 315 pass, 1 fail (pre-existing loadable-tools snapshot mismatch at HEAD after ce35274, unrelated); changeNotifier alone 44 pass. - kap-server sessions and node-sdk reload suites resolve @moonshot-ai/agent-core-v2 through the root node_modules junction to the main checkout, so they see the old notifier interface; kap-server typecheck reports the same two missing members. Re-run after integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
会话第一次请求时,
Agent、AgentSwarm、TowerSpawn的工具定义会被冻结进会话快照(tool_select.initialized),之后每次请求都复用这份快照,所以 Prompt Cache 不受影响。但这三个工具的model参数和Available models (pass via model): ...描述是按[secondary_model]实时生成的:会话中途改了模型池(/secondary-model、改配置文件、:reload),快照里的列表就过时了,模型还会收到一条Tool "Agent" has an update, but the update is not applied in this session提醒,要求继续用旧版本;而运行期的resolveSubagentBinding已经按新配置校验和派发。结果是模型拿着旧列表选模型,选到已删除的别名就报错重试,新增的模型也看不到。ChangeNotifier里比较模型池增删的补丁只在 profile 名单变化或 reload 时运行,覆盖不全。本 PR 让这三个工具的定义保持静态,改用
<system-reminder>把当前的模型池告诉模型:模型池一变,下一轮就能看到,前缀缓存也不受影响。同时把resume时被静默忽略的model参数改成显式报错。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
把工具的静态定义(
parameters、description)和运行期的模型池状态拆开。三个派生工具始终带一个可选的model: string参数,描述里不再拼模型列表;新增的 Agent 作用域服务AgentSubagentModelsReminderService在每次请求前比较"当前模型池"和"历史里最后一次告诉模型的内容"(origin.disclosure),有变化才注入一条<system-reminder>。没配[secondary_model]的会话不发任何提醒,行为和 main 一致;只有模型池在会话中途被删掉时,才发一次"列表已撤回"的提醒。结构图
flowchart LR Config["IConfigService<br/>([secondary_model])"] --> Reminder["AgentSubagentModelsReminderService"] Gate["受绑定 profile +<br/>激活了 Agent / AgentSwarm / TowerSpawn"] --> Reminder History["上下文历史<br/>(最后一次 disclosure)"] --> Reminder Reminder -->|"有变化才注入"| SR["<system-reminder><br/>subagent_models"] Tools["静态工具定义<br/>(Agent / AgentSwarm / TowerSpawn)"] -->|"校验 resume 与 model"| Binding["resolveSubagentBinding"] Config --> Binding提醒追加在当前轮消息的末尾,不改动
tools[]和已有历史,所以前缀缓存不受影响。每次都发完整列表而不是增删 diff,压缩丢掉旧提醒之后,下一轮也能重新给出一份完整的当前列表。关键决策
IAgentReminderService注册的subagent_models提醒,用origin.disclosure去重ChangeNotifier发增删 diff/reload[secondary_model]由bindSubagentModel每次实时读取,改完立刻生效,只有即时告知才不会和运行期不一致model都报错(含调用方自己的别名)/model切换都要重发resume时传model阅读指南
packages/agent-core-v2/src/agent/subagentModelsReminder/subagentModelsReminderService.ts:提醒的准入条件、disclosure 的构造(没配池时为空)、去重,以及首次 / 变化 / 撤回三种文本。packages/agent-core-v2/src/agent/tools/agent/agentTool.ts、features/swarm/tools/agent-swarm/agentSwarmTool.ts、features/tower/tools/spawn/spawnTool.ts:三个工具静态化后的定义,以及resume(或只有resume_agent_ids)时对model的拒绝。packages/agent-core-v2/src/session/subagent/configSection.ts:删掉了按配置裁剪 schema 和拼描述的辅助函数;bindSubagentModel的行为与 main 相同。packages/agent-core-v2/src/agent/changeNotifier/changeNotifierService.ts:删掉模型池比较;新增prepareForReload()/notifyAllChanges(),把 kap-server 和 SDK 里各写一遍的 reload 通知流程收进服务。快照里的modelPool字段类型保留,用于旧会话回放。agent.ts、agent-swarm.ts、spawn.ts、spawn.md是参数描述措辞,sessions.ts、sdk-rpc-client-v2.ts是 reload 调用的替换,其余是测试和中英文文档,可以略读。具体逻辑变化
Behavior Changes and Affected Users
Agent/AgentSwarm/TowerSpawn的 JSON schema 是否有modelAgent/AgentSwarm去掉model;没配池时TowerSpawn去掉modelmodel: stringmodel时的绑定结果不变Available models (pass via model): ...<system-reminder>注入给激活了派生工具的受绑定 profile[secondary_model]的会话,主 agent 和能派生的自定义 agentsubagent_models提醒explore、coder这类没有派生工具的 profile 不注入[secondary_model]的会话[secondary_model]后模型看到的内容Tool "Agent" has an update, but the update is not applied in this session提醒/secondary-model、改配置文件或:reload修改模型池的会话tool_update_pending提醒;之后模型列表以subagent_models提醒为准modelAgent/AgentSwarm/TowerSpawn的 schema 里没有model,被参数校验拒绝(must NOT have additional property 'model')bindSubagentModel拒绝:Invalid model "<x>": no [secondary_model] pool is configured, so subagents inherit the caller's model (omit the model parameter).model的调用modelAgent/AgentSwarm的 schema 里没有model,被参数校验拒绝Invalid model "<x>". Available models: <alias>.model的调用Agent同时传resume和model;AgentSwarm只传resume_agent_ids又传modelmodel被静默忽略RESUME_WITH_MODEL_UNAVAILABLE/SWARM_RESUME_ONLY_WITH_MODEL_UNAVAILABLE;AgentSwarm同时有items时仍可传model,只作用于新建的 subagentmodel的调用model重试即可。这是收紧,请维护者确认subagents_change提醒The available subagent profiles and models changed:,含Models added/removed、Model descriptions updated、Default model changed等行The available subagent profiles changed:,只报 profile 增删;模型池变化交给subagent_modelsmodelPool字段类型保留,旧会话可正常回放。wire-manifest.d.ts、state-manifest.d.ts无变化:reload/ SDKreload失败的会话提示词文本的变化(每句一行):
Agent的model参数描述one of the aliases listed under "Available models" in this tool description ... Ignored when resumingchosen from the available subagent models announced in <system-reminder> ... Cannot be set when resumingresume时能否传;现在指向提醒,resume由工具显式报错兜底AgentSwarm的model参数描述Resumed subagents always keep their own modelcannot be set when resuming without itemsSWARM_RESUME_ONLY_WITH_MODEL_UNAVAILABLE兜底TowerSpawn的model参数描述one of the aliases listed under "Available models" in this tool descriptionchosen from the available subagent models announced in <system-reminder>KIMI_CODE_EXPERIMENTAL_TOWER的会话spawn.md的 Model selection 段The allowed choices are the configured secondary-pool aliases ...;The model parameter is available whenever a pool is configured.resolveSubagentBinding校验受影响模块与测试覆盖
@moonshot-ai/agent-core-v2:subagentModelsReminder、session/subagent、agentTool、agentSwarmTool、tower/spawn、changeNotifier@moonshot-ai/kap-server:/api/v1/sessions/:id:reload改用prepareForReload/notifyAllChanges@moonshot-ai/kimi-code-sdk:reloadRPC 同上docs/{en,zh}:reference/tools.md、configuration/config-files.md、guides/tower.md对应测试:
model、描述保持静态、热更新模型池不改变tools[]:test/tool/tool.test.ts、test/features/swarm/swarm.test.ts、test/features/tower/tools/spawnTool.test.tstest/tool/tool.test.tsmodel(含调用方别名)都拒绝:test/tool/tool.test.ts、test/features/tower/tools/spawnTool.test.ts、test/app/config/config.test.tspackages/klient/test/e2e/invalid-input-matrix.test.ts(与 main 相同,无需过滤)resume+model报错;AgentSwarm只有resume_agent_ids+model报错,items+resume_agent_ids+model保持旧行为:test/tool/tool.test.ts、test/features/swarm/swarm.test.tsChangeNotifier只跟进 profile 增删、prepareForReload失败恢复、:reload集成:test/agent/changeNotifier/changeNotifier.test.ts、packages/kap-server/test/sessions.test.ts验证结论
在 Linux(Node.js 24)上跑了
pnpm lint、agent-core-v2 / kap-server / node-sdk 的类型检查,以及受影响的测试文件,全部通过。未运行三个包的全量测试、桌面端和 GUI 测试(本 PR 不涉及渲染端和 CLI 交互层代码)。验证命令与结果
pnpm lint:通过(check-comments、oxlint --type-aware --deny-warnings、check-import-boundaries、guards、ratchet、instructions)pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit:通过pnpm exec tsc -p packages/kap-server/tsconfig.json --noEmit:通过pnpm exec tsc -p packages/node-sdk/tsconfig.json --noEmit:通过pnpm exec vitest run packages/agent-core-v2/test/tool/tool.test.ts packages/agent-core-v2/test/features/tower/tools/spawnTool.test.ts packages/agent-core-v2/test/features/swarm/swarm.test.ts packages/agent-core-v2/test/session/subagent/spawn.test.ts packages/agent-core-v2/test/app/config/config.test.ts packages/agent-core-v2/test/agent/changeNotifier/changeNotifier.test.ts packages/agent-core-v2/test/agent/profile packages/kap-server/test/sessions.test.ts:13 个文件 / 766 个用例通过pnpm exec vitest run packages/klient/test/e2e/invalid-input-matrix.test.ts:23 个用例通过Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.