add per-role and per-invocation model selection for subagents#592
Open
AGSQ11 wants to merge 11 commits into
Open
add per-role and per-invocation model selection for subagents#592AGSQ11 wants to merge 11 commits into
AGSQ11 wants to merge 11 commits into
Conversation
… 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 detectedLatest commit: e293fbe 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 |
There was a problem hiding this comment.
💡 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".
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.
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.
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 anmodelparameter on the Agent tool. Model resolution follows a clear 3-tier priority:modelparameter passed in the Agent tool call (e.g.Agent(model="glm-5-turbo", ...))[subagent_models]in config.toml maps profile names to model aliasesFiles changed:
config/schema.tssubagentModels: Record<string, string>added toKimiConfigSchemaandKimiConfigPatchSchemaconfig/toml.ts[subagent_models]sectiontools/builtin/collaboration/agent.tsmodelstring parameter added toAgentToolInputSchema, forwarded to spawn optionstools/builtin/collaboration/agent.mdsession/subagent-host.tsmodel?: stringadded toSpawnSubagentOptions;configureChild()resolves effective model with the 3-tier prioritytest/config/configs.test.tsExample config.toml:
Example per-invocation usage (LLM-generated tool call):
Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.