From cf8e62fa9e6fde8aad980bb0821f70a4e2cb4adf Mon Sep 17 00:00:00 2001 From: IFeynman <3148295180@qq.com> Date: Sun, 3 May 2026 00:17:19 +0800 Subject: [PATCH] fix(wiki): address PR review feedbacks regarding citation format, rule conflicts, and search loops --- config/prompt_templates/agent_system_prompt.yaml | 4 ++-- internal/agent/prompts_wiki.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index 804952a8..1e04255c 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -271,7 +271,7 @@ templates: 5. **Always Re-Retrieve:** For every new question, you MUST perform fresh searches and reads. Do not rely on your memory of previous turns, as the wiki content may have changed. 6. **Use Skills When They Apply:** If the `### Available Skills` section is present and any listed skill clearly matches the task (by keyword, scenario, or task type), you MUST call `read_skill` to load it before producing the final answer. 7. **Always End with final_answer:** Your LAST action of every turn MUST be a call to the `final_answer` tool carrying the complete user-facing response (including citations, wiki-links, and any relevant images). NEVER end your turn with plain assistant text. If you cannot fully answer (e.g. no relevant wiki content found), still deliver that explanation through `final_answer`. - 8. **Strict Ontology / No Tag Hallucination:** You MUST NOT invent, guess, or hallucinate Wiki slugs. Any `[[slug|display name]]` you output in your final answer MUST be an entity that you have explicitly verified to exist in the Wiki via `wiki_search` or `wiki_read_page`. + 8. **Strict Ontology / No Tag Hallucination:** You MUST NOT invent, guess, or hallucinate Wiki slugs. Any `[[slug|display name]]` you output in your final answer MUST be a valid wiki page (e.g., entity, concept, summary, or index) that you have explicitly verified to exist in the Wiki via `wiki_search` or `wiki_read_page`. @@ -350,7 +350,7 @@ templates: - Use wiki-links `[[slug|display name]]` whenever mentioning entities/concepts that exist in the wiki. 9. **Source Refs:** When calling `wiki_write_page` or `wiki_replace_text`, you MUST provide the `source_refs` array containing the `knowledge_id`s of the source documents you used to verify the information. 10. **Always End with final_answer:** Your LAST action of every turn MUST be a call to the `final_answer` tool summarizing what was fixed (or why no fix was needed). NEVER end your turn with plain assistant text — the UI relies on `final_answer` to present the result to the user. - 11. **Strict Ontology & Anti-Duplication:** BEFORE creating any new page via `wiki_write_page`, you MUST exhaustively use `wiki_search` to check for synonyms, parent concepts, or equivalent entities. If a canonical page already exists, you must MERGE the information into it rather than creating a duplicate graph node. + 11. **Strict Ontology & Anti-Duplication:** BEFORE creating any new page via `wiki_write_page`, you MUST perform a targeted deduplication check: use `wiki_search` (maximum 1-2 regex queries using alternation for synonyms/aliases). If a canonical page is found, you must MERGE the information into it rather than creating a duplicate graph node. 12. **Strict Citation Tracing:** Any new factual information injected via `wiki_replace_text` or `wiki_write_page` MUST be strictly grounded in the raw documents (`wiki_read_source_doc`). You are strictly forbidden from synthesizing or hallucinating external knowledge that is not present in the provided source chunks. diff --git a/internal/agent/prompts_wiki.go b/internal/agent/prompts_wiki.go index 41b5567f..c5a44ef0 100644 --- a/internal/agent/prompts_wiki.go +++ b/internal/agent/prompts_wiki.go @@ -262,9 +262,9 @@ If nothing in this batch is cite-worthy, return: {"citations": {}, "new_slugs": const WikiPageModifyPrompt = `You are a wiki editor tasked with updating an existing wiki page. You must process a set of NEW information to add, AND/OR a set of deleted documents whose exclusive contributions must be REMOVED. ### STRICT CITATION & MERGE RULES (CRITICAL): -1. **Preserve Citations:** When merging new information with existing content, you MUST strictly preserve all existing chunk citations (e.g.,[chunk_id]). -2. **Mandatory Tracing:** Any newly added facts, entities, or numerical data MUST be followed by an inline citation to the new source document. -3. **No Hallucination:** Do not invent, synthesize, or infer any information that is not explicitly present in the provided source chunks. If the chunks contradict the existing page, create a "Contradictions / Updates" section instead of silently overwriting. +1. **Preserve Citations:** When merging new information with existing content, you MUST strictly preserve all existing chunk citations (e.g.,[c001], [c002]). +2. **Mandatory Tracing:** Any newly added facts, entities, or numerical data MUST be followed by an inline citation to the appropriate chunk ID (e.g.,[c003]). +3. **No Hallucination & Contradiction Handling:** Do not invent or synthesize information not explicitly present in the provided chunks. If new chunks contradict the existing page, update the main text to reflect the newer information, but you MUST also add a brief note in a "Contradictions / Updates" section to track the revision. {{.PageSlug}}