diff --git a/strix/agents/factory.py b/strix/agents/factory.py index 063a5dd4a..5770083fd 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -660,6 +660,7 @@ def build_strix_agent( skills: list[str] | None = None, is_root: bool, scan_mode: str = "deep", + model: str | None = None, is_whitebox: bool = False, is_diff_scoped: bool = False, interactive: bool = False, @@ -725,7 +726,7 @@ def build_strix_agent( instructions=instructions, tools=tools, tool_use_behavior=_finish_tool_use_behavior, - model=None, + model=model, capabilities=[ Filesystem( configure_tools=_make_filesystem_configurator( @@ -752,6 +753,7 @@ def make_child_factory( chat_completions_tools: bool = False, strict_tool_schemas: bool = True, system_prompt_context: dict[str, Any] | None = None, + subagent_model: str | None = None, ) -> Any: """Return the runner-owned builder used by ``spawn_child_agent``. @@ -765,6 +767,7 @@ def make_child_factory( name=name, skills=skills, is_root=False, + model=subagent_model, scan_mode=scan_mode, is_whitebox=is_whitebox, is_diff_scoped=is_diff_scoped, diff --git a/strix/core/runner.py b/strix/core/runner.py index 42df1f00a..70f0912b3 100644 --- a/strix/core/runner.py +++ b/strix/core/runner.py @@ -195,6 +195,7 @@ async def run_strix_scan( status_sink: StatusSink | None = None, mcp_connection_requests: list[McpConnectionRequest] | None = None, mcp_status_sink: McpStatusSink | None = None, + subagent_model: str | None = None, ) -> RunResultBase | None: """Run or resume one Strix scan against a sandbox. @@ -471,14 +472,15 @@ async def run_strix_scan( ) child_agent_builder = make_child_factory( - scan_mode=scan_mode, - is_whitebox=is_whitebox, - is_diff_scoped=is_diff_scoped, - interactive=interactive, - chat_completions_tools=chat_completions_tools, - strict_tool_schemas=strict_tool_schemas, - system_prompt_context=scope_context, - ) + scan_mode=scan_mode, + is_whitebox=is_whitebox, + is_diff_scoped=is_diff_scoped, + interactive=interactive, + chat_completions_tools=chat_completions_tools, + strict_tool_schemas=strict_tool_schemas, + system_prompt_context=scope_context, + subagent_model=subagent_model or scan_config.get("subagent_model"), + ) async def spawn_child_agent(**kwargs: Any) -> dict[str, Any]: return await start_child_agent( diff --git a/strix/interface/cli.py b/strix/interface/cli.py index a8992ce49..2b89b67cf 100644 --- a/strix/interface/cli.py +++ b/strix/interface/cli.py @@ -85,11 +85,12 @@ async def run_cli(args: Any) -> None: # noqa: PLR0915 scan_mode = getattr(args, "scan_mode", "deep") - scan_config: dict[str, Any] = { + scan_config: dict[str, Any] = { "scan_id": args.run_name, "targets": args.targets_info, - "user_instructions": args.instruction or "", + "user_instruction": args.instruction or "", "run_name": args.run_name, + "subagent_model": getattr(args, "subagent_model", None), "diff_scope": getattr(args, "diff_scope", {"active": False}), "scan_mode": scan_mode, "non_interactive": bool(getattr(args, "non_interactive", False)), diff --git a/strix/interface/cli_args.py b/strix/interface/cli_args.py index 340a5d471..473630a3c 100644 --- a/strix/interface/cli_args.py +++ b/strix/interface/cli_args.py @@ -201,6 +201,17 @@ Strix Cloud: ), ) + parser.add_argument( + "--subagent-model", + dest="subagent_model", + type=str, + default=None, + help=( + "Model identifier to use for spawned subagents (e.g. claude-3-5-haiku, " + "gpt-4o-mini). If not specified, subagents inherit the root agent model." + ), + ) + parser.add_argument( "--scope-mode", type=str, @@ -465,3 +476,7 @@ def _load_resume_state(args: argparse.Namespace, parser: argparse.ArgumentParser persisted_scan_mode = state.get("scan_mode") if persisted_scan_mode and args.scan_mode == "deep": args.scan_mode = persisted_scan_mode + persisted_subagent_model = state.get("subagent_model") + if not getattr(args, "subagent_model", None) and persisted_subagent_model: + args.subagent_model = persisted_subagent_model + diff --git a/tests/test_cli_subagent_model.py b/tests/test_cli_subagent_model.py new file mode 100644 index 000000000..cfcc75791 --- /dev/null +++ b/tests/test_cli_subagent_model.py @@ -0,0 +1,48 @@ +import argparse +from pathlib import Path +import pytest + +from strix.interface.cli_args import parse_arguments, _load_resume_state + + +def test_subagent_model_default_none(monkeypatch): + """Verify --subagent-model defaults to None when omitted.""" + monkeypatch.setattr("sys.argv", ["strix", "--target", "https://example.com"]) + args = parse_arguments() + assert args.subagent_model is None + + +def test_subagent_model_flag_parsed(monkeypatch): + """Verify --subagent-model accepts a model name.""" + monkeypatch.setattr( + "sys.argv", + ["strix", "--target", "https://example.com", "--subagent-model", "claude-3-5-haiku"], + ) + args = parse_arguments() + assert args.subagent_model == "claude-3-5-haiku" + + +def test_resume_restores_subagent_model(monkeypatch, tmp_path): + """Verify _load_resume_state restores persisted subagent_model.""" + fake_state = { + "targets_info": [{"type": "domain", "original": "example.com"}], + "subagent_model": "gpt-4o-mini", + "scan_mode": "deep", + } + + args = argparse.Namespace( + resume="test-run", + subagent_model=None, + scan_mode="deep", + diff_scope="auto", + targets_info=[], + workspace_mount=None, + ) + parser = argparse.ArgumentParser() + + monkeypatch.setattr("strix.report.writer.read_run_record", lambda run_dir: fake_state) + monkeypatch.setattr("strix.core_paths.run_dir_for", lambda r: tmp_path) + monkeypatch.setattr(Path, "exists", lambda self: True) + + _load_resume_state(args, parser) + assert args.subagent_model == "gpt-4o-mini"