Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(skill): use canonical URI for skill indexing (#1781)
Qin Haojie7819d154e594
diff --git a/openviking/utils/skill_processor.py b/openviking/utils/skill_processor.pyindex 1a600a71f..164b143b4 100644--- a/openviking/utils/skill_processor.py+++ b/openviking/utils/skill_processor.py@@ -13,6 +13,8 @@ from copy import deepcopyfrom pathlib import Pathfrom typing import Any, Dict, List, Optional+import yaml+from openviking.core.context import Context, ContextType, Vectorizefrom openviking.core.mcp_converter import is_mcp_format, mcp_to_skillfrom openviking.core.namespace import agent_space_fragment, canonical_agent_root@@ -91,12 +93,13 @@ class SkillProcessor:)skill_dict = await self._sanitize_skill_privacy(skill_dict, ctx)+ skill_abstract = self._build_skill_abstract(skill_dict)context = Context(uri=f"{canonical_agent_root(ctx)}/skills/{skill_dict['name']}",parent_uri=f"{canonical_agent_root(ctx)}/skills",is_leaf=False,- abstract=skill_dict.get("description", ""),+ abstract=skill_abstract,context_type=ContextType.SKILL.value,user=ctx.user,account_id=ctx.account_id,@@ -118,13 +121,14 @@ class SkillProcessor:round((time.perf_counter() - overview_start) * 1000, 3),)- skill_dir_uri = f"viking://agent/skills/{context.meta['name']}"+ skill_dir_uri = context.uriwrite_start = time.perf_counter()await self._write_skill_content(viking_fs=viking_fs,skill_dict=skill_dict,skill_dir_uri=skill_dir_uri,+ abstract=skill_abstract,overview=overview,ctx=ctx,)@@ -210,6 +214,24 @@ class SkillProcessor:return skill_dict, auxiliary_files, base_path+ @staticmethod+ def _build_skill_abstract(skill_dict: Dict[str, Any]) -> str:+ """Build the L0 skill abstract from normalized SKILL.md header metadata."""+ abstract_meta: Dict[str, Any] = {+ "name": skill_dict["name"],+ "description": skill_dict.get("description", ""),+ }++ tags = skill_dict.get("tags")+ if tags:+ abstract_meta["tags"] = tags++ allowed_tools = skill_dict.get("allowed_tools") or skill_dict.get("allowed-tools")+ if allowed_tools:+ abstract_meta["allowed_tools"] = allowed_tools++ return yaml.safe_dump(abstract_meta, allow_unicode=True, sort_keys=False).strip()+async def _sanitize_skill_privacy(self, skill_dict: Dict[str, Any], ctx: RequestContext) -> Dict[str, Any]:@@ -256,6 +278,7 @@ class SkillProcessor:viking_fs: VikingFS,skill_dict: Dict[str, Any],skill_dir_uri: str,+ abstract: str,overview: str,ctx: RequestContext,):@@ -263,7 +286,7 @@ class SkillProcessor:await viking_fs.write_context(uri=skill_dir_uri,content=skill_dict.get("content", ""),- abstract=skill_dict.get("description", ""),+ abstract=abstract,overview=overview,content_filename="SKILL.md",is_leaf=False,@@ -301,7 +324,6 @@ class SkillProcessor:async def _index_skill(self, context: Context, skill_dir_uri: str):"""Write skill directory vector via async queue as L0."""context.uri = skill_dir_uri- context.parent_uri = "viking://agent/skills"context.is_leaf = Falsecontext.level = 0diff --git a/openviking_cli/utils/config/retrieval_config.py b/openviking_cli/utils/config/retrieval_config.pyindex b29c28ecd..2ca613084 100644--- a/openviking_cli/utils/config/retrieval_config.py+++ b/openviking_cli/utils/config/retrieval_config.py@@ -17,7 +17,7 @@ class RetrievalConfig(BaseModel):),)score_propagation_alpha: float = Field(- default=0.5,+ default=0.0,ge=0.0,le=1.0,description=(diff --git a/tests/client/test_skill_management.py b/tests/client/test_skill_management.pyindex aab01d2ca..e0e992c2d 100644--- a/tests/client/test_skill_management.py+++ b/tests/client/test_skill_management.py@@ -8,11 +8,17 @@ from types import SimpleNamespacefrom openviking import AsyncOpenVikingfrom openviking.client import LocalClient+from openviking.core.namespace import canonical_agent_rootfrom openviking.server.identity import RequestContext, Role+from openviking.storage.expr import PathScopefrom openviking.telemetry import get_current_telemetryfrom openviking_cli.session.user_id import UserIdentifier+def _agent_skills_root(client: AsyncOpenViking) -> str:+ return f"{canonical_agent_root(client._client._ctx)}/skills"++class TestAddSkill:"""Test add_skill"""@@ -49,7 +55,14 @@ Use this skill when you need to test skill functionality.assert "root_uri" in resultassert "uri" in resultassert result["root_uri"] == result["uri"]- assert "viking://agent/skills/" in result["uri"]+ assert result["uri"].startswith(f"{_agent_skills_root(client)}/")++ abstract = await client.abstract(result["uri"])+ assert "name: test-skill" in abstract+ assert "description: A test skill for unit testing" in abstract+ assert "tags:" in abstract+ assert "test" in abstract+ assert "unit-test" in abstractasync def test_add_skill_from_string(self, client: AsyncOpenViking):"""Test adding skill from string"""@@ -58,6 +71,8 @@ name: string-skilldescription: A skill created from stringtags:- test+allowed-tools:+ - shell---# String Skill@@ -68,7 +83,15 @@ This skill was created from a string.result = await client.add_skill(data=skill_content)assert "uri" in result- assert "viking://agent/skills/" in result["uri"]+ assert result["uri"].startswith(f"{_agent_skills_root(client)}/")++ abstract = await client.abstract(result["uri"])+ assert "name: string-skill" in abstract+ assert "description: A skill created from string" in abstract+ assert "tags:" in abstract+ assert "test" in abstract+ assert "allowed_tools:" in abstract+ assert "shell" in abstractasync def test_add_skill_with_wait_returns_queue_status(self, client: AsyncOpenViking):"""Test local SDK add_skill(wait=True) preserves queue_status and binds telemetry."""@@ -125,6 +148,7 @@ This skill was created from a string.result = await client.add_skill(data=mcp_tool)assert "uri" in result+ assert result["uri"].startswith(f"{_agent_skills_root(client)}/")async def test_add_skill_from_directory(self, client: AsyncOpenViking, temp_dir: Path):"""Test adding skill from directory"""@@ -154,7 +178,7 @@ This skill was loaded from a directory.result = await client.add_skill(data=skill_dir)assert "uri" in result- assert "viking://agent/skills/" in result["uri"]+ assert result["uri"].startswith(f"{_agent_skills_root(client)}/")class TestSkillSearch:@@ -185,3 +209,56 @@ Use this skill to test search functionality.result = await client.find(query="search functionality")assert hasattr(result, "skills")++ async def test_add_skill_indexes_canonical_agent_uri(+ self, client: AsyncOpenViking, temp_dir: Path+ ):+ """Skill vectors should be stored under the canonical agent root."""+ skill_file = temp_dir / "canonical_scope_skill.md"+ skill_file.write_text(+ """---+name: canonical-scope-skill+description: A skill for testing canonical vector scope+tags:+ - search+ - test+---++# Canonical Scope Skill++## Instructions+Use this skill to test canonical URI vector indexing.+"""+ )++ result = await client.add_skill(data=skill_file, wait=True)+ canonical_uri = f"{_agent_skills_root(client)}/canonical-scope-skill"+ short_uri = "viking://agent/skills/canonical-scope-skill"++ assert result["uri"] == canonical_uri++ vikingdb = client._service.vikingdb_manager+ canonical_count = await vikingdb.count(+ filter=PathScope("uri", canonical_uri, depth=0),+ ctx=client._client._ctx,+ )+ short_count = await vikingdb.count(+ filter=PathScope("uri", short_uri, depth=0),+ ctx=client._client._ctx,+ )++ assert canonical_count == 1+ assert short_count == 0++ records = await vikingdb.filter(+ filter=PathScope("uri", canonical_uri, depth=0),+ limit=10,+ output_fields=["uri", "abstract"],+ ctx=client._client._ctx,+ )+ assert len(records) == 1+ assert records[0]["uri"] == canonical_uri+ assert "name: canonical-scope-skill" in records[0]["abstract"]+ assert "description: A skill for testing canonical vector scope" in records[0]["abstract"]+ assert "tags:" in records[0]["abstract"]+ assert "search" in records[0]["abstract"]diff --git a/tests/server/test_api_local_input_security.py b/tests/server/test_api_local_input_security.pyindex 9564ea163..f3c98914c 100644--- a/tests/server/test_api_local_input_security.py+++ b/tests/server/test_api_local_input_security.py@@ -38,7 +38,7 @@ description: temp uploaded skillassert resp.status_code == 200body = resp.json()assert body["status"] == "ok"- assert body["result"]["uri"].startswith("viking://agent/skills/")+ assert body["result"]["uri"].startswith("viking://agent/default/skills/")async def test_add_skill_rejects_direct_local_path(client: httpx.AsyncClient):@@ -76,7 +76,7 @@ description: inlineassert resp.status_code == 200body = resp.json()assert body["status"] == "ok"- assert body["result"]["uri"].startswith("viking://agent/skills/")+ assert body["result"]["uri"].startswith("viking://agent/default/skills/")def _build_ovpack_bytes() -> bytes:diff --git a/tests/server/test_http_client_sdk.py b/tests/server/test_http_client_sdk.pyindex dda3914a1..9d17a17e4 100644--- a/tests/server/test_http_client_sdk.py+++ b/tests/server/test_http_client_sdk.py@@ -111,7 +111,7 @@ description: SDK localhost upload testassert "root_uri" in resultassert "uri" in resultassert result["root_uri"] == result["uri"]- assert result["uri"].startswith("viking://agent/skills/")+ assert result["uri"].startswith("viking://agent/default/skills/")def _build_ovpack_bytes() -> bytes: