From 703fb75bf698ba30e3decc11cd86c69e74c24d87 Mon Sep 17 00:00:00 2001 From: Man Yue Mo Date: Mon, 27 Apr 2026 15:16:47 +0000 Subject: [PATCH 1/6] add cli argument for model config --- src/seclab_taskflow_agent/cli.py | 6 +++++- src/seclab_taskflow_agent/runner.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/seclab_taskflow_agent/cli.py b/src/seclab_taskflow_agent/cli.py index 19e7790c..3e873b91 100644 --- a/src/seclab_taskflow_agent/cli.py +++ b/src/seclab_taskflow_agent/cli.py @@ -108,6 +108,10 @@ def main( list[str] | None, typer.Argument(help="Remaining prompt text."), ] = None, + model_config: Annotated[ + str | None, + typer.Option("-m", "--model-config", help="Model configuration module path. Only relevant when running taskflows"), + ] = None, ) -> None: """Run a taskflow or personality-based agent session.""" # Debug mode from flag or env var @@ -158,7 +162,7 @@ def main( asyncio.run( run_main( available_tools, personality, effective_taskflow, - cli_globals, user_prompt, resume_session_id=resume, + cli_globals, user_prompt, cli_model_config = model_config, resume_session_id=resume, ), debug=debug, ) diff --git a/src/seclab_taskflow_agent/runner.py b/src/seclab_taskflow_agent/runner.py index 6a8aa608..8e2bdd80 100644 --- a/src/seclab_taskflow_agent/runner.py +++ b/src/seclab_taskflow_agent/runner.py @@ -490,6 +490,7 @@ async def run_main( taskflow_path: str | None, cli_globals: dict[str, str], prompt: str | None, + cli_model_config: str | None, resume_session_id: str | None = None, ) -> None: """Main entry point for taskflow/personality execution. @@ -500,6 +501,7 @@ async def run_main( taskflow_path: Taskflow module path, or None. cli_globals: Global variables from CLI. prompt: User prompt text. + cli_model_config: Model configuration module path, or None. resume_session_id: Session ID to resume from a checkpoint. """ from .session import TaskflowSession @@ -557,6 +559,8 @@ async def on_handoff_hook(context: RunContextWrapper[TContext], agent: Agent[TCo # Resolve model config model_config_ref = taskflow_doc.model_config_ref + if cli_model_config: + model_config_ref = cli_model_config model_keys: list[str] = [] model_dict: dict[str, str] = {} models_params: dict[str, dict[str, Any]] = {} From 3b89db987d47ecb86027e66a1a73ba49cf65e824 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Mon, 27 Apr 2026 19:10:26 +0100 Subject: [PATCH 2/6] Update src/seclab_taskflow_agent/cli.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/seclab_taskflow_agent/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seclab_taskflow_agent/cli.py b/src/seclab_taskflow_agent/cli.py index 3e873b91..79bffdb1 100644 --- a/src/seclab_taskflow_agent/cli.py +++ b/src/seclab_taskflow_agent/cli.py @@ -110,7 +110,7 @@ def main( ] = None, model_config: Annotated[ str | None, - typer.Option("-m", "--model-config", help="Model configuration module path. Only relevant when running taskflows"), + typer.Option("-m", "--model-config", help="Model configuration module path. Only relevant when running taskflows."), ] = None, ) -> None: """Run a taskflow or personality-based agent session.""" From e5b40238dfcd9b3d0d4626f25d8e8a1ea31c91da Mon Sep 17 00:00:00 2001 From: Man Yue Mo Date: Tue, 28 Apr 2026 14:42:34 +0000 Subject: [PATCH 3/6] addressed comments --- src/seclab_taskflow_agent/cli.py | 2 +- src/seclab_taskflow_agent/runner.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seclab_taskflow_agent/cli.py b/src/seclab_taskflow_agent/cli.py index 79bffdb1..3eff06aa 100644 --- a/src/seclab_taskflow_agent/cli.py +++ b/src/seclab_taskflow_agent/cli.py @@ -162,7 +162,7 @@ def main( asyncio.run( run_main( available_tools, personality, effective_taskflow, - cli_globals, user_prompt, cli_model_config = model_config, resume_session_id=resume, + cli_globals, user_prompt, resume_session_id=resume, cli_model_config=model_config, ), debug=debug, ) diff --git a/src/seclab_taskflow_agent/runner.py b/src/seclab_taskflow_agent/runner.py index 8e2bdd80..421d1650 100644 --- a/src/seclab_taskflow_agent/runner.py +++ b/src/seclab_taskflow_agent/runner.py @@ -490,8 +490,8 @@ async def run_main( taskflow_path: str | None, cli_globals: dict[str, str], prompt: str | None, - cli_model_config: str | None, resume_session_id: str | None = None, + cli_model_config: str | None = None, ) -> None: """Main entry point for taskflow/personality execution. From a62b4c3b938f51ad30abe6105cdb24974d42cb3c Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Fri, 22 May 2026 11:15:07 +0100 Subject: [PATCH 4/6] Fix indentation in cli.py --- src/seclab_taskflow_agent/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seclab_taskflow_agent/cli.py b/src/seclab_taskflow_agent/cli.py index 3eff06aa..b5bf2ebc 100644 --- a/src/seclab_taskflow_agent/cli.py +++ b/src/seclab_taskflow_agent/cli.py @@ -162,7 +162,7 @@ def main( asyncio.run( run_main( available_tools, personality, effective_taskflow, - cli_globals, user_prompt, resume_session_id=resume, cli_model_config=model_config, + cli_globals, user_prompt, resume_session_id=resume, cli_model_config=model_config, ), debug=debug, ) From c5289a400686a8d774b4302c1b7260f909e49321 Mon Sep 17 00:00:00 2001 From: Bas Alberts Date: Mon, 1 Jun 2026 12:31:16 -0400 Subject: [PATCH 5/6] Address PR review feedback for CLI model config - Fix docstring arg order: match resume_session_id, cli_model_config parameter order in run_main signature - Persist cli_model_config in TaskflowSession for deterministic resume: restored automatically on resume, can be explicitly overridden with --model-config - Add TestCliModelConfigOverride test suite (6 tests) covering override precedence, resolution, session persistence, and resume behavior - Add session-level tests for cli_model_config persistence and defaults Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/seclab_taskflow_agent/runner.py | 6 +- src/seclab_taskflow_agent/session.py | 3 + tests/test_runner.py | 88 +++++++++++++++++++++++++++- tests/test_session.py | 17 ++++++ 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/seclab_taskflow_agent/runner.py b/src/seclab_taskflow_agent/runner.py index 421d1650..12d36bd8 100644 --- a/src/seclab_taskflow_agent/runner.py +++ b/src/seclab_taskflow_agent/runner.py @@ -501,8 +501,8 @@ async def run_main( taskflow_path: Taskflow module path, or None. cli_globals: Global variables from CLI. prompt: User prompt text. - cli_model_config: Model configuration module path, or None. resume_session_id: Session ID to resume from a checkpoint. + cli_model_config: Model configuration module path, or None. """ from .session import TaskflowSession @@ -545,6 +545,9 @@ async def on_handoff_hook(context: RunContextWrapper[TContext], agent: Agent[TCo cli_globals = session.cli_globals prompt = session.prompt last_mcp_tool_results = list(session.last_tool_results) + # Restore persisted model config unless explicitly overridden + if not cli_model_config and session.cli_model_config: + cli_model_config = session.cli_model_config await render_model_output( f"** πŸ€–πŸ”„ Resuming session {resume_session_id} from task {session.next_task_index}\n" ) @@ -578,6 +581,7 @@ async def on_handoff_hook(context: RunContextWrapper[TContext], agent: Agent[TCo cli_globals=cli_globals, prompt=prompt or "", total_tasks=len(taskflow_doc.taskflow), + cli_model_config=cli_model_config or "", ) session.save() await render_model_output(f"** πŸ€–πŸ“‹ Session: {session.session_id}\n") diff --git a/src/seclab_taskflow_agent/session.py b/src/seclab_taskflow_agent/session.py index c682cb92..d829da45 100644 --- a/src/seclab_taskflow_agent/session.py +++ b/src/seclab_taskflow_agent/session.py @@ -60,6 +60,9 @@ class TaskflowSession(BaseModel): finished: bool = False error: str = "" + # CLI model config override persisted for deterministic resume + cli_model_config: str = "" + # Accumulated tool results carried across tasks (used by repeat_prompt) last_tool_results: list[str] = Field(default_factory=list) diff --git a/tests/test_runner.py b/tests/test_runner.py index 35a9a555..70511e7e 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -278,9 +278,95 @@ def test_task_engine_keys_override_config(self): # =================================================================== -# _build_prompts_to_run +# CLI model config override # =================================================================== +class TestCliModelConfigOverride: + """Tests for CLI model config overriding taskflow model_config_ref.""" + + def test_cli_overrides_taskflow_model_config(self): + """cli_model_config takes precedence over taskflow_doc.model_config_ref.""" + taskflow_ref = "taskflow.models.default" + cli_ref = "cli.models.override" + + # Simulate the override logic from run_main + model_config_ref = taskflow_ref + if cli_ref: + model_config_ref = cli_ref + + assert model_config_ref == cli_ref + + def test_taskflow_model_config_used_when_cli_absent(self): + """Taskflow model_config_ref is used when cli_model_config is None.""" + taskflow_ref = "taskflow.models.default" + cli_ref = None + + model_config_ref = taskflow_ref + if cli_ref: + model_config_ref = cli_ref + + assert model_config_ref == taskflow_ref + + def test_cli_model_config_resolves_via_available_tools(self): + """CLI-provided model config is resolved through _resolve_model_config.""" + at = _mock_available_tools() + at.get_model_config.return_value = _make_model_config( + models={"fast": "gpt-4o-mini"}, + ) + keys, mdict, params, api_type, backend = _resolve_model_config(at, "cli.override.ref") + at.get_model_config.assert_called_once_with("cli.override.ref") + assert mdict == {"fast": "gpt-4o-mini"} + + def test_cli_model_config_persisted_in_session(self): + """cli_model_config is stored in session for deterministic resume.""" + from seclab_taskflow_agent.session import TaskflowSession + + session = TaskflowSession( + taskflow_path="test.flow", + cli_model_config="cli.models.fast", + ) + assert session.cli_model_config == "cli.models.fast" + + def test_session_resume_restores_cli_model_config(self, tmp_path, monkeypatch): + """Resumed session restores cli_model_config when not overridden.""" + monkeypatch.setattr("seclab_taskflow_agent.session.session_dir", lambda: tmp_path) + from seclab_taskflow_agent.session import TaskflowSession + + session = TaskflowSession( + taskflow_path="test.flow", + cli_model_config="persisted.models.ref", + ) + session.save() + + loaded = TaskflowSession.load(session.session_id) + + # Simulate the resume logic from run_main + cli_model_config = None # not passed on resume + if not cli_model_config and loaded.cli_model_config: + cli_model_config = loaded.cli_model_config + + assert cli_model_config == "persisted.models.ref" + + def test_session_resume_cli_override_takes_precedence(self, tmp_path, monkeypatch): + """Explicit --model-config on resume overrides persisted value.""" + monkeypatch.setattr("seclab_taskflow_agent.session.session_dir", lambda: tmp_path) + from seclab_taskflow_agent.session import TaskflowSession + + session = TaskflowSession( + taskflow_path="test.flow", + cli_model_config="persisted.models.ref", + ) + session.save() + + loaded = TaskflowSession.load(session.session_id) + + # Simulate the resume logic from run_main with explicit override + cli_model_config = "new.override.ref" + if not cli_model_config and loaded.cli_model_config: + cli_model_config = loaded.cli_model_config + + assert cli_model_config == "new.override.ref" + class TestBuildPromptsToRun: """Tests for _build_prompts_to_run (async, run via asyncio.run).""" diff --git a/tests/test_session.py b/tests/test_session.py index f8563f95..a6c1765e 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -78,6 +78,23 @@ def test_list_sessions(self, tmp_path, monkeypatch): assert s1.session_id in ids assert s2.session_id in ids + def test_cli_model_config_persisted(self, tmp_path, monkeypatch): + """cli_model_config is persisted and restored on load.""" + monkeypatch.setattr("seclab_taskflow_agent.session.session_dir", lambda: tmp_path) + s = TaskflowSession( + taskflow_path="examples.taskflows.echo", + cli_model_config="custom.models.fast", + ) + s.save() + + loaded = TaskflowSession.load(s.session_id) + assert loaded.cli_model_config == "custom.models.fast" + + def test_cli_model_config_defaults_empty(self): + """cli_model_config defaults to empty string.""" + s = TaskflowSession(taskflow_path="test.flow") + assert s.cli_model_config == "" + class TestCompletedTask: """Tests for CompletedTask model.""" From ab1f815f87fa9dc0974a2c929d1b909a5b016616 Mon Sep 17 00:00:00 2001 From: Bas Alberts Date: Mon, 1 Jun 2026 12:34:15 -0400 Subject: [PATCH 6/6] Document --model-config / -m CLI flag in README - Add -m to architecture diagram CLI flags listing - Document model config persistence in session recovery section - Add CLI override subsection under Model configs with usage example Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 23 ++++++++++++++++++++++- tests/test_runner.py | 20 +++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ba43c346..3e44d86d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You can find a detailed overview of the taskflow grammar [here](doc/GRAMMAR.md) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CLI (cli.py) β”‚ -β”‚ Typer-based entry point: -p, -t, -l, -g, --resume β”‚ +β”‚ Typer-based entry point: -p, -t, -l, -g, -m, --resumeβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” @@ -132,6 +132,14 @@ Resume from the last successful checkpoint: python -m seclab_taskflow_agent --resume abc123def456 ``` +The session checkpoint persists the CLI-provided `--model-config` value (if +any), so resumes use the same model configuration by default. To override the +model config on resume, pass `--model-config` / `-m` explicitly: + +```bash +python -m seclab_taskflow_agent --resume abc123def456 -m examples.model_configs.responses_api +``` + Failed tasks are automatically retried up to 3 times with increasing backoff before the session is saved. Session checkpoints are stored in the platform-specific application data directory. @@ -611,6 +619,19 @@ taskflow: The model version can then be updated by changing `gpt_latest` in the `model_config` file and applied across all taskflows that use the config. +#### CLI override + +The `model_config` can also be specified (or overridden) from the command line +with `--model-config` / `-m`. This takes precedence over any `model_config` +value defined in the taskflow YAML: + +```bash +python -m seclab_taskflow_agent -t examples.taskflows.echo -m examples.model_configs.responses_api +``` + +The CLI-provided model config is persisted in the session checkpoint, so +resumed runs automatically use the same configuration. + In addition, model specific parameters can be provided via `model_config`. To do so, define a `model_settings` section in the `model_config` file. This section has to be a dictionary with the model names as keys: ```yaml diff --git a/tests/test_runner.py b/tests/test_runner.py index 70511e7e..a7713953 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -286,26 +286,24 @@ class TestCliModelConfigOverride: def test_cli_overrides_taskflow_model_config(self): """cli_model_config takes precedence over taskflow_doc.model_config_ref.""" - taskflow_ref = "taskflow.models.default" - cli_ref = "cli.models.override" - - # Simulate the override logic from run_main - model_config_ref = taskflow_ref - if cli_ref: - model_config_ref = cli_ref - - assert model_config_ref == cli_ref + model_config_ref = self._resolve("taskflow.models.default", "cli.models.override") + assert model_config_ref == "cli.models.override" def test_taskflow_model_config_used_when_cli_absent(self): """Taskflow model_config_ref is used when cli_model_config is None.""" taskflow_ref = "taskflow.models.default" cli_ref = None + model_config_ref = self._resolve(taskflow_ref, cli_ref) + assert model_config_ref == taskflow_ref + + @staticmethod + def _resolve(taskflow_ref: str, cli_ref: str | None) -> str: + """Reproduce the override logic from run_main.""" model_config_ref = taskflow_ref if cli_ref: model_config_ref = cli_ref - - assert model_config_ref == taskflow_ref + return model_config_ref def test_cli_model_config_resolves_via_available_tools(self): """CLI-provided model config is resolved through _resolve_model_config."""