diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index 22b14396..84a4f40a 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -73,7 +73,7 @@ templates: ### Critical Constraints (ABSOLUTE RULES) 1. **Evidence-Based Facts:** For factual claims about documents or domain knowledge, rely on KB/Web retrieval rather than internal knowledge. However, you MAY answer directly when the user's question is about image content you can see, conversational context, or general interaction. - 2. **Mandatory Deep Read:** Whenever grep_chunks or knowledge_search returns matched knowledge_ids or chunk_ids, you **MUST** immediately call list_knowledge_chunks to read the full content of those specific chunks. Do not rely on search snippets alone. + 2. **Mandatory Deep Read:** Whenever grep_chunks or knowledge_search returns matches, you **MUST** read full content before answering. For **FAQ** hits use `list_knowledge_chunks(faq_id=...)` or `get_document_info(faq_ids=[...])` with the **faq_id** from the result — do **not** use the parent knowledge_id of the FAQ container. For **documents**, use `list_knowledge_chunks(knowledge_id=...)` or `get_document_info(knowledge_ids=...)`. Do not rely on search snippets alone. 3. **Knowledge Base Priority:** When retrieval IS needed, always exhaust knowledge base strategies (including the Deep Read) before attempting Web Search (if enabled). 4. **Always Re-Retrieve for Each New Question:** You MUST perform fresh knowledge base retrieval for EVERY new user question that requires factual or domain-specific information, even if a similar or identical question was asked earlier in the conversation. NEVER rely on previously retrieved knowledge base content from the conversation history — the knowledge base may have been updated, switched, or had content removed since the last retrieval. Treat each new question as if you have no prior knowledge from previous retrievals. 5. **User-Friendly Communication:** In ALL outputs visible to users (including your thinking/reasoning process), you MUST: diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 894a573b..a2c1b5fb 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -2701,6 +2701,9 @@ export default { referenceIconAlt: 'Reference materials icon', chunkIdLabel: 'Chunk ID:', documentIdLabel: 'Document ID:', + faqIdLabel: 'FAQ ID:', + faqContainerIdLabel: 'Container ID:', + faqAnswersLabel: 'Answers:', chunkOrdinal: 'Chunk {index}', previewContent: 'Preview content', noPlanSteps: 'No detailed steps provided', @@ -4570,6 +4573,7 @@ export default { getDocument: 'Get document: {title}', document: 'Document', listChunks: 'View {title}', + listFaqEntry: 'View FAQ: {question}', deepThinking: 'Deep Thinking', }, plan: { @@ -4588,6 +4592,7 @@ export default { chunkHits: '{count} chunks', keywordHits: '{count} hits', titleMatch: 'title', + faqEntry: 'FAQ entry', }, toolStatus: { calling: 'Calling {name}...', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index de857327..6d3c76b9 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -806,6 +806,9 @@ export default { referenceIconAlt: "参考内容图标", chunkIdLabel: "片段ID:", documentIdLabel: "文档ID:", + faqIdLabel: "FAQ ID:", + faqContainerIdLabel: "所属文档ID:", + faqAnswersLabel: "答案:", chunkOrdinal: "片段 {index}", previewContent: "预览内容", noPlanSteps: "未提供具体步骤", @@ -4564,6 +4567,7 @@ export default { getDocument: "获取文档:{title}", document: "文档", listChunks: "查看 {title}", + listFaqEntry: "查看 FAQ:{question}", deepThinking: "深度思考", }, plan: { @@ -4582,6 +4586,7 @@ export default { chunkHits: "{count} 片段", keywordHits: "{count} 次", titleMatch: "标题匹配", + faqEntry: "FAQ 条目", }, toolStatus: { calling: "正在调用 {name}...", diff --git a/frontend/src/types/tool-results.ts b/frontend/src/types/tool-results.ts index bdfbe6f0..a51640f3 100644 --- a/frontend/src/types/tool-results.ts +++ b/frontend/src/types/tool-results.ts @@ -105,8 +105,14 @@ export interface KnowledgeBaseListData { // Document info data export interface DocumentInfoDocument { - knowledge_id: string; + knowledge_id?: string; + faq_id?: string; + chunk_id?: string; title: string; + faq_question?: string; + faq_answers?: string[]; + faq_similar_questions?: string[]; + is_faq?: boolean; description?: string; type?: string; source?: string; @@ -204,13 +210,11 @@ export interface WebFetchResultsData { count?: number; } -// Grep knowledge aggregation item +// Grep knowledge aggregation item (legacy, grouped by knowledge_id) export interface GrepKnowledgeResult { knowledge_id: string; knowledge_base_id: string; knowledge_title: string; - // Standard question of the first matched FAQ entry, used as the row label - // since FAQ entries share the owning document's title. faq_question?: string; title_match?: boolean; chunk_hit_count: number; @@ -220,11 +224,28 @@ export interface GrepKnowledgeResult { distinct_patterns: number; } +// Per-chunk grep hit (preferred for UI — one row per FAQ entry or chunk) +export interface GrepChunkResult { + chunk_id: string; + faq_id?: string; + knowledge_id: string; + knowledge_base_id: string; + knowledge_title: string; + chunk_type?: string; + index?: number; + chunk_index?: number; + faq_question?: string; + title_match?: boolean; + match_snippet?: string; + score?: number; +} + // Grep results data export interface GrepResultsData { display_type: 'grep_results'; query?: string; patterns: string[]; + chunk_results?: GrepChunkResult[]; knowledge_results: GrepKnowledgeResult[]; result_count: number; total_matches: number; diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 499ec687..6d9d1de8 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -2080,6 +2080,9 @@ const getToolSummary = (event: any): string => { return t('agentStream.toolSummary.getDocument', { title: toolData.title }); } } else if (toolName === 'list_knowledge_chunks') { + if (toolData?.faq_question) { + return t('agentStream.toolSummary.listFaqEntry', { question: toolData.faq_question }); + } if (toolData?.fetched_chunks !== undefined) { const title = toolData?.knowledge_title || toolData?.knowledge_id || t('agentStream.toolSummary.document'); return t('agentStream.toolSummary.listChunks', { title, fetched: toolData.fetched_chunks, total: toolData.total_chunks ?? '?' }); @@ -2238,7 +2241,8 @@ const getGrepResultsSummary = (toolData: any): string => { if (!toolData) return ''; const totalChunks = toolData.total_matches || 0; - const docCount = toolData.result_count || 0; + const rowCount = + toolData.chunk_results?.length ?? toolData.result_count ?? toolData.knowledge_results?.length ?? 0; if (totalChunks === 0) { return t('agentStream.search.noResults'); @@ -2246,7 +2250,7 @@ const getGrepResultsSummary = (toolData: any): string => { return t('agentStream.search.grepSummary', { chunks: `${totalChunks}`, - docs: `${docCount}`, + docs: `${rowCount}`, }); }; diff --git a/frontend/src/views/chat/components/tool-results/DocumentInfo.vue b/frontend/src/views/chat/components/tool-results/DocumentInfo.vue index 5d3bd638..8827687d 100644 --- a/frontend/src/views/chat/components/tool-results/DocumentInfo.vue +++ b/frontend/src/views/chat/components/tool-results/DocumentInfo.vue @@ -4,7 +4,7 @@