-
Notifications
You must be signed in to change notification settings - Fork 253
feat: add /swarm-model command for subagent model override #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@moonshot-ai/agent-core": minor | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Add `/swarm-model` command and `sub_agent_model` config key to let users set a different model for swarm subagents. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,23 @@ export function handleModelCommand(host: SlashCommandHost, args: string): void { | |
| showModelPicker(host, alias); | ||
| } | ||
|
|
||
| export function handleSwarmModelCommand(host: SlashCommandHost, args: string): void { | ||
| const alias = args.trim(); | ||
| if (alias.length === 0) { | ||
| showSwarmModelPicker(host); | ||
| return; | ||
| } | ||
| if (alias.toLowerCase() === 'off') { | ||
| void clearSwarmModel(host); | ||
| return; | ||
| } | ||
| if (host.state.appState.availableModels[alias] === undefined) { | ||
| host.showError(`Unknown model alias: ${alias}`); | ||
| return; | ||
| } | ||
| showSwarmModelPicker(host, alias); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Pickers & config apply | ||
| // --------------------------------------------------------------------------- | ||
|
|
@@ -285,6 +302,86 @@ export function showModelPicker(host: SlashCommandHost, selectedValue: string = | |
| ); | ||
| } | ||
|
|
||
| function showSwarmModelPicker(host: SlashCommandHost, selectedValue?: string): void { | ||
| const entries = Object.entries(host.state.appState.availableModels); | ||
| if (entries.length === 0) { | ||
| host.showNotice( | ||
| 'No models configured', | ||
| 'Run /login to sign in to Kimi, or /provider to add another provider from a model catalog.', | ||
| ); | ||
| return; | ||
| } | ||
| host.mountEditorReplacement( | ||
| new TabbedModelSelectorComponent({ | ||
| models: host.state.appState.availableModels, | ||
| currentValue: host.state.appState.subAgentModel ?? '', | ||
| selectedValue, | ||
| currentThinking: false, | ||
| colors: host.state.theme.colors, | ||
| onSelect: ({ alias }) => { | ||
| host.restoreEditor(); | ||
| void setSwarmModel(host, alias); | ||
| }, | ||
| onCancel: () => { | ||
| host.restoreEditor(); | ||
| }, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| async function setSwarmModel(host: SlashCommandHost, alias: string): Promise<void> { | ||
| if (host.state.appState.streamingPhase !== 'idle') { | ||
| host.showError('Cannot switch models while streaming — press Esc or Ctrl-C first.'); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await host.harness.setConfig({ subAgentModel: alias }); | ||
| } catch (error) { | ||
| host.showError(`Failed to save sub-agent model: ${formatErrorMessage(error)}`); | ||
| return; | ||
| } | ||
|
|
||
| // Push the updated config to the live session so active agents pick it up | ||
| const session = host.session; | ||
| if (session !== undefined) { | ||
| await session.reloadSession(); | ||
| } | ||
|
|
||
| host.setAppState({ subAgentModel: alias }); | ||
| host.showStatus( | ||
| `Swarm subagents will use ${alias}.`, | ||
| host.state.theme.colors.success, | ||
| ); | ||
| host.track('swarm_model_switch', { model: alias }); | ||
| } | ||
|
|
||
| async function clearSwarmModel(host: SlashCommandHost): Promise<void> { | ||
| if (host.state.appState.streamingPhase !== 'idle') { | ||
| host.showError('Cannot switch models while streaming — press Esc or Ctrl-C first.'); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await host.harness.setConfig({ subAgentModel: null }); | ||
| } catch (error) { | ||
| host.showError(`Failed to clear sub-agent model: ${formatErrorMessage(error)}`); | ||
| return; | ||
| } | ||
|
|
||
| // Push the updated config to the live session so active agents pick it up | ||
| const session = host.session; | ||
| if (session !== undefined) { | ||
| await session.reloadSession(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| host.setAppState({ subAgentModel: undefined }); | ||
| host.showStatus( | ||
| 'Swarm subagents will inherit the main model.', | ||
| host.state.theme.colors.success, | ||
| ); | ||
| } | ||
|
|
||
| async function performModelSwitch(host: SlashCommandHost, alias: string, thinking: boolean): Promise<void> { | ||
| if (host.state.appState.streamingPhase !== 'idle') { | ||
| host.showError('Cannot switch models while streaming — press Esc or Ctrl-C first.'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
/swarm-modelis used after a session is already active, this only persists the new value to config.toml and updates TUI state; existingSession/Agentinstances keep theconfigobject they were constructed with, and the new subagent path readsparent.kimiConfig?.subAgentModelwhen spawning. As a result, the command can reportSwarm subagents will use <alias>while swarms in the current session still use the old/inherited model until a reload or new session. Please also update the live session/agent runtime state, or make the subagent host read the refreshed config.Useful? React with 👍 / 👎.