Skip to content

Personal AI, On Personal Devices

Python

fix: complete persona wiring across agent entry points

Elliot Sluskyef28e5f84bc3
diff --git a/src/openjarvis/agents/monitor_operative.py b/src/openjarvis/agents/monitor_operative.py
index d95fc582..d4cf2580 100644
--- a/src/openjarvis/agents/monitor_operative.py
+++ b/src/openjarvis/agents/monitor_operative.py
@@ -127,6 +127,7 @@ class MonitorOperativeAgent(ToolUsingAgent):
memory_backend: Optional[Any] = None,
interactive: bool = False,
confirm_callback=None,
+ prompt_builder: Optional[Any] = None,
**kwargs: Any,
) -> None:
super().__init__(
@@ -139,7 +140,7 @@ class MonitorOperativeAgent(ToolUsingAgent):
max_tokens=max_tokens,
interactive=interactive,
confirm_callback=confirm_callback,
- prompt_builder=kwargs.get("prompt_builder"),
+ prompt_builder=prompt_builder,
)
# Validate strategies
if memory_extraction not in VALID_MEMORY_EXTRACTION:
diff --git a/src/openjarvis/agents/operative.py b/src/openjarvis/agents/operative.py
index ca1d88d5..0e9a0529 100644
--- a/src/openjarvis/agents/operative.py
+++ b/src/openjarvis/agents/operative.py
@@ -58,6 +58,7 @@ class OperativeAgent(ToolUsingAgent):
memory_backend: Optional[Any] = None,
interactive: bool = False,
confirm_callback=None,
+ prompt_builder: Optional[Any] = None,
**kwargs: Any,
) -> None:
super().__init__(
@@ -70,7 +71,7 @@ class OperativeAgent(ToolUsingAgent):
max_tokens=max_tokens,
interactive=interactive,
confirm_callback=confirm_callback,
- prompt_builder=kwargs.get("prompt_builder"),
+ prompt_builder=prompt_builder,
)
self._system_prompt = system_prompt or ""
self._operator_id = operator_id
diff --git a/src/openjarvis/cli/ask.py b/src/openjarvis/cli/ask.py
index 3f6152cd..14052cd6 100644
--- a/src/openjarvis/cli/ask.py
+++ b/src/openjarvis/cli/ask.py
@@ -398,9 +398,8 @@ def _run_agent(
# Wire the SystemPromptBuilder so SOUL.md / MEMORY.md / USER.md persona
# files actually reach the model. Only passed to agents whose __init__
- # accepts a `prompt_builder` kwarg (BaseAgent does; agents that override
- # __init__ without forwarding it, e.g. OrchestratorAgent, opt out
- # automatically and keep their existing system-prompt machinery).
+ # explicitly accepts a `prompt_builder` kwarg. Agents with specialized
+ # prompt machinery opt in by naming and forwarding the parameter.
import inspect as _inspect
if "prompt_builder" in _inspect.signature(agent_cls.__init__).parameters:
diff --git a/src/openjarvis/cli/serve.py b/src/openjarvis/cli/serve.py
index 6369b8cc..650f7e42 100644
--- a/src/openjarvis/cli/serve.py
+++ b/src/openjarvis/cli/serve.py
@@ -372,8 +372,8 @@ def serve(
# this since the persona system landed; ``serve.py`` never did,
# so an agent served over HTTP silently answered as a generic
# assistant while the same agent via the CLI kept its persona.
- # Guarded so agents whose ``__init__`` doesn't accept the kwarg
- # (e.g. OrchestratorAgent) opt out automatically.
+ # Guarded so agents with specialized prompt machinery must opt
+ # in by explicitly naming and forwarding the kwarg.
import inspect as _inspect
if (
diff --git a/tests/cli/test_ask_agent.py b/tests/cli/test_ask_agent.py
index 1a9bc8b7..73abdaf9 100644
--- a/tests/cli/test_ask_agent.py
+++ b/tests/cli/test_ask_agent.py
@@ -396,11 +396,10 @@ class TestPersonaFilesReachModel:
assert "MEMORY_SENTINEL" in joined
assert "USER_SENTINEL" in joined
- def test_orchestrator_keeps_its_own_system_prompt(
+ def test_orchestrator_accepts_persona_prompt_builder(
self, runner, monkeypatch, tmp_path
):
- """OrchestratorAgent's __init__ doesn't accept ``prompt_builder``;
- the wiring must skip it silently rather than crash."""
+ """Orchestrator explicitly accepts and applies persona wiring."""
from openjarvis.core.config import JarvisConfig
soul = tmp_path / "SOUL.md"
@@ -425,5 +424,6 @@ class TestPersonaFilesReachModel:
):
result = runner.invoke(cli, ["ask", "--agent", "orchestrator", "Hello"])
- # Pass condition: doesn't crash with TypeError on prompt_builder kwarg.
assert result.exit_code == 0, result.output
+ messages = engine.generate.call_args.args[0]
+ assert "ORCH_PERSONA_SENTINEL" in messages[0].content
diff --git a/tests/cli/test_serve_persona.py b/tests/cli/test_serve_persona.py
index 67445cba..e64e2c62 100644
--- a/tests/cli/test_serve_persona.py
+++ b/tests/cli/test_serve_persona.py
@@ -41,10 +41,19 @@ def _fake_engine() -> MagicMock:
return engine
-def test_serve_wires_persona_builder_into_served_agent(tmp_path, monkeypatch):
+ "agent_name",
+ ["simple", "orchestrator", "monitor_operative", "operative"],
+)
+def test_serve_wires_persona_builder_into_served_agent(
+ tmp_path, monkeypatch, agent_name
+):
"""The agent built on the serve path must carry a SystemPromptBuilder whose
assembled prompt includes SOUL.md content (regression for the HTTP persona
loss)."""
+ from openjarvis.agents.monitor_operative import MonitorOperativeAgent
+ from openjarvis.agents.operative import OperativeAgent
+ from openjarvis.agents.orchestrator import OrchestratorAgent
from openjarvis.agents.simple import SimpleAgent
from openjarvis.core.config import JarvisConfig
from openjarvis.core.registry import AgentRegistry
@@ -54,9 +63,14 @@ def test_serve_wires_persona_builder_into_served_agent(tmp_path, monkeypatch):
soul.write_text("SERVE_PERSONA_SENTINEL", encoding="utf-8")
# conftest clears registries per-test; re-register the agent we exercise.
- # (SimpleAgent extends BaseAgent, whose __init__ accepts ``prompt_builder``.)
- if not AgentRegistry.contains("simple"):
- AgentRegistry.register_value("simple", SimpleAgent)
+ agent_classes = {
+ "simple": SimpleAgent,
+ "orchestrator": OrchestratorAgent,
+ "monitor_operative": MonitorOperativeAgent,
+ "operative": OperativeAgent,
+ }
+ if not AgentRegistry.contains(agent_name):
+ AgentRegistry.register_value(agent_name, agent_classes[agent_name])
config = JarvisConfig()
config.server.host = "127.0.0.1"
@@ -95,7 +109,7 @@ def test_serve_wires_persona_builder_into_served_agent(tmp_path, monkeypatch):
patch("uvicorn.run", lambda *a, **k: None),
):
result = CliRunner().invoke(
- cli, ["serve", "--agent", "simple"], catch_exceptions=False
+ cli, ["serve", "--agent", agent_name], catch_exceptions=False
)
assert result.exit_code == 0, result.output
@@ -107,7 +121,7 @@ def test_serve_wires_persona_builder_into_served_agent(tmp_path, monkeypatch):
# The regression: without the fix ``agent._prompt_builder`` is None and the
# persona files never reach the model over HTTP.
assert agent._prompt_builder is not None, (
- "serve constructed the agent without a prompt_builder — SOUL.md / "
+ f"serve constructed {agent_name} without a prompt_builder — SOUL.md / "
"MEMORY.md / USER.md would be silently dropped on the HTTP path."
)
assert "SERVE_PERSONA_SENTINEL" in agent._prompt_builder.build(), (
diff --git a/tests/sdk/test_sdk.py b/tests/sdk/test_sdk.py
index 70c20832..b64e19e7 100644
--- a/tests/sdk/test_sdk.py
+++ b/tests/sdk/test_sdk.py
@@ -95,6 +95,30 @@ class TestJarvisAsk:
assert result == "Agent response"
j.close()
+ def test_ask_with_agent_wires_persona(self, tmp_path):
+ from openjarvis.agents.simple import SimpleAgent
+ from openjarvis.core.registry import AgentRegistry
+
+ soul = tmp_path / "SOUL.md"
+ soul.write_text("SDK_PERSONA_SENTINEL", encoding="utf-8")
+
+ cfg = JarvisConfig()
+ cfg.memory_files.soul_path = str(soul)
+ cfg.memory_files.memory_path = ""
+ cfg.memory_files.user_path = ""
+ cfg.agent.context_from_memory = False
+
+ if not AgentRegistry.contains("simple"):
+ AgentRegistry.register_value("simple", SimpleAgent)
+
+ engine = _make_engine()
+ with patch("openjarvis.sdk.get_engine", return_value=("mock", engine)):
+ j = Jarvis(config=cfg, model="test-model")
+ j.ask("Hello", agent="simple")
+ messages = engine.generate.call_args.args[0]
+ assert "SDK_PERSONA_SENTINEL" in messages[0].content
+ j.close()
+
def test_ask_no_engine_raises(self):
with patch("openjarvis.sdk.get_engine", return_value=None):
j = Jarvis(config=JarvisConfig())