feat: Update agent system prompt and frontend citation handling for wiki sources

- Enhanced the agent system prompt to clarify citation formats for wiki and chunk sources, ensuring accurate inline citations.
- Introduced a new citation format section in the prompt, detailing the required syntax for both wiki pages and knowledge chunks.
- Updated the frontend to visually align wiki citations with knowledge base citations, improving user experience and consistency in citation presentation.
- Implemented truncation for long wiki labels in citations to maintain visual consistency in chat bubbles.

These changes improve the clarity and usability of citations in the agent system, enhancing the overall information retrieval process.
This commit is contained in:
wizardchen
2026-04-21 19:54:33 +08:00
parent 37a517612d
commit b3eab5276c
2 changed files with 78 additions and 7 deletions
@@ -439,18 +439,30 @@ templates:
6. **Synthesize:**
- Build an answer grounded in content actually retrieved this turn.
- Cite every source: wiki pages as `[[slug|display name]]`, chunks as `[knowledge_id#chunk_id]` (or the citation style expected by the product).
- Attach citations inline using the formats defined in `<citation_format>` below.
- When only one surface was reachable, note it briefly ("The bound KB only exposes X, so this answer is drawn entirely from X").
</workflow>
<citation_format>
Use EXACTLY these two formats (any other syntax renders as plain text):
- Chunk (verifiable facts: quotes, numbers, code, names): `<kb doc="..." chunk_id="..." kb_id="..." />`
- Wiki page (concepts / overviews / navigation): `[[slug|display name]]`
All values MUST come from tool results of this turn — never fabricate a `chunk_id`, `kb_id`, or `slug`.
Placement: inline on the same line as the sentence it supports, one per source per paragraph, never grouped at the end, never wrapped in backticks.
Example: WeKnora 采用混合检索。<kb doc="架构设计.md" chunk_id="abc123" kb_id="kb-01" /> 详见 [[hybrid-retrieval|混合检索]]。
</citation_format>
<constraints>
ABSOLUTE RULES:
1. **Evidence-Based Facts:** Ground every factual claim in content you retrieved *this turn*, either from wiki pages or from source chunks.
2. **Wiki Never Replaces RAG for Exact Quotes:** Wiki pages are summaries. If the user asks for a direct quote, numeric value, code, or table row, you MUST read the underlying chunks via `list_knowledge_chunks` or `wiki_read_source_doc`.
2. **Wiki Never Replaces RAG for Exact Quotes:** Wiki pages are summaries. If the user asks for a direct quote, numeric value, code, or table row, you MUST read the underlying chunks via `list_knowledge_chunks` or `wiki_read_source_doc` and cite them with `<kb .../>`.
3. **Mandatory Deep Read:** Whenever `grep_chunks` or `knowledge_search` returns matched `knowledge_id`s / `chunk_id`s, you MUST immediately call `list_knowledge_chunks` to read the full content. Do NOT rely on search snippets.
4. **Mandatory Wiki Read:** `wiki_search` returns summaries only. If a wiki hit is relevant, you MUST call `wiki_read_page` before citing it.
4. **Mandatory Wiki Read:** `wiki_search` returns summaries only. If a wiki hit is relevant, you MUST call `wiki_read_page` before citing it via `[[slug|name]]`.
5. **Always Re-Retrieve:** Every new user question triggers fresh retrieval. Do not reuse retrieved content from earlier turns.
6. **Cite Both Sides:** When your answer draws on wiki context plus chunk evidence, cite both (`[[wiki slug|name]]` + chunk refs). Make the evidence chain explicit.
6. **Cite Both Sides When Both Contributed:** If a claim came from a wiki overview AND was verified against a source chunk, cite both.
7. **Flag Contradictions:** If wiki contradicts source chunks, call `wiki_flag_issue` on the wiki page before submitting the final answer.
</constraints>