Repository navigation
feat(agent-core-v2): limit subagents to the configured model pool - #4418
Conversation
Agent and AgentSwarm no longer offer an implicit "primary" choice once [secondary_model] is configured: subagents only bind pool entries, and a pool with a single entry (or a lone default_model) hides the model parameter and pins every spawn. List the main model's alias in [secondary_model.models] to offer it explicitly. [secondary_model] force is removed. A lone default_model already pins every subagent, so a leftover force key is ignored with a config warning instead of failing session startup. Tower keeps its behavior: reviewers default to the tower's own model and an explicitly requested "primary" stays valid.
🦋 Changeset detectedLatest commit: e8bbab9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
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.
|
@codex review |
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 879b184865
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Stop letting the main agent run Agent and AgentSwarm subagents on its own model through an implicit `primary` choice when a subagent model pool is configured; add the main model's alias to `[secondary_model.models]` to offer it again. |
There was a problem hiding this comment.
State that the replacement no longer inherits caller settings
For users who selected model: "primary" to follow the caller's current model and thinking level, adding that model's alias to the pool does not restore the advertised behavior: pool binding uses only [secondary_model].default_effort, does not inherit the caller's thinking level, and will not follow later main-model switches. The changeset should name these losses rather than presenting the fixed pool alias as an equivalent replacement.
AGENTS.md reference: AGENTS.md:L115-L117
Useful? React with 👍 / 👎.
The v2 engine binds the [models] entry as configured, so max_context_size, capabilities and the other recipe keys under [secondary_model] never took effect. Remove them from the schema, warn when a config still sets them, and drop the node-sdk __secondary__ alias synthesis that only fed the removed v1 engine.
…sages The reserved primary pool key now only serves Tower spawn, and a lone default_model no longer pins Tower reviewers. Name the losses of the removed primary choice in its changeset.
Signed-off-by: 7Sageer <[email protected]>
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec93dfc277
ℹ️ 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".
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Remove `[secondary_model] force`, which is now ignored with a warning: a lone `default_model` still pins every subagent to that model. |
There was a problem hiding this comment.
Correct the claim that the default pins every subagent
When Tower users have force = true and a default_model, this claim is incorrect: workers still use the pool default, but reviewers now default to the current primary model (TowerSpawnTool, spawnTool.ts:223; see also docs/en/guides/tower.md:106). The release note should name this loss and note that reviewers can still be assigned a pool alias per spawn.
AGENTS.md reference: AGENTS.md:L115-L117
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8bbab96e4
ℹ️ 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".
| @@ -1 +1 @@ | |||
| Context forking: by default, each spawned subagent starts with zero context — brief it through the template. When every item builds on the current conversation, pass `fork: true` instead: each item-spawned subagent then starts with a snapshot of your completed history (inheriting your own agent type, tool set, and model), so the template only needs the task itself. A non-empty `resume_agent_ids` map is rejected with `fork`. If `subagent_type` is provided, it must match your own agent type; if `model` is provided, it must be your own model or `primary`. Different types and model overrides are rejected. Keep `fork` off for independent tasks — it copies the full history into every subagent. No newline at end of file | |||
| Context forking: pass `fork: true` so every item-spawned subagent starts with a snapshot of your completed conversation history, inheriting your current agent type, model, and tool set. No newline at end of file | |||
There was a problem hiding this comment.
Restore the zero-context guidance for independent swarm items
When subagent_fork is enabled, this prompt no longer says to use zero context by default and fork only when every item builds on the current conversation; it now simply tells the model to pass fork: true. AgentSwarm forwards that choice to each spawn, where forking copies the caller's conversation history, so unrelated items can each receive a full, irrelevant transcript and consume extra context and tokens. Restore the dependency criterion here and in the matching Agent prompt.
AGENTS.md reference: AGENTS.md:L119-L121
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8bbab96e4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| await config.set(domain, camelPatch[domain]); | ||
| const patch = camelPatch[domain]; | ||
| if (domain === 'secondaryModel' && patch === null) { | ||
| await config.replace(domain, null); |
There was a problem hiding this comment.
Make multi-domain config patches atomic
When a client sends secondary_model: null before another domain that fails core validation—for example, thinking: { enabled: "bad" }—this call persists the deletion before the later config.set throws. The endpoint then returns VALIDATION_FAILED, but the secondary-model configuration is already gone, so desktop/web clients that batch settings can lose data on a rejected request. Validate and persist the complete patch atomically, such as through replaceSections, rather than deleting domains one at a time.
AGENTS.md reference: AGENTS.md:L131-L133
Useful? React with 👍 / 👎.
| export const SecondaryModelConfigSchema = z.object({ | ||
| model: z.string().min(1).optional(), | ||
| defaultModel: z.string().min(1).optional(), | ||
| models: z.record(z.string(), z.string()).optional(), | ||
| force: z.boolean().optional(), | ||
| defaultEffort: z.string().optional(), |
There was a problem hiding this comment.
Preserve removed fields in the public SDK config type
Because KimiConfig and KimiConfigPatch are re-exported from the SDK root, replacing ModelAliasOverrideSchema.extend(...) with this narrower object removes force and all model-tuning properties from the public secondaryModel type. TypeScript SDK hosts that still construct patches such as { secondaryModel: { force: true } } or set one of those tuning fields will stop compiling on this patch release, even though the runtime migration is designed to load those settings and warn that they are ignored. Keep the old optional properties as deprecated public type fields while stripping them at the engine boundary, or treat the removal as an explicitly approved major change.
AGENTS.md reference: AGENTS.md:L63-L63
Useful? React with 👍 / 👎.
Port of upstream MoonshotAI#4418 (e3efbb9). Agent and AgentSwarm no longer offer an implicit "primary" choice once [secondary_model] is configured: subagents bind pool entries only, and a single-entry pool (or a lone default_model) hides the model parameter and pins every spawn. Tower keeps its own "primary" choice. [secondary_model] force is removed: a leftover force key is ignored with a config warning instead of failing session startup, and the never-effective model-tuning keys (max_context_size, capabilities and friends) drop out of the schema through the same warning path. node-sdk stops synthesizing the __secondary__ derived alias that only fed the removed v1 engine, and the TUI pickers stop filtering it. kap-server accepts secondary_model: null to clear the section. Fork adaptations made while applying the port: - provider.ts keeps the fork's mountProviderModelSelector helper; only the __secondary__ filtering was removed inside it. - kap-server config route keeps the fork's applied/failedDomain persistence-split reporting, merged with the new null-clearing branch. - tool.test.ts keeps bun:test style (mock instead of vi.fn) and the fork-local default-WebSearch expectation in one assertion. - tools.md keeps the fork-parameter documentation (the subagent_fork flag still gates it) with the "primary" wording removed from pool text.
The behaviour of MoonshotAI#4421 has been in the requester since 94397aa, but its suite still asserted only that the lowered system message lost its `tools` field, which a message kept in place would also satisfy. Assert instead that no system message survives and the history keeps its length, and rename the case after what it protects. Also settle ten ledger rows that were already implemented here: MoonshotAI#3733, MoonshotAI#4413, MoonshotAI#4418, MoonshotAI#4421, MoonshotAI#4435, MoonshotAI#4460, MoonshotAI#4465, MoonshotAI#4516, MoonshotAI#4523, MoonshotAI#4532 and the MoonshotAI#4558 test calibration, each with a probe over the suite that pins it. Two rows carried a probe without a test-name selector (MoonshotAI#4557, MoonshotAI#4558), which aborted `--verify` for every other row; MoonshotAI#4557 is a changelog sync and now carries a manual probe.
Ports the docs half of upstream MoonshotAI/kimi-code 8b6a003 (MoonshotAI#4673): the 2.5.0 section from the upstream release notes lands in both changelogs, en and zh, word for word. Every feature the section names is in this tree - busy /model and /effort (MoonshotAI#4621), merged project-level skills (MoonshotAI#4520), remote sessions in SSH, Docker and custom-command environments (MoonshotAI#4062), [workspace] require_trust (MoonshotAI#4517), web search off by default (MoonshotAI#4516), and the subagent model pool (MoonshotAI#4418) - so the notes describe what the fork actually does. Deliberately not touched: apps/kimi-code/CHANGELOG.md still tops out at 2.4.1 and package.json still says 2.4.1. That file is generated by `changeset version`, this tree has 377 pending changesets, and AGENTS.md forbids running version or publish from this repository, so the entry is written on the docs side only. Whoever next cuts a release here should reconcile this section with what changeset version generates rather than re-deriving it by hand.
Requirement or Bug
配置了
[secondary_model]之后,Agent / AgentSwarm 会把主模型作为隐式的primary选项一起提供给主 agent,子 agent 可能悄悄跑回主模型,和"副模型用来省钱"的预期不符;改为只提供模型池里显式列出的模型,并顺带删掉因此变得多余的force。同一节里还有 9 个模型调参字段(
max_context_size、capabilities等):v2 引擎按[models]条目原样绑定,从不读取它们,写了也不生效;一并移除并在加载时提示。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
模型选择规则(Agent / AgentSwarm):
model参数何时出现:Tower 保留
primary选择,移除force例外(接受实验性功能的这项行为变化):force的去留:[secondary_model]模型调参字段:其他:
model只接受调用方自己的别名,不再接受primary。model_source去掉forced;primary_override只剩 Tower 会产生。force;PRIMARY_SUBAGENT_MODEL_CHOICE导出保留(Tower 仍在用)。config-manifest.toml;更新中英文 config-files / tools / tower 文档与内置 update-config skill。/api/v1/config新增secondary_model: null:仅该域走IConfigService.replace删除整个配置节,对象仍按 merge 更新;用于 desktop/web 的“跟随默认模型”设置。Behavior Changes and Affected Users
model: "primary"Invalid model "primary". Available models: …[secondary_model.models];区别是不继承 thinking level、不跟随/model切换default_model(/secondary-model写的就是这个)时的model参数<default>或primarydefault_model/secondary-model配置过的用户[secondary_model.models]表model参数(该项 +primary)force = true+default_modeldefault_modeldefault_model);Tower reviewer 回到 Tower 自身模型;加载时出警告force让 reviewer 省钱的用户force = true但没有default_modelforce = true+[secondary_model.models]表force时的model参数primaryforce行model的报错文案no [secondary_model.models] pool … (pass "primary" or omit …)no [secondary_model] pool … (omit the model parameter)model: "primary"FORK_WITH_MODEL_UNAVAILABLE)[secondary_model]里的max_context_size等 9 个调参字段[models.<alias>]条目上KIMI_SECONDARY_MODEL/KIMI_SECONDARY_EFFORTsubagent事件model_sourceforcedforcedPOST /api/v1/config的secondary_model: null[secondary_model]节,之后派生的 subagent 继承调用方模型与 thinking levelPrompt / 工具描述文本改动(逐句):
- primary (= <alias>): your current model and thinking level与Pool entries don't inherit your thinking level.两行,AgentSwarm 的单行摘要删除primary (…)。影响所有配置了 ≥2 项模型池的会话。之前它向模型宣告可以升级到主模型;现在由resolveSubagentBinding拒绝primary来约束。agent.ts/agent-swarm.ts的model参数描述:删除or "primary" for your current model and thinking level。人群同上。agent.ts/agent-fork.md的 fork 快照说明:收敛为一句“从已完成对话的快照开始,继承当前类型、模型和工具集”,不再建议用 fork 替代重新 briefing。仅影响开启 fork 实验 flag 的会话;快照与继承仍由planSpawn/spawn实现。agent-swarm.ts/agent-swarm-fork.md的 fork 快照说明:同样只说明每个 item 子 agent 继承当前类型、模型和工具集,不展开工具列表。人群同上。forkIncompatibility与 swarm resume 检查保留。forkIncompatibility仍拒绝不同类型。forkIncompatibility现在只接受自己的模型别名,不再接受primary。spawn.md:删除If [secondary_model].force = true, the forced model is mandatory and every explicit choice, including primary, is rejected.。只影响 Tower 会话;该约束随force一起移除。update-configskill:[secondary_model]说明去掉force,改为说明子 agent 只用模型池、单独default_model即固定、force已废弃被忽略。影响调用该 skill 的会话;避免它再帮用户写出force。受影响模块与测试覆盖:
session/subagent/configSection.ts:test/app/config/config.test.ts(模型池默认、显式别名、无模型池继承、primary被拒、单项模型池、legacymodel键、force被忽略且出警告、报错文案),test/session/subagent/subagentModelsValidation.test.ts(force不再导致启动失败;单独default_model的default_effort校验),test/session/subagent/spawn.test.ts。test/tool/tool.test.ts(≥2 项才出现model参数且描述无primary;单项模型池 / 单独default_model隐藏参数;primary被拒;主模型写进模型池时可选且不继承 thinking;fork 接受自身别名、拒绝primary;ReadMediaFile / select_tools 在 fork 开关两种状态下都只描述池内能力;无池继承调用方能力;Agent / AgentSwarm fork 提示保持一句继承说明),test/features/swarm/swarm.test.ts(主模型显式写入模型池时可用——即退路)。test/features/tower/tools/spawnTool.test.ts(reviewer 默认仍用 Tower 模型——钉住未变人群的旧行为;显式primary仍可用;越界别名报错仍列出primary;单独default_model时出现model参数)。[secondary_model]调参字段:test/app/config/config.test.ts(字段被忽略、出警告、config.set后仍保留在磁盘上),apps/kimi-code/test/tui/commands/secondary-model.test.ts(去掉__secondary__用例)。packages/agent-core-v2/docs/config-manifest.toml删除force及 9 个调参字段(消费方:code-app desktop/web、VS Code 扩展的配置编辑);旧版本写出的含force的 config.toml 仍能加载,仅出警告。packages/node-sdk/src/index.ts未改动:SECONDARY_DERIVED_MODEL_ALIAS导出保留并标为@deprecated,避免 SDK 破坏性变更;node-sdk 的SecondaryModelConfig类型去掉这些字段。packages/kap-server/src/routes/config.ts仅对secondaryModel: null调用replace;packages/kap-server/test/config.test.ts验证整节删除、其他配置域保留,以及 reload 后仍然生效。验证(本次增量):
warn-secondary-model-tuning-keys。现有中英文用户文档已说明模型能力约束,本次无需额外扩展文档。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.