Personal AI, On Personal Devices
Python
fix(ask): honor agent.default_agent from config when --agent omitted
IsaacHc7f451fbc896
diff --git a/src/openjarvis/cli/ask.py b/src/openjarvis/cli/ask.pyindex b1460ae1..165d5f68 100644--- a/src/openjarvis/cli/ask.py+++ b/src/openjarvis/cli/ask.py@@ -535,7 +535,11 @@ def _print_profile("--agent","agent_name",default=None,- help="Agent to use (simple, orchestrator).",+ help=(+ "Agent to use (simple, orchestrator, ...). "+ "When omitted, falls back to ``agent.default_agent`` from config. "+ "Pass ``--agent ''`` to force direct-to-engine mode (no agent)."+ ),)@click.option("--tools",@@ -591,6 +595,16 @@ def ask(# Load configconfig = load_config()+ # Honor `agent.default_agent` from config when --agent was not explicitly+ # passed. Pass `--agent ""` to opt out and use direct-to-engine mode.+ # Without this fallback, `[agent].default_system_prompt` and the+ # SOUL.md / MEMORY.md / USER.md persona system are silently bypassed for+ # the most common command (`jarvis ask "..."`).+ if agent_name is None:+ configured_default = (config.agent.default_agent or "").strip()+ if configured_default:+ agent_name = configured_default+# Track whether the user explicitly set --max-tokensuser_set_max_tokens = max_tokens is not None@@ -715,8 +729,8 @@ def ask(model_name,)- # Agent mode- if agent_name is not None:+ # Agent mode (treat empty-string `--agent ""` as explicit opt-out)+ if agent_name:parsed_tools = resolve_tool_names(tool_names,getattr(config.tools, "enabled", None),diff --git a/tests/cli/test_ask_agent.py b/tests/cli/test_ask_agent.pyindex 622c2910..8da0e234 100644--- a/tests/cli/test_ask_agent.py+++ b/tests/cli/test_ask_agent.py@@ -212,7 +212,39 @@ class TestAskAgentOption:)assert result.exit_code != 0- def test_no_agent_uses_direct_mode(self, runner, mock_setup):+ def test_no_agent_flag_falls_back_to_config_default_agent(+ self, runner, mock_setup+ ):+ """When --agent is omitted, ``config.agent.default_agent`` is used.++ The default ``JarvisConfig`` sets ``default_agent = "simple"``, so+ ``jarvis ask "..."`` should route through SimpleAgent rather than+ the direct-to-engine path. Without this fallback, persona settings+ (``default_system_prompt`` and SOUL.md/MEMORY.md/USER.md) would be+ silently bypassed.+ """+ result = runner.invoke(cli, ["ask", "Hello"])+ assert result.exit_code == 0+ assert "Hello from engine" in result.output++ def test_explicit_empty_agent_opts_out_of_agent_mode(+ self, runner, mock_setup+ ):+ """``--agent ""`` is the explicit opt-out: use direct-to-engine."""+ result = runner.invoke(cli, ["ask", "--agent", "", "Hello"])+ assert result.exit_code == 0+ assert "Hello from engine" in result.output++ def test_no_agent_with_blank_config_default_uses_direct_mode(+ self, runner, mock_setup, monkeypatch+ ):+ """When config's ``default_agent`` is blank and --agent is omitted,+ the original direct-to-engine path is preserved."""+ from openjarvis.core.config import JarvisConfig++ cfg = JarvisConfig()+ cfg.agent.default_agent = ""+ monkeypatch.setattr(_ask_mod, "load_config", lambda *a, **kw: cfg)result = runner.invoke(cli, ["ask", "Hello"])assert result.exit_code == 0assert "Hello from engine" in result.outputdiff --git a/tests/cli/test_ask_e2e.py b/tests/cli/test_ask_e2e.pyindex 336f58b4..3f833d14 100644--- a/tests/cli/test_ask_e2e.py+++ b/tests/cli/test_ask_e2e.py@@ -32,6 +32,15 @@ def _mock_engine_response():def _patch_ask(monkeypatch, tmp_path, *, engine_result=None, no_engine=False):"""Set up common mocks for ask tests."""+ # Re-register SimpleAgent after the autouse `_clean_registries` conftest+ # fixture clears it. ``JarvisConfig().agent.default_agent`` defaults to+ # ``"simple"``, so ``jarvis ask "..."`` (no --agent) routes through it.+ from openjarvis.agents.simple import SimpleAgent+ from openjarvis.core.registry import AgentRegistry++ if not AgentRegistry.contains("simple"):+ AgentRegistry.register_value("simple", SimpleAgent)+cfg = JarvisConfig()cfg.telemetry.db_path = str(tmp_path / "telemetry.db")diff --git a/tests/cli/test_ask_router.py b/tests/cli/test_ask_router.pyindex a4f5fbbe..ddbae1e4 100644--- a/tests/cli/test_ask_router.py+++ b/tests/cli/test_ask_router.py@@ -27,8 +27,23 @@ def _mock_engine():return engine+def _register_agents():+ """Re-register agents after the conftest registry clear.++ The default ``JarvisConfig().agent.default_agent`` is ``"simple"``,+ so ``jarvis ask "..."`` (without ``--agent``) routes through SimpleAgent.+ Without this re-registration, that path raises ``Unknown agent: simple``.+ """+ from openjarvis.agents.simple import SimpleAgent+ from openjarvis.core.registry import AgentRegistry++ if not AgentRegistry.contains("simple"):+ AgentRegistry.register_value("simple", SimpleAgent)++def _patch_engine(engine):"""Return context managers that patch engine discovery to use our mock."""+ _register_agents()return (mock.patch.object(_ask_mod,@@ -96,6 +111,7 @@ class TestAskModelResolution:cfg.intelligence.temperature = 0.7cfg.intelligence.max_tokens = 1024cfg.agent.context_from_memory = False+ cfg.agent.default_agent = ""result = CliRunner().invoke(cli, ["ask", "Hello"])assert result.exit_code == 0@@ -127,5 +143,6 @@ class TestAskModelResolution:cfg.intelligence.temperature = 0.7cfg.intelligence.max_tokens = 1024cfg.agent.context_from_memory = False+ cfg.agent.default_agent = ""result = CliRunner().invoke(cli, ["ask", "Hello"])assert result.exit_code == 0