Skip to content

feat: support a configurable secondary model for subagents#2064

Open
7Sageer wants to merge 16 commits into
MoonshotAI:mainfrom
7Sageer:feat-subagent-k27
Open

feat: support a configurable secondary model for subagents#2064
7Sageer wants to merge 16 commits into
MoonshotAI:mainfrom
7Sageer:feat-subagent-k27

Conversation

@7Sageer

@7Sageer 7Sageer commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked GitHub issue. This PR addresses the secondary-model behavior identified during design review.

Problem

Subagents currently inherit the caller model, so users cannot route routine delegated work to a separately configured model while keeping the primary model available for quality-sensitive tasks. A misconfigured secondary alias should also be rejected before this feature allocates an Agent, rather than introducing a persisted or live ghost Agent.

What changed

  • Add [secondary_model] model and effort configuration, with KIMI_SECONDARY_MODEL and KIMI_SECONDARY_EFFORT environment overrides.
  • Let Agent and AgentSwarm choose the secondary or primary model for new spawns.
  • Add model_preference: primary | secondary to Agent files and apply this precedence: explicit tool argument, target profile preference, configured secondary-model default, then caller-model inheritance.
  • Keep resumed subagents on the model recorded in their own wire journal.
  • Validate the configured secondary model when a session starts and surface advisory model or effort warnings through the existing session-warnings API.
  • Resolve a selected model alias before calling the Agent lifecycle from both spawn paths, so invalid aliases fail without allocating an Agent. The existing lifecycle and onDidCreate ordering remain unchanged.
  • Add configuration, warning, spawn-path, and regression coverage, and update the mirrored English and Chinese documentation.

Verification

  • agent-core-v2 affected suites: 10 files, 268 tests.
  • kap-server affected suites: 2 files, 114 tests.
  • TypeScript checks passed for both packages.
  • Agent-core domain lint passed across 925 files.
  • git diff --check passed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5a58ff1

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

@7Sageer
7Sageer force-pushed the feat-subagent-k27 branch from 2dc8bf8 to d2ce676 Compare July 22, 2026 15:02
@7Sageer
7Sageer marked this pull request as ready for review July 23, 2026 06:17
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026

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

commit: 5a58ff1

@7Sageer 7Sageer closed this Jul 23, 2026
@7Sageer 7Sageer reopened this Jul 23, 2026
7Sageer and others added 16 commits July 23, 2026 22:54
…dary_model]

The secondary model becomes a model-domain concept next to default_model so
future consumers beyond subagents can share it: [secondary_model] model /
effort in config.toml, KIMI_SECONDARY_MODEL / KIMI_SECONDARY_EFFORT env
overrides, and the Agent / AgentSwarm per-spawn choice renamed from
"subagent" to "secondary".
…aces

State that [secondary_model], its env overrides, the Agent/AgentSwarm
model parameter, and SYSTEM.md take effect only under kimi web and
experimental kimi -p (the TUI ignores them), and that --agent /
--agent-file are available only under experimental kimi -p. Also drop
the SYSTEM.md claim of parity with --agent/--agent-file, which was
inaccurate: SYSTEM.md is an agent-core-v2 app-domain feature and also
applies under kimi web, while the flags are gated at the CLI.
- Drop the "cheaper" claim from the Agent/AgentSwarm model parameter
  descriptions and the advertised model list — the secondary model is
  not necessarily the cheaper one.
- Downgrade the changeset to patch, note the kimi web / experimental
  kimi -p effective surface, and tighten the wording.
- Remove the onWillRestore stub fields from two lifecycle stubs; they
  belong to upcoming lifecycle work, not to this change.
The model catalog's not-configured throw now carries details.model, and
wrapSubagentModelError only decorates errors whose details.model matches
the bound model. Malformed [models.*] entries and unrelated config.invalid
failures during agent creation pass through untouched instead of being
misattributed to an invalid secondary-model alias.
Signed-off-by: 7Sageer <12210216@mail.sustech.edu.cn>
Signed-off-by: 7Sageer <12210216@mail.sustech.edu.cn>
Individual agents can override this via the new `model_preference` field in their agent file.

Signed-off-by: 7Sageer <sag77r@hotmail.com>
The recipe is now `model` plus the flattened ModelOverride field set.
With any patch field set, a config overlay synthesizes a derived
registry entry (base copy, patch merged into overrides, aliases
dropped) so subagent spawning rides the standard effectiveModelConfig
merge; with none, subagents bind the pointed entry directly.
`default_effort` replaces `effort` (KIMI_SECONDARY_EFFORT rebinds)
and doubles as the explicit subagent thinking; unset, thinking
resolves naturally instead of inheriting the caller. The overlay
strips the derived entry (and any defaultModel pointer to it) from
writes, and the kap-server GET /models route hides it from pickers.
rebuildEffective only committed the caller-named domains, so a
ConfigEffectiveOverlay or section env binding that rewrote a sibling
domain (setting [secondary_model] synthesizes a derived models entry;
removing the recipe retracts it) left consumers of the models section
stale. Widen the commit candidates with every domain the recompute
actually changed; commit() deepEqual-guards each candidate, so the
widening costs nothing.
@7Sageer
7Sageer force-pushed the feat-subagent-k27 branch from 28f6027 to 5a58ff1 Compare July 23, 2026 15:03
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.

1 participant