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
perf(retrieval): align default intent planner with compact v4 prompt (#6039)
Zayn Jarvisb8ec9d8210ab
diff --git a/openviking/prompts/templates/retrieval/intent_analysis.yaml b/openviking/prompts/templates/retrieval/intent_analysis.yamlindex 15b055ceb..fb5a5288a 100644--- a/openviking/prompts/templates/retrieval/intent_analysis.yaml+++ b/openviking/prompts/templates/retrieval/intent_analysis.yaml@@ -1,8 +1,8 @@metadata:id: "retrieval.intent_analysis"name: "Intent Analysis"- description: "Analyze session context to generate query plans for different context types"- version: "2.1.0"+ description: "Generate compact query plans for different context types"+ version: "2.2.0"language: "en"category: "retrieval"@@ -36,7 +36,7 @@ variables:required: falsetemplate: |- You are OpenViking's context query planner, responsible for analyzing task context gaps and generating queries.+ You are OpenViking's context query planner. Given the session context and the current message, decide what context information is missing and emit retrieval queries to fill the gap.## Session Context@@ -57,119 +57,35 @@ template: |**Target Directory Abstract**: {{ target_abstract }}{% endif %}- **Important**: You can only generate `{{ context_type }}` type queries, do not generate other types.+ Only emit `{{ context_type }}` queries; do not generate other types.{% endif %}- ## Your Task+ External information takes priority over built-in knowledge - actively query for any missing context.- Analyze the current task, identify context gaps, and generate queries to fill in the required information.+ ## Context Types- **Core Principle**: OpenViking's external information takes priority over built-in knowledge, actively query external context.+ - `skill` - executable capability (tool, function, API, automation). Query style: imperative starting with a verb.+ - `resource` - knowledge artifact (doc, spec, guide, code, configuration). Query style: noun phrase.+ - `memory` - user preference or agent execution experience.- ## Context Types and Query Styles+ ## Procedure- OpenViking supports the following context types, **each type has a different query style**:+ 1. Classify the task: operational tasks typically need skill+resource+memory; informational tasks typically need resource+memory; conversational small talk needs no query.+ 2. Skip any context type already covered explicitly in the conversation.+ 3. For each needed type, emit 1-5 concise retrievable queries with `priority` from 1 to 5.- ### 1. skill (Execution Capability)-- **Purpose**: Executable tools, functions, APIs, automation scripts-- **When to Query**:- - Task contains action verbs (create, generate, write, build, analyze, process)- - Need to perform specific operations-- ### 2. resource (Knowledge Resources)-- **Purpose**: Documents, specifications, guides, code, configurations, and other structured knowledge-- **When to Query**:- - Need reference materials, templates, specifications- - Need to understand knowledge, concepts, definitions-- ### 3. memory (User/Agent Memory)-- **Purpose**: User personalization information or Agent execution experience-- **When to Query**:- - Need personalized customization (user memory)- - Need to learn from historical experience (agent memory)-- ## Analysis Method-- ### Step 1: Identify Task Type-- **Operational Tasks** (containing actions):- - Characteristics: Verbs like create, generate, write, build, transform, calculate, analyze, process- - Typical context combination: `skill + resource + memory`-- **Informational Tasks** (acquiring knowledge):- - Characteristics: What is, how to understand, why, concept explanation, etc.- - Typical context combination: `resource + memory`-- **Conversational Tasks** (small talk):- - Characteristics: Greetings, small talk, confirmation of understanding, etc.- - Usually no query needed-- ### Step 2: Check Context Coverage-- Analyze whether the session context (summary + recent conversation) already contains the information needed to complete the task:-- - **Fully covered**: Skip queries for that type- - **Partially covered**: Generate supplementary queries- - **Not covered**: Generate complete queries-- **Note**: Only skip information that has been **explicitly and in detail** discussed in the context.-- ### Step 3: Generate Queries-- **Important Principles**:-- 1. **Don't over-transform**:- - ❌ Don't convert "Create XX" to "XX format/specification"-- 2. **Multi-type combination**:- - A task may require multiple context types- - Operational tasks typically need: skill (execution) + resource (reference) + memory (preference/experience)-- 3. **Multiple queries per type**:- - Can generate multiple queries for the same type- - Maximum 5 queries-- 4. **Queries should be concise and specific**:- - Queries should be short, specific, and retrievable- - Avoid lengthy descriptions+ ## Output Format- 5. **Priority setting**:- - 1 = Highest priority (core requirement)- - 3 = Medium priority (helpful)- - 5 = Lowest priority (optional)+ Output a single JSON object with exactly one top-level key:- 6. **Query Style** (optimize for vector / semantic retrieval):- - Queries are embedded and matched against indexed content by **semantic similarity**. Write each query so its embedding lands close to the target content — not necessarily a verbatim fragment, any phrasing that captures the same meaning works.- - **Declarative, not interrogative**: state the information need as a noun/verb phrase rather than a question. Drop question framings ("what / who / when / how is ...").- - **One information need per query**: each query targets one retrievable fact, relation, comparison, event, or procedure. Do not pile unrelated intents into one query.- - **Self-contained**: resolve pronouns and references using the session context; the retriever only sees the query string.- - **Concept-dense and natural**: use a grammatical, well-formed phrase carrying the key entities, attributes, and qualifiers. Avoid both bare single keywords and telegraphic word-salad.- - **No retrieval-meta words**: exclude words describing the act of retrieval or generic containers ("find", "search", "records", "information about", "content", "details", etc.) — they do not appear in the target content and only dilute the embedding.- - **Keep discriminative specifics**: preserve names, dates, places, and domain terms from the task — they anchor the embedding to the right content.+ - `queries`: array of objects with:+ - `query`: actual query text+ - `context_type`: one of `skill`, `resource`, `memory`+ - `priority`: integer from 1 to 5- ## Output Format+ If no query is needed, set `queries` to an empty array `[]`.- ```json- {- "reasoning": "1. Task type (operational/informational/conversational); 2. What context is needed (skill/resource/memory); 3. What is already in context; 4. What is missing and needs to be queried",- "queries": [- {- "query": "Specific query text (following the style of the corresponding type)",- "context_type": "skill|resource|memory",- "intent": "Purpose of the query",- "priority": 1-5- }- ]- }- ```-- Please output JSON:+ Output the JSON object directly. Do not wrap it in markdown code fences.llm_config:temperature: 0.0diff --git a/tests/prompts/test_retrieval_intent_prompt_contract.py b/tests/prompts/test_retrieval_intent_prompt_contract.pyindex 474389464..2f54462ba 100644--- a/tests/prompts/test_retrieval_intent_prompt_contract.py+++ b/tests/prompts/test_retrieval_intent_prompt_contract.py@@ -9,11 +9,12 @@ from openviking.prompts.manager import PromptManager@pytest.mark.parametrize("prompt_id",[+ "retrieval.intent_analysis","retrieval.ov_intent_analysis_sft_v4","retrieval.ov_intent_analysis_sft_v7",],)-def test_sft_intent_prompts_use_compact_queries_contract(prompt_id: str):+def test_intent_prompts_use_compact_queries_contract(prompt_id: str):manager = PromptManager(templates_dir=PromptManager._get_bundled_templates_dir())rendered = manager.render(prompt_id,@@ -34,3 +35,18 @@ def test_sft_intent_prompts_use_compact_queries_contract(prompt_id: str):assert "priority" in output_contractassert '"reasoning"' not in output_contractassert '"intent"' not in output_contract+++def test_default_intent_prompt_matches_v4_contract():+ manager = PromptManager(templates_dir=PromptManager._get_bundled_templates_dir())+ variables = {+ "compression_summary": "The user is working on OpenViking retrieval.",+ "recent_messages": "[user]: Improve semantic search.",+ "current_message": "Use the style we discussed earlier.",+ "context_type": "resource",+ "target_abstract": "OpenViking retrieval documentation.",+ }++ assert manager.render("retrieval.intent_analysis", variables) == manager.render(+ "retrieval.ov_intent_analysis_sft_v4", variables+ )diff --git a/tests/retrieve/test_intent_analyzer_query_planner.py b/tests/retrieve/test_intent_analyzer_query_planner.pyindex b805bbbb2..da8ce03f0 100644--- a/tests/retrieve/test_intent_analyzer_query_planner.py+++ b/tests/retrieve/test_intent_analyzer_query_planner.py@@ -153,6 +153,35 @@ async def test_intent_analyzer_handles_bare_array_response(monkeypatch):assert result.reasoning == ""+async def test_intent_analyzer_handles_compact_object_response(monkeypatch):+ planner = RecordingModel(+ """{+ "queries": [+ {+ "query": "compact query",+ "context_type": "resource",+ "priority": 2+ }+ ]+ }"""+ )+ monkeypatch.setattr(intent_module, "render_prompt", lambda prompt_id, variables: "prompt")++ result = await IntentAnalyzer(query_planner=planner).analyze(+ compression_summary="",+ messages=[],+ current_message="find the relevant documentation",+ )++ assert len(result.queries) == 1+ assert result.queries[0].query == "compact query"+ assert result.queries[0].context_type.value == "resource"+ assert result.queries[0].intent == ""+ assert result.queries[0].priority == 2+ assert result.reasoning == ""++@pytest.mark.asyncioasync def test_intent_analyzer_uses_model_specific_prompt(monkeypatch):planner = RecordingModel(