Skip to content

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

fix(bot): use user-scoped resources URI in VikingSearchTool (#4214)

YaCHEN Wangd1fd66eb82b6
diff --git a/bot/tests/test_openviking_api_key_type.py b/bot/tests/test_openviking_api_key_type.py
index 10bb4ea9a..7b5c973f0 100644
--- a/bot/tests/test_openviking_api_key_type.py
+++ b/bot/tests/test_openviking_api_key_type.py
@@ -2555,11 +2555,12 @@ async def test_openviking_search_uses_user_namespace(monkeypatch):
tool_context = SimpleNamespace(workspace_id="workspace", memory_owner_user_ids=["sender-1"])
result = await tool.execute(tool_context, query="hello")
- assert "sender-1/memories" in result
+ assert "memories" in result
assert calls == [
("viking://resources/", None),
- ("viking://user/sender-1/memories/", "sender-1"),
- ("viking://user/sender-1/skills/", "sender-1"),
+ ("viking://~/resources/", "sender-1"),
+ ("viking://~/memories/", "sender-1"),
+ ("viking://~/skills/", "sender-1"),
]
@@ -2591,6 +2592,7 @@ async def test_openviking_search_user_key_mode_uses_current_user_namespace(monke
assert "sender-1/memories" in result
assert calls == [
("viking://resources/", None),
+ ("viking://~/resources/", None),
("viking://~/memories/", None),
("viking://~/skills/", None),
("viking://~/peers/sender-0/memories/", None),
@@ -2644,6 +2646,7 @@ async def test_openviking_search_actor_client_expands_current_peer_scope(monkeyp
assert "sender-0/memories" in result
assert calls == [
("viking://resources/", None),
+ ("viking://~/resources/", None),
("viking://~/memories/", None),
("viking://~/skills/", None),
("viking://~/peers/sender-0/memories/", None),
@@ -2726,7 +2729,8 @@ async def test_openviking_list_default_memory_expands_current_peer(monkeypatch):
)
return uris
- async def list_resources(self, path=None, recursive=False):
+ async def list_resources(self, path=None, recursive=False, node_limit=1000):
+ del node_limit
calls.append((path, recursive))
return []
@@ -2780,6 +2784,7 @@ async def test_openviking_glob_root_adds_current_peer_memory(monkeypatch):
assert calls == [
("*.md", "viking://resources/"),
+ ("*.md", "viking://~/resources/"),
("*.md", "viking://~/memories/"),
("*.md", "viking://~/skills/"),
("*.md", "viking://user/default/peers/sender-0/memories/"),
@@ -2818,8 +2823,9 @@ async def test_openviking_glob_root_uses_namespaced_self_targets_for_root_key(mo
assert calls == [
("*.md", "viking://resources/"),
- ("*.md", "viking://user/admin/memories/"),
- ("*.md", "viking://user/admin/skills/"),
+ ("*.md", "viking://~/resources/"),
+ ("*.md", "viking://~/memories/"),
+ ("*.md", "viking://~/skills/"),
("*.md", "viking://user/admin/peers/sender-0/memories/"),
]
diff --git a/bot/vikingbot/agent/tools/ov_file.py b/bot/vikingbot/agent/tools/ov_file.py
index cd0196926..398c7999c 100644
--- a/bot/vikingbot/agent/tools/ov_file.py
+++ b/bot/vikingbot/agent/tools/ov_file.py
@@ -117,17 +117,12 @@ class OVFileTool(Tool, ABC):
]
)
- def _is_default_memory_uri(self, client: VikingClient, uri: str | None) -> bool:
+ def _is_default_memory_uri(self, uri: str | None) -> bool:
normalized = self._normalize_uri(uri)
# ``viking://user/memories`` is the legacy spelling of the current-user default
# target; it is still accepted here because it survives in stored bot configs and
# LLM output. New emissions always use the ``viking://~`` home alias.
- if normalized in {"", "viking://user/memories", "viking://~/memories"}:
- return True
- try:
- return normalized == self._normalize_uri(client._memory_target_uri(None))
- except Exception:
- return False
+ return normalized in {"", "viking://user/memories", "viking://~/memories"}
def _is_default_root_uri(self, uri: str | None) -> bool:
return self._normalize_uri(uri) in {"", "viking://", "viking://user", "viking://~"}
@@ -146,15 +141,6 @@ class OVFileTool(Tool, ABC):
include_self=False,
)
- def _current_memory_uri(self, client: VikingClient) -> str:
- return client._memory_target_uri(None)
-
- def _current_skill_uri(self, client: VikingClient) -> str:
- memory_uri = self._current_memory_uri(client).rstrip("/")
- if memory_uri.endswith("/memories"):
- return f"{memory_uri[: -len('/memories')]}/skills/"
- return "viking://~/skills/"
-
def _fs_retrieval_uris(
self,
client: VikingClient,
@@ -164,18 +150,19 @@ class OVFileTool(Tool, ABC):
if getattr(client, "actor_peer_id", None):
if self._is_default_root_uri(uri):
return [uri or "viking://"]
- if self._is_default_memory_uri(client, uri):
- return [uri or self._current_memory_uri(client)]
+ if self._is_default_memory_uri(uri):
+ return [uri or "viking://~/memories/"]
return [uri or ""]
- if not self._is_default_memory_uri(client, uri):
+ if not self._is_default_memory_uri(uri):
if not self._is_default_root_uri(uri):
return [uri or ""]
target_uris = [
"viking://resources/",
- self._current_memory_uri(client),
- self._current_skill_uri(client),
+ "viking://~/resources/",
+ "viking://~/memories/",
+ "viking://~/skills/",
*self._peer_memory_uris(client, tool_context),
]
return self._dedupe_strings(target_uris)
@@ -458,13 +445,13 @@ class VikingSearchTool(OVFileTool):
user_ids = memory_owner_user_ids or legacy_memory_user_ids
search_targets: list[tuple[str, str | None]] = [("viking://resources/", None)]
for user_id in self._dedupe_strings(list(user_ids or [])):
- memory_uri = client._memory_target_uri(user_id)
- skill_uri = (
- f"{memory_uri.rstrip('/')[: -len('/memories')]}/skills/"
- if memory_uri.rstrip("/").endswith("/memories")
- else "viking://~/skills/"
+ search_targets.extend(
+ [
+ ("viking://~/resources/", user_id),
+ ("viking://~/memories/", user_id),
+ ("viking://~/skills/", user_id),
+ ]
)
- search_targets.extend([(memory_uri, user_id), (skill_uri, user_id)])
else:
peer_ids = self._memory_peer_ids(tool_context)
if not target_uri:
@@ -475,15 +462,20 @@ class VikingSearchTool(OVFileTool):
target_uris = self._dedupe_strings(
[
"viking://resources/",
- self._current_memory_uri(client),
- self._current_skill_uri(client),
- *self._peer_memory_uris(client, tool_context, peer_ids=peer_ids),
+ "viking://~/resources/",
+ "viking://~/memories/",
+ "viking://~/skills/",
+ *self._peer_memory_uris(
+ client,
+ tool_context,
+ peer_ids=peer_ids,
+ ),
]
)
else:
target_uris = [""]
elif (
- self._is_default_memory_uri(client, target_uri)
+ self._is_default_memory_uri(target_uri)
and not getattr(client, "actor_peer_id", None)
and peer_ids
):