feat(agent-core-v2): add named subagent model slots for autonomous model selection - #2264
feat(agent-core-v2): add named subagent model slots for autonomous model selection#2264Yiksing wants to merge 1 commit into
Conversation
…del selection Add a [subagent_models.<slot>] config section: each named slot carries a base model, description, recommended_for tags, an optional default marker, and optional model patch fields. The Agent and AgentSwarm tools expose the slot names dynamically in their model parameter enum and describe every slot to the calling model, so the main agent can pick a subagent model by task fit and cost. Explicit tool-call choice > profile model_preference > default slot > first slot; the legacy [secondary_model] single slot remains the fallback when no named slots exist, and resumed subagents keep their recorded model. Patched slots synthesize runtime-only derived model entries (__sm__<slot>) through a derived-phase config overlay that also covers Memory-layer recipes. Derived entries never persist to config.toml (identity provenance marks plus a recipe-echo strip guard), never surface in /api/v1/models, and never override a user-defined [models.__sm__*] entry — collisions warn once per session, degrade tool metadata gracefully, and fail closed at spawn. Gated behind the existing secondary-model experimental flag.
🦋 Changeset detectedLatest commit: 880c0fd 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 880c0fd432
ℹ️ 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".
| ): AgentFileDefinition['modelPreference'] { | ||
| if (value === undefined || value === null) return undefined; | ||
| if (value === 'primary' || value === 'secondary') return value; | ||
| if (typeof value === 'string' && value.trim().length > 0) return value.trim(); |
There was a problem hiding this comment.
Reject model preferences that cannot name a slot
When an agent file uses a value such as model_preference: fast-model or one containing internal whitespace, this parser now accepts it even though [subagent_models] only permits names matching ^[a-zA-Z][a-zA-Z0-9_]*$. If Agent or AgentSwarm later spawns that profile without an explicit model, resolveSubagentBinding always rejects the impossible preference as an unknown slot instead of the invalid agent file being skipped (or rejected when passed explicitly). Validate preferences against the slot-name grammar while retaining the supported primary and legacy secondary values.
Useful? React with 👍 / 👎.
Related Issue
Resolve #2250
Problem
See linked issue. In short: with the experimental secondary-model feature, spawned subagents can bind to a single
[secondary_model]slot, but one alternate slot is not enough — routine search/formatting wants a cheap fast model, architecture review wants the highest-quality one, and the main agent has no information to choose by task.What changed
[subagent_models.<slot>]config section (agent-core-v2,session/subagentdomain): each named slot carries a basemodel, adescription,recommended_fortags, an optionaldefaultmarker, and optional per-slot model patch fields (same shape as[models.*.overrides]). Slot names are validated (^[a-zA-Z][a-zA-Z0-9_]*$,primaryand__-prefixed names rejected).AgentandAgentSwarmexpose the slot names dynamically as themodelparameter enum (plusprimary), and their descriptions list every slot's model, description, and recommended uses, so the calling model can choose per task. Selection priority: explicit tool-callmodel> profilemodel_preference> the slot markeddefault> the first slot. With no named slots the legacy[secondary_model]keeps working as a singlesecondaryslot; with neither, subagents inherit the caller's model. Resumed subagents always keep their recorded model.__sm__<slot>entries through a derived-phase config overlay. They never persist toconfig.toml(runtime-only provenance marks plus a recipe-echo strip guard), never surface inGET /api/v1/models(mirroring the__secondary__hiding from feat(kap-server): accept secondary_model in the config API #2228), and never override a user-defined[models.__sm__*]entry — a collision warns once per session, tool metadata degrades gracefully, and spawning on that slot fails closed.ConfigServiceoverlays now carry a phase (environment/derived) so derived overlays always run after env bindings and Memory-layer input; overlay failures land in diagnostics without breaking other domains.KIMI_CODE_EXPERIMENTAL_SECONDARY_MODELflag; behavior with the flag off is unchanged, and the interactive TUI is unaffected (same surface support as the current secondary-model experiment:kimi weband experimentalkimi -p).docs/en+docs/zh: config-files, agents, tools) alongside the config manifest.Checklist
gen-changesetsskill, or this PR needs no changeset. (Apatchchangeset is included, worded to note the experimental flag and effective surfaces — following the precedent of feat: support a configurable secondary model for subagents #2064, which introduced the secondary-model experiment with a patch entry.)gen-docsskill, or this PR needs no doc update. (Bilingual docs updated in this PR.)