Skip to content

feat(agent-core): allow subagents to select configured models#1841

Open
AidenNovak wants to merge 5 commits into
MoonshotAI:mainfrom
AidenNovak:agent/subagent-model-selection
Open

feat(agent-core): allow subagents to select configured models#1841
AidenNovak wants to merge 5 commits into
MoonshotAI:mainfrom
AidenNovak:agent/subagent-model-selection

Conversation

@AidenNovak

Copy link
Copy Markdown

Related Issue

No linked issue. The limitation and motivation are described below.

Problem

Delegated Agent and AgentSwarm runs currently inherit the caller's active model. Users can already configure multiple model aliases in config.toml, but the main agent cannot discover those aliases or select a different configured model for delegated work.

This prevents useful routing patterns such as keeping the main conversation on one model while assigning exploration, coding, or parallel swarm tasks to another model.

What changed

  • Add the opt-in subagent-model-selection experiment, disabled by default and available through KIMI_CODE_EXPERIMENTAL_SUBAGENT_MODEL_SELECTION=1.
  • Expose a bounded, sanitized directory of resolvable configured model aliases to Agent and AgentSwarm when the experiment is enabled.
  • Add an optional model argument so the main agent can select an exact displayed alias; omission preserves the current inheritance behavior.
  • Carry the approved model through spawn, resume, retry, queue, and batch execution in both agent-core v1 and v2.
  • Freeze the effective model at approval time so live flag or configuration changes cannot silently alter the delegated execution.
  • Keep provider names, base URLs, API keys, unsafe aliases, and unrecognized capability metadata out of the LLM-facing directory and approval display.
  • Add English and Chinese user documentation plus a CLI minor changeset.

The implementation is split into four reviewable commits: v1 Agent, v2 Agent, v1 AgentSwarm, and v2 AgentSwarm.

Validation

  • agent-core v1 full suite: 223 test files passed (2 skipped); 3,947 tests passed.
  • agent-core v2 full suite: 240 test files passed; 3,646 tests passed.
  • Targeted model-selection suites: 150 v1 tests and 167 v2 tests passed.
  • Package builds, CLI build, CLI typecheck, root lint (0 errors), v2 domain lint, and the VitePress documentation build passed.
  • CLI --help and doctor smoke checks passed against the locally built CLI.
  • Real-provider smoke tests passed for v1/v2 Agent and v1/v2 AgentSwarm, with the main agent using kimi-code/k3 and delegated children using deepseek-v4-flash; both swarm paths launched two children on the selected alias.

The real-provider smoke-test harness and its results are local-only and intentionally not committed.

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 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cfbcab9

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 Minor

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

@AidenNovak
AidenNovak marked this pull request as ready for review July 17, 2026 11:13

@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: cfbcab9b30

ℹ️ 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".

throw new Error('Requested model alias is not in the exposed directory');
}
}
this.modelResolver.resolve(modelAlias);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Freeze the resolved model configuration across approval

When /reload remaps an existing alias while an AgentSwarm call is waiting for manual approval, this preflight resolution is discarded and only the alias string is captured; runSwarm later resolves that alias again, so an approval displaying model fast can launch a different provider or wire model with different cost and capabilities. Preserve an immutable resolved binding or detect a changed mapping and request approval again. The same alias-only capture pattern also exists in the v2 Agent tool and both v1 collaboration tools.

Useful? React with 👍 / 👎.

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