feat(subagent): add configurable subagent model via config.yaml

Allow users to configure a dedicated model for subagents spawned by
delegate_task, so narrowly-scoped subtasks can use a cheaper/faster
model while the parent agent runs on a more powerful one.

Config:
  subagent:
    model: google/gemini-3-flash-preview

Precedence: explicit model arg > config.subagent.model > parent model.

Cherry-picked from PR #751 by Bartok9, rebased onto current main
with conflict resolution and simplified to model-only override
(provider/base_url/api_key stay inherited from parent — covers the
common case of same-provider model swap via OpenRouter).

Closes #609

Co-authored-by: Bartok Moltbot <bartokmoltbot@users.noreply.github.com>
This commit is contained in:
Bartok Moltbot 2026-03-10 23:45:05 -07:00 committed by teknium1
parent 58dbd81f03
commit 6bd1726422
2 changed files with 22 additions and 1 deletions

View file

@ -119,6 +119,13 @@ DEFAULT_CONFIG = {
}, },
}, },
# Subagent configuration — model/provider for tasks spawned via delegate_task.
# By default subagents inherit the parent agent's model and provider.
# Set "model" to use a cheaper/faster model for delegated subtasks.
"subagent": {
# "model": "google/gemini-3-flash-preview",
},
"display": { "display": {
"compact": False, "compact": False,
"personality": "kawaii", "personality": "kawaii",

View file

@ -78,6 +78,15 @@ def _strip_blocked_tools(toolsets: List[str]) -> List[str]:
return [t for t in toolsets if t not in blocked_toolset_names] return [t for t in toolsets if t not in blocked_toolset_names]
def _get_subagent_config() -> Dict[str, Any]:
"""Load subagent config from CLI_CONFIG if available."""
try:
from cli import CLI_CONFIG
return CLI_CONFIG.get("subagent", {})
except Exception:
return {}
def _build_child_progress_callback(task_index: int, parent_agent, task_count: int = 1) -> Optional[callable]: def _build_child_progress_callback(task_index: int, parent_agent, task_count: int = 1) -> Optional[callable]:
"""Build a callback that relays child agent tool calls to the parent display. """Build a callback that relays child agent tool calls to the parent display.
@ -199,10 +208,15 @@ def _run_single_child(
# count toward the session-wide limit. # count toward the session-wide limit.
shared_budget = getattr(parent_agent, "iteration_budget", None) shared_budget = getattr(parent_agent, "iteration_budget", None)
# Subagent model override from config.
# Precedence: explicit model arg > config.subagent.model > parent model
subagent_cfg = _get_subagent_config()
effective_model = model or subagent_cfg.get("model") or parent_agent.model
child = AIAgent( child = AIAgent(
base_url=parent_agent.base_url, base_url=parent_agent.base_url,
api_key=parent_api_key, api_key=parent_api_key,
model=model or parent_agent.model, model=effective_model,
provider=getattr(parent_agent, "provider", None), provider=getattr(parent_agent, "provider", None),
api_mode=getattr(parent_agent, "api_mode", None), api_mode=getattr(parent_agent, "api_mode", None),
max_iterations=max_iterations, max_iterations=max_iterations,