Skip to content

add per-role and per-invocation model selection for subagents#592

Open
AGSQ11 wants to merge 11 commits into
MoonshotAI:mainfrom
AGSQ11:main
Open

add per-role and per-invocation model selection for subagents#592
AGSQ11 wants to merge 11 commits into
MoonshotAI:mainfrom
AGSQ11:main

Conversation

@AGSQ11

@AGSQ11 AGSQ11 commented Jun 9, 2026

Copy link
Copy Markdown

Related Issue

No prior issue — this is a self-contained feature enabling multi-model subagent workflows.

Problem

All subagents (coder, explore, plan) inherit the parent agent's model. There is no way to assign different models to different subagent roles, or to override the model for a specific subagent invocation. Users who want to use a cheaper/faster model for exploration and a stronger model for coding, or who instruct the agent to use a specific model for a one-off task, have no mechanism to do so.

What changed

Adds a [subagent_models] config.toml section and an model parameter on the Agent tool. Model resolution follows a clear 3-tier priority:

  1. Per-invocationmodel parameter passed in the Agent tool call (e.g. Agent(model="glm-5-turbo", ...))
  2. Per-role config[subagent_models] in config.toml maps profile names to model aliases
  3. Inherit from parent — the existing default behaviour

Files changed:

File Change
config/schema.ts subagentModels: Record<string, string> added to KimiConfigSchema and KimiConfigPatchSchema
config/toml.ts TOML read/write for [subagent_models] section
tools/builtin/collaboration/agent.ts Optional model string parameter added to AgentToolInputSchema, forwarded to spawn options
tools/builtin/collaboration/agent.md "Model selection" section documenting the new behaviour
session/subagent-host.ts model?: string added to SpawnSubagentOptions; configureChild() resolves effective model with the 3-tier priority
test/config/configs.test.ts 4 tests: parse, round-trip, merge patch, empty config

Example config.toml:

[subagent_models]
coder = "kimi-k2.5"
explore = "kimi-k2-thinking"

Example per-invocation usage (LLM-generated tool call):

Agent(model="kimi-k2.5", subagent_type="coder", prompt="optimize the hot path in render.ts")

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.

AGSQ11 and others added 2 commits June 9, 2026 13:23
… subagents

Add a [subagent_models] config.toml section that maps subagent profile
names (coder, explore, plan) to model aliases, so different subagent
roles can use different LLM models. Also add a 'model' parameter to the
Agent tool so the parent agent can override the model on a per-call
basis.

Model resolution priority:
  1. Per-invocation 'model' override (Agent tool parameter)
  2. Role-based [subagent_models] config mapping
  3. Parent model (default inheritance)

Changes:
- schema: add subagentModels field to KimiConfigSchema + patch schema
- toml: add transform/serialize for subagent_models section
- agent tool: add optional 'model' string parameter to input schema
- subagent-host: wire model resolution in configureChild()
- agent.md: document model selection behaviour
- tests: parse, round-trip, merge, and empty config coverage
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e293fbe

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/kosong Patch
@moonshot-ai/acp-adapter Patch
@moonshot-ai/migration-legacy 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

@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: 0c78ee58f3

ℹ️ 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 thread packages/agent-core/src/session/subagent-host.ts Outdated
AGSQ11 and others added 8 commits June 9, 2026 14:36
retry() was resetting the child's model to parent.config.modelAlias,
losing any [subagent_models] config that was applied during the initial
spawn. Now retry() preserves the child's existing model since it is an
automatic retry of the same agent instance.

resume() now re-resolves the model using [subagent_models] config so
that role-based model settings survive across resume boundaries.
…l output

Thread the effective model alias through the subagent.spawned event so
that the TUI can render it alongside the agent description. Also
refactors model resolution into a single resolveSubagentModel() helper
used consistently across spawn(), resume(), and retry() paths.
…s support

When a subagent is configured with a different model from its parent,
check the target model's capabilities. If the model does not support
thinking/reasoning, reset thinkingLevel to 'off' instead of blindly
inheriting the parent's level. This prevents API errors like:

  Model grok-build-0.1 does not support parameter reasoningEffort.

The check is best-effort: if provider resolution fails, we fall back to
the parent's thinking level and let the first request fail with the
usual configuration error.
Add  section to config-files.md in both English and
Chinese, explaining the 3-tier model resolution priority. Update the
Agent tool description in tools.md to mention the optional
parameter for per-invocation overrides.
…ot be resolved

When configureChild() cannot resolve a subagent model's capabilities
(catch block), default thinkingLevel to 'off' instead of inheriting the
parent's level. This prevents reasoningEffort API errors on models that
do not support thinking parameters.
When thinking is off, the Anthropic provider previously sent
thinking: { type: 'disabled' } to the API. Some Anthropic-compatible
backends (e.g. grok) reject any thinking parameter, including disabled.

Now withThinking('off') deletes the thinking key from generation kwargs
entirely, so the parameter is omitted from the request body.

Also in configureChild: when a subagent uses a different model from its
parent, default thinkingLevel to 'off' to avoid sending reasoning params
to models that don't support them.
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