From e9ed8d1961609af0b9fad3f52c211653b8ed8308 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 20 Apr 2026 19:17:48 +0800 Subject: [PATCH] feat: Enhance wiki navigation and citation handling in AgentStreamDisplay and WikiBrowser - Updated the agent system prompt to require wiki-links in citations, improving user navigation to source pages. - Implemented logic in AgentStreamDisplay to handle wiki link clicks and keyboard interactions, facilitating seamless navigation to knowledge base wiki pages. - Enhanced WikiBrowser to auto-select pages based on query parameters, improving user experience when accessing specific wiki content. - Added localization support for new error messages related to knowledge base identification, ensuring clarity in user interactions. These changes significantly improve the usability and functionality of the wiki navigation system, providing users with a more intuitive experience when accessing and citing wiki content. --- .../prompt_templates/agent_system_prompt.yaml | 3 +- frontend/src/i18n/locales/en-US.ts | 1 + frontend/src/i18n/locales/zh-CN.ts | 1 + .../chat/components/AgentStreamDisplay.vue | 125 +++++++++++++++++- .../src/views/knowledge/wiki/WikiBrowser.vue | 32 ++++- internal/agent/tools/wiki_tools.go | 26 +++- 6 files changed, 175 insertions(+), 13 deletions(-) diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index cfebcae5..794b004f 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -262,7 +262,7 @@ templates: ABSOLUTE RULES: 1. **Never Guess:** Never rely on your internal knowledge. Only answer based on what you have successfully read via `wiki_read_page`. 2. **Mandatory Reading:** `wiki_search` only returns summaries. You CANNOT write a final answer based solely on `wiki_search` results. You MUST call `wiki_read_page` on the relevant slugs to get the actual facts. - 3. **Cite Sources:** Your final answer must clearly state which wiki pages you derived the information from. + 3. **Cite Sources:** Your final answer must clearly state which wiki pages you derived the information from, and MUST include wiki-links to them in the format `[[slug|display name]]` so the user can click them to navigate. 4. **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. @@ -336,6 +336,7 @@ templates: - Use proper heading hierarchy (`##` for sections, `###` for subsections). - Include a "## Key Takeaways" section with bullet points at the end. - Preserve any valid image links `![alt](url)`. + - 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. diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 936d3f34..719c9b07 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -3413,6 +3413,7 @@ export default { notFound: 'Content not found', loadFailed: 'Failed to load', chunkId: 'Chunk ID', + noKbForWiki: 'Unable to identify associated knowledge base. Cannot open Wiki.', }, toolSummary: { getDocument: 'Get document: {title}', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 9c56e3b8..1bdb17af 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -3411,6 +3411,7 @@ export default { notFound: "未找到内容", loadFailed: "加载失败", chunkId: "片段ID", + noKbForWiki: "无法识别关联的知识库,无法打开 Wiki", }, toolSummary: { getDocument: "获取文档:{title}", diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index d98f7cc9..d249d38f 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -339,7 +339,7 @@