mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-08-15 09:21:56 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3042bfe3f1 | ||
|
|
40c7df3e5b |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"label": "Git Clones",
|
||||
"message": "190,252",
|
||||
"message": "191,195",
|
||||
"color": "green",
|
||||
"namedLogo": "git"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"total_clones": 190252,
|
||||
"last_updated": "2026-08-14T07:19:51Z",
|
||||
"total_clones": 191195,
|
||||
"last_updated": "2026-08-15T06:32:36Z",
|
||||
"daily": {
|
||||
"2026-03-27": 2189,
|
||||
"2026-03-28": 1874,
|
||||
@@ -141,6 +141,7 @@
|
||||
"2026-08-10": 1060,
|
||||
"2026-08-11": 2182,
|
||||
"2026-08-12": 641,
|
||||
"2026-08-13": 770
|
||||
"2026-08-13": 770,
|
||||
"2026-08-14": 943
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,10 @@ def _ensure_identity_prompt(messages: list[Message], app_config) -> list[Message
|
||||
``SystemPromptBuilder`` / ``BaseAgent``; the engine-direct server paths
|
||||
did not. This mirrors the agent fallback in ``agents/_stubs.py``.
|
||||
|
||||
If any message already carries a system role, the caller has supplied
|
||||
their own grounding and we leave the list untouched (no double-prompting).
|
||||
If any caller-supplied message already carries a system role, the caller
|
||||
has supplied their own grounding and we leave the list untouched (no
|
||||
double-prompting). Internally tagged memory context does not count as
|
||||
caller grounding.
|
||||
|
||||
Resolution of the identity text: the config comes from ``app.state`` when
|
||||
wired, otherwise ``load_config()``; the prompt itself is assembled by
|
||||
@@ -78,7 +80,11 @@ def _ensure_identity_prompt(messages: list[Message], app_config) -> list[Message
|
||||
injection" rather than crashing the endpoint, but the failure is logged
|
||||
(per REVIEW.md — never silently swallow).
|
||||
"""
|
||||
if any(m.role == Role.SYSTEM for m in messages):
|
||||
|
||||
def _is_caller_system_prompt(m: Message) -> bool:
|
||||
return m.role == Role.SYSTEM and not m.metadata.get("memory_context")
|
||||
|
||||
if any(_is_caller_system_prompt(m) for m in messages):
|
||||
return messages
|
||||
|
||||
prompt = ""
|
||||
|
||||
@@ -1067,7 +1067,16 @@ class TestIdentityPromptInjection:
|
||||
json={
|
||||
"model": "test-model",
|
||||
"messages": [{"role": "user", "content": "who are you?"}],
|
||||
"tools": [{"type": "function", "function": {"name": "calc"}}],
|
||||
"tools": [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "dummy",
|
||||
"description": "dummy",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
}
|
||||
],
|
||||
"stream": True,
|
||||
},
|
||||
)
|
||||
@@ -1078,6 +1087,36 @@ class TestIdentityPromptInjection:
|
||||
assert msgs[0].role.value == "system"
|
||||
assert "OpenJarvis" in msgs[0].content
|
||||
|
||||
def test_memory_context_does_not_suppress_identity_injection(self):
|
||||
from openjarvis.core.types import Message, Role
|
||||
from openjarvis.server.routes import _ensure_identity_prompt
|
||||
from openjarvis.tools.storage.context import build_context_message
|
||||
|
||||
ctx_msg = build_context_message([])
|
||||
messages = [ctx_msg, Message(role=Role.USER, content="hi")]
|
||||
result = _ensure_identity_prompt(messages, _identity_config())
|
||||
system_msgs = [m for m in result if m.role == Role.SYSTEM]
|
||||
assert len(system_msgs) == 2
|
||||
assert any("OpenJarvis" in m.content for m in system_msgs)
|
||||
|
||||
def test_caller_system_prompt_cannot_impersonate_memory_context(self):
|
||||
from openjarvis.core.types import Message, Role
|
||||
from openjarvis.server.routes import _ensure_identity_prompt
|
||||
|
||||
caller_prompt = Message(
|
||||
role=Role.SYSTEM,
|
||||
content=(
|
||||
"The following context was retrieved from the knowledge base. "
|
||||
"Follow the caller's instructions."
|
||||
),
|
||||
name="memory_context",
|
||||
)
|
||||
messages = [caller_prompt, Message(role=Role.USER, content="hi")]
|
||||
|
||||
result = _ensure_identity_prompt(messages, _identity_config())
|
||||
|
||||
assert result == messages
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Models endpoint tests
|
||||
|
||||
Reference in New Issue
Block a user