Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(recall): mark recalled memory as the user's own history (#6285)

Zayn Jarvis172c8648f8f0
diff --git a/docs/en/gateway/01-how-it-works.md b/docs/en/gateway/01-how-it-works.md
index 8027532cf..886c85e60 100644
--- a/docs/en/gateway/01-how-it-works.md
+++ b/docs/en/gateway/01-how-it-works.md
@@ -30,7 +30,7 @@ When a request ends with a new user message, the gateway searches OpenViking wit
What did we decide about the release date?
<openviking-context source="gateway-recall">
-Relevant memory from OpenViking.
+Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact.
<memory uri="viking://user/alice/memories/events/release-planning.md" type="memory" detail="abstract">
The team moved the 2.0 release to the first week of November.
</memory>
@@ -71,7 +71,7 @@ The OpenViking Gateway, a proxy between the client and the model, added this blo
</openviking-context>
<openviking-context source="gateway-recall">
-Relevant memory from OpenViking. Use the openviking_read tool to expand URIs.
+Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the openviking_read tool to expand URIs.
...
</openviking-context>
```
diff --git a/docs/zh/gateway/01-how-it-works.md b/docs/zh/gateway/01-how-it-works.md
index 746364bcb..b037ee2e9 100644
--- a/docs/zh/gateway/01-how-it-works.md
+++ b/docs/zh/gateway/01-how-it-works.md
@@ -30,7 +30,7 @@ description: OpenViking 网关如何处理一轮对话:召回、对话开头
发布日期最后定在哪天?
<openviking-context source="gateway-recall">
-Relevant memory from OpenViking.
+Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact.
<memory uri="viking://user/alice/memories/events/release-planning.md" type="memory" detail="abstract">
团队把 2.0 版本的发布推迟到了 11 月第一周。
</memory>
@@ -71,7 +71,7 @@ The OpenViking Gateway, a proxy between the client and the model, added this blo
</openviking-context>
<openviking-context source="gateway-recall">
-Relevant memory from OpenViking. Use the openviking_read tool to expand URIs.
+Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the openviking_read tool to expand URIs.
...
</openviking-context>
```
diff --git a/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs b/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs
index b893078b0..cf0f684c9 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs
@@ -473,17 +473,22 @@ function looksLikeUnknownField(res) {
return text.includes("extra") || text.includes("mode") || text.includes("unexpected");
}
+// Recalled text is the user's own history. Without a provenance boundary a model
+// may cite an internal decision as external evidence or industry practice.
+export const RECALL_CONTEXT_TEMPLATE = [
+ "<openviking-context>",
+ "Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the search/read MCP tools to expand URIs.",
+ "{context}",
+ "</openviking-context>",
+].join("\n");
+
function wrapContext(body) {
// Retrieved text cannot introduce a second capture delimiter inside ours.
const text = String(body)
.replace(/<\/?relevant-memor(?:y|ies)\b[^>]*>/gi, "legacy memory wrapper")
.replace(/<\/?openviking-context\b[^>]*>/gi, "openviking context marker");
- return [
- "<openviking-context>",
- "Relevant memory from OpenViking. Use the search/read MCP tools to expand URIs.",
- text,
- "</openviking-context>",
- ].join("\n");
+ // Use a replacer so recalled dollar sequences stay literal.
+ return RECALL_CONTEXT_TEMPLATE.replace("{context}", () => text);
}
/**
diff --git a/examples/codex-memory-plugin/scripts/shared/recall-core.mjs b/examples/codex-memory-plugin/scripts/shared/recall-core.mjs
index b893078b0..cf0f684c9 100644
--- a/examples/codex-memory-plugin/scripts/shared/recall-core.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/recall-core.mjs
@@ -473,17 +473,22 @@ function looksLikeUnknownField(res) {
return text.includes("extra") || text.includes("mode") || text.includes("unexpected");
}
+// Recalled text is the user's own history. Without a provenance boundary a model
+// may cite an internal decision as external evidence or industry practice.
+export const RECALL_CONTEXT_TEMPLATE = [
+ "<openviking-context>",
+ "Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the search/read MCP tools to expand URIs.",
+ "{context}",
+ "</openviking-context>",
+].join("\n");
+
function wrapContext(body) {
// Retrieved text cannot introduce a second capture delimiter inside ours.
const text = String(body)
.replace(/<\/?relevant-memor(?:y|ies)\b[^>]*>/gi, "legacy memory wrapper")
.replace(/<\/?openviking-context\b[^>]*>/gi, "openviking context marker");
- return [
- "<openviking-context>",
- "Relevant memory from OpenViking. Use the search/read MCP tools to expand URIs.",
- text,
- "</openviking-context>",
- ].join("\n");
+ // Use a replacer so recalled dollar sequences stay literal.
+ return RECALL_CONTEXT_TEMPLATE.replace("{context}", () => text);
}
/**
diff --git a/examples/memory-plugin-shared/lib/recall-core.d.mts b/examples/memory-plugin-shared/lib/recall-core.d.mts
index a3f1793d2..b8de9bcff 100644
--- a/examples/memory-plugin-shared/lib/recall-core.d.mts
+++ b/examples/memory-plugin-shared/lib/recall-core.d.mts
@@ -84,3 +84,4 @@ export function estimateTokens(text: string): number;
export function isRecallEnabled(cfg?: Record<string, any>): boolean;
export function selectRecallContent(result?: { rendered?: string; digest?: string; stats?: Record<string, unknown> }): string;
+export const RECALL_CONTEXT_TEMPLATE: string;
diff --git a/examples/memory-plugin-shared/lib/recall-core.mjs b/examples/memory-plugin-shared/lib/recall-core.mjs
index 1c7409f00..3b7661210 100644
--- a/examples/memory-plugin-shared/lib/recall-core.mjs
+++ b/examples/memory-plugin-shared/lib/recall-core.mjs
@@ -472,17 +472,22 @@ function looksLikeUnknownField(res) {
return text.includes("extra") || text.includes("mode") || text.includes("unexpected");
}
+// Recalled text is the user's own history. Without a provenance boundary a model
+// may cite an internal decision as external evidence or industry practice.
+export const RECALL_CONTEXT_TEMPLATE = [
+ "<openviking-context>",
+ "Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the search/read MCP tools to expand URIs.",
+ "{context}",
+ "</openviking-context>",
+].join("\n");
+
function wrapContext(body) {
// Retrieved text cannot introduce a second capture delimiter inside ours.
const text = String(body)
.replace(/<\/?relevant-memor(?:y|ies)\b[^>]*>/gi, "legacy memory wrapper")
.replace(/<\/?openviking-context\b[^>]*>/gi, "openviking context marker");
- return [
- "<openviking-context>",
- "Relevant memory from OpenViking. Use the search/read MCP tools to expand URIs.",
- text,
- "</openviking-context>",
- ].join("\n");
+ // Use a replacer so recalled dollar sequences stay literal.
+ return RECALL_CONTEXT_TEMPLATE.replace("{context}", () => text);
}
/**
diff --git a/examples/memory-plugin-shared/recall-core.test.mjs b/examples/memory-plugin-shared/recall-core.test.mjs
index 8cb45c217..24c1f502f 100644
--- a/examples/memory-plugin-shared/recall-core.test.mjs
+++ b/examples/memory-plugin-shared/recall-core.test.mjs
@@ -87,6 +87,9 @@ test("buildRecallBlock injects context assembled by the server", async () => {
assert.match(block, /^<openviking-context>/);
assert.match(block, /viking:\/\/user\/default\/memories\/a\.md/);
assert.match(block, /<\/openviking-context>$/);
+ // Recalled history is labelled as internal context, not external evidence.
+ assert.match(block, /this user's own saved history/);
+ assert.match(block, /not an external source or established fact/);
});
test("a server-side digest outlasts the ordinary request timeout", async () => {
diff --git a/examples/openclaw-plugin/shared/recall-core.d.mts b/examples/openclaw-plugin/shared/recall-core.d.mts
index 490b6901b..f99082f1e 100644
--- a/examples/openclaw-plugin/shared/recall-core.d.mts
+++ b/examples/openclaw-plugin/shared/recall-core.d.mts
@@ -85,3 +85,4 @@ export function estimateTokens(text: string): number;
export function isRecallEnabled(cfg?: Record<string, any>): boolean;
export function selectRecallContent(result?: { rendered?: string; digest?: string; stats?: Record<string, unknown> }): string;
+export const RECALL_CONTEXT_TEMPLATE: string;
diff --git a/examples/openclaw-plugin/shared/recall-core.mjs b/examples/openclaw-plugin/shared/recall-core.mjs
index b893078b0..cf0f684c9 100644
--- a/examples/openclaw-plugin/shared/recall-core.mjs
+++ b/examples/openclaw-plugin/shared/recall-core.mjs
@@ -473,17 +473,22 @@ function looksLikeUnknownField(res) {
return text.includes("extra") || text.includes("mode") || text.includes("unexpected");
}
+// Recalled text is the user's own history. Without a provenance boundary a model
+// may cite an internal decision as external evidence or industry practice.
+export const RECALL_CONTEXT_TEMPLATE = [
+ "<openviking-context>",
+ "Relevant memory from OpenViking. It is this user's own saved history (past conversations, meetings, notes) as recorded then: internal context, not an external source or established fact. Use the search/read MCP tools to expand URIs.",
+ "{context}",
+ "</openviking-context>",
+].join("\n");
+
function wrapContext(body) {
// Retrieved text cannot introduce a second capture delimiter inside ours.
const text = String(body)
.replace(/<\/?relevant-memor(?:y|ies)\b[^>]*>/gi, "legacy memory wrapper")
.replace(/<\/?openviking-context\b[^>]*>/gi, "openviking context marker");
- return [
- "<openviking-context>",
- "Relevant memory from OpenViking. Use the search/read MCP tools to expand URIs.",
- text,
- "</openviking-context>",
- ].join("\n");
+ // Use a replacer so recalled dollar sequences stay literal.
+ return RECALL_CONTEXT_TEMPLATE.replace("{context}", () => text);
}
/**
diff --git a/openviking_gateway/blocks.py b/openviking_gateway/blocks.py
index 4c0f23e6c..edffdcc22 100644
--- a/openviking_gateway/blocks.py
+++ b/openviking_gateway/blocks.py
@@ -48,6 +48,14 @@ def block(source, text):
)
+# Recalled text is the user's own history. Without a provenance boundary a model may
+# cite an internal decision as external evidence or industry practice.
+RECALL_PROVENANCE_NOTE = (
+ "It is this user's own saved history (past conversations, meetings, notes) as recorded "
+ "then: internal context, not an external source or established fact."
+)
+
+
def gateway_note(policy, tools):
"""Opening lines that tell the model what the gateway adds to this history."""
if not (policy.recall or tools):
diff --git a/openviking_gateway/kernel.py b/openviking_gateway/kernel.py
index 59de1d037..78a75246c 100644
--- a/openviking_gateway/kernel.py
+++ b/openviking_gateway/kernel.py
@@ -10,7 +10,7 @@ from dataclasses import dataclass, field, replace
import orjson
-from .blocks import block, gateway_note, history_hint, token_estimate
+from .blocks import RECALL_PROVENANCE_NOTE, block, gateway_note, history_hint, token_estimate
from .capture import CapturePipeline, lineage
from .capture_store import Document
from .client import VikingError
@@ -512,7 +512,7 @@ class MemoryKernel:
budget = await self.reserve_recall(request, policy, used, window)
reserved = budget > 0
tools = request.root["tools"]
- lead = "Relevant memory from OpenViking."
+ lead = f"Relevant memory from OpenViking. {RECALL_PROVENANCE_NOTE}"
if any(tool["function"]["name"] == "openviking_read" for tool in tools):
lead += " Use the openviking_read tool to expand URIs."
overhead = token_estimate(block("gateway-recall", lead + "\n"))
diff --git a/tests/gateway/test_kernel.py b/tests/gateway/test_kernel.py
index 103f532fe..773dd38a7 100644
--- a/tests/gateway/test_kernel.py
+++ b/tests/gateway/test_kernel.py
@@ -9,7 +9,7 @@ import pytest
from conftest import replay_records
from openviking_gateway import protocols
-from openviking_gateway.blocks import gateway_note
+from openviking_gateway.blocks import RECALL_PROVENANCE_NOTE, gateway_note
from openviking_gateway.capture import CaptureWorker, capture_messages
from openviking_gateway.capture_store import Document
from openviking_gateway.client import VikingError
@@ -133,7 +133,7 @@ NOTE = (
"Tool names in their descriptions omit the openviking_ prefix.\n"
"- The gateway saves this conversation to the user's OpenViking memory."
)
-LEAD = "Relevant memory from OpenViking."
+LEAD = "Relevant memory from OpenViking. " + RECALL_PROVENANCE_NOTE
@pytest.mark.parametrize("protocol", ["chat", "anthropic", "responses"])
@@ -150,6 +150,9 @@ async def test_first_injection_opens_with_gateway_note(setup_kernel, credential,
note, recalled = context_blocks(one.body[field][0])
assert note == NOTE + "\n</openviking-context>"
assert LEAD + " Use the openviking_read tool to expand URIs.\n" in recalled
+ # Recalled history is labelled as internal context, not external evidence.
+ assert "user's own saved history" in recalled
+ assert "not an external source or established fact" in recalled
assert "Deploy using the blue cluster." in recalled
# The note is replayed with recall but stays outside the recall budget.
decision = (await replay_records(store, one, "injection"))["injection", one.chain[0]]