Skip to content

Personal AI, On Personal Devices

Python

fix(system): wire the persona prompt builder into channel agent turns (#1078)

Ari Vitor S. Lazzarotto0c508c6cd010
diff --git a/src/openjarvis/system/orchestrator.py b/src/openjarvis/system/orchestrator.py
index 90a0eb3d..b80f5b16 100644
--- a/src/openjarvis/system/orchestrator.py
+++ b/src/openjarvis/system/orchestrator.py
@@ -209,6 +209,24 @@ class QueryOrchestrator:
existing = agent_kwargs.get("tools", [])
agent_kwargs["tools"] = digest_tools + list(existing)
+ # Wire the SystemPromptBuilder so SOUL.md / MEMORY.md / USER.md reach the
+ # model on channel turns too, like cli/serve.py and sdk.py. Skipped when
+ # the caller passed its own system_prompt, which the builder would
+ # replace; agents whose __init__ lacks the kwarg opt out.
+ import inspect
+
+ if (
+ system_prompt is None
+ and "prompt_builder" in inspect.signature(agent_cls.__init__).parameters
+ ):
+ from openjarvis.prompt.builder import SystemPromptBuilder
+
+ agent_kwargs["prompt_builder"] = SystemPromptBuilder(
+ agent_template=s.config.agent.default_system_prompt or "",
+ memory_files_config=s.config.memory_files,
+ system_prompt_config=s.config.system_prompt,
+ )
+
try:
ag = agent_cls(s.engine, s.model, **agent_kwargs)
except TypeError:
diff --git a/tests/test_query_orchestrator.py b/tests/test_query_orchestrator.py
index da9b1323..25ed29e6 100644
--- a/tests/test_query_orchestrator.py
+++ b/tests/test_query_orchestrator.py
@@ -4,11 +4,14 @@ from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional
+from unittest.mock import patch
import pytest
+from openjarvis.agents._stubs import AgentResult
from openjarvis.core.config import JarvisConfig
from openjarvis.core.events import EventBus
+from openjarvis.core.types import Message, Role
from openjarvis.system import QueryOrchestrator
@@ -143,3 +146,37 @@ class TestDetectAgentIntent:
system = _FakeSystem()
orchestrator = QueryOrchestrator(system)
assert orchestrator._detect_agent_intent("what's the weather") is None
+
+
+class TestRunAgentPersonaWiring:
+ @staticmethod
+ def _run(system_prompt: Optional[str]) -> Dict[str, Any]:
+ seen: Dict[str, Any] = {}
+
+ class _Agent:
+ mode = "function_calling"
+
+ def __init__(self, engine, model, *, prompt_builder=None, **_):
+ seen["prompt_builder"] = prompt_builder
+
+ def run(self, *_, **__):
+ return AgentResult(content="hi", turns=1)
+
+ orch = QueryOrchestrator(_FakeSystem())
+ with patch("openjarvis.core.registry.AgentRegistry.get", return_value=_Agent):
+ orch._run_agent(
+ "hi",
+ [Message(role=Role.USER, content="hi")],
+ "orchestrator",
+ None,
+ 0.7,
+ 1024,
+ system_prompt=system_prompt,
+ )
+ return seen
+
+ def test_channel_turn_gets_the_persona_prompt_builder(self):
+ assert self._run(None)["prompt_builder"] is not None
+
+ def test_explicit_system_prompt_is_not_replaced(self):
+ assert self._run("custom prompt")["prompt_builder"] is None