feat: Add Wiki Researcher agent and system prompt for enhanced knowledge retrieval
- Introduced a new built-in agent, "Wiki Researcher," designed for navigating and answering questions based on Wiki knowledge bases, complete with multilingual support. - Added a corresponding system prompt that outlines the agent's role, mission, and workflow for effective knowledge graph traversal. - Updated the agent configuration to include specific tools and parameters tailored for the Wiki Researcher, enhancing its functionality and user interaction. - Removed deprecated wiki tools from the agent service to streamline the toolset and improve performance. These changes significantly enhance the capabilities of the agent framework, providing users with a specialized tool for in-depth Wiki-based research.
This commit is contained in:
@@ -75,8 +75,8 @@ templates:
|
|||||||
### Critical Constraints (ABSOLUTE RULES)
|
### 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.
|
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 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.
|
||||||
3. **KB First, Web Second:** When retrieval IS needed, always exhaust KB strategies (including the Deep Read) before attempting Web Search (if enabled).
|
3. **Knowledge Base Priority:** When retrieval IS needed, always exhaust knowledge base strategies (including the Deep Read) before attempting Web Search (if enabled).
|
||||||
4. **Strict Plan Adherence:** If a todo_write plan exists, execute it sequentially. No skipping.
|
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:
|
5. **User-Friendly Communication:** In ALL outputs visible to users (including your thinking/reasoning process), you MUST:
|
||||||
- Use natural language descriptions instead of internal tool names (e.g., say "搜索知识库" not "knowledge_search", "文本搜索" not "grep_chunks", "阅读文档内容" not "list_knowledge_chunks").
|
- Use natural language descriptions instead of internal tool names (e.g., say "搜索知识库" not "knowledge_search", "文本搜索" not "grep_chunks", "阅读文档内容" not "list_knowledge_chunks").
|
||||||
- Never expose internal IDs (knowledge_base_id, knowledge_id, chunk_id, etc.) in thinking or answers. Refer to documents by their title or name instead.
|
- Never expose internal IDs (knowledge_base_id, knowledge_id, chunk_id, etc.) in thinking or answers. Refer to documents by their title or name instead.
|
||||||
@@ -85,18 +85,16 @@ templates:
|
|||||||
|
|
||||||
### Workflow: The "Assess-Reconnaissance-Plan-Execute" Cycle
|
### Workflow: The "Assess-Reconnaissance-Plan-Execute" Cycle
|
||||||
|
|
||||||
#### Phase 0: Intent Assessment (Before Any Retrieval)
|
#### Intent Assessment
|
||||||
Before initiating any KB search, briefly evaluate the user's request in your think block:
|
Before initiating any search, briefly evaluate the user's request:
|
||||||
* **Direct Answer Path (skip retrieval):** ONLY when the request is:
|
* **If retrieval is unnecessary** — the request is purely conversational (greetings, thanks, farewells), or explicitly asking to describe/read image content with no deeper question (e.g., "帮我读一下图片上的文字", "Describe this image") — proceed directly to **final_answer**.
|
||||||
- Pure conversational interaction (greetings, thanks, farewells)
|
* **Otherwise, proceed to retrieval.** Even if the user asks a question similar to a previous one, you MUST perform a fresh retrieval — do NOT reuse or summarize answers from earlier in the conversation. The knowledge base content may have changed.
|
||||||
- Summarizing or continuing previous discussion from conversation context
|
In most cases, especially when the user uploads an image with a question (e.g., "这是为啥", "这是什么意思", "这张图说的啥"), the user likely wants you to **combine the image content with knowledge base information** to provide an informed answer. Use the image content (OCR text or visual description) as search keywords.
|
||||||
- Explicitly asking to describe/read image content with no deeper question (e.g., "帮我读一下图片上的文字", "Describe this image")
|
Also proceed to retrieval when:
|
||||||
→ Proceed directly to **final_answer**.
|
|
||||||
* **Retrieval Path (default for image + question):** In most cases, especially when the user uploads an image with a question (e.g., "这是为啥", "这是什么意思", "这张图说的啥"), the user likely wants you to **combine the image content with knowledge base information** to provide an informed answer. Use the image content (OCR text or visual description) as search keywords and proceed to Phase 1.
|
|
||||||
Also proceed to Phase 1 when:
|
|
||||||
- The question involves factual, technical, or domain-specific knowledge
|
- The question involves factual, technical, or domain-specific knowledge
|
||||||
- The user asks to find related documents
|
- The user asks to find related documents
|
||||||
- You are uncertain whether the image alone can fully answer the question
|
- You are uncertain whether the image alone can fully answer the question
|
||||||
|
- The user asks the same or a similar question as before (knowledge base may have been updated)
|
||||||
|
|
||||||
#### Phase 1: Preliminary Reconnaissance
|
#### Phase 1: Preliminary Reconnaissance
|
||||||
Perform a "Deep Read" test of the KB to gain preliminary cognition.
|
Perform a "Deep Read" test of the KB to gain preliminary cognition.
|
||||||
|
|||||||
@@ -324,6 +324,37 @@ func countTotalToolCalls(steps []types.AgentStep) int {
|
|||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kbToolNames lists tools whose results contain knowledge base content that
|
||||||
|
// may become stale across turns (KB can be switched, updated, or deleted).
|
||||||
|
// Historical results from these tools are redacted to force fresh retrieval.
|
||||||
|
var kbToolNames = map[string]bool{
|
||||||
|
agenttools.ToolKnowledgeSearch: true,
|
||||||
|
agenttools.ToolGrepChunks: true,
|
||||||
|
agenttools.ToolListKnowledgeChunks: true,
|
||||||
|
agenttools.ToolQueryKnowledgeGraph: true,
|
||||||
|
agenttools.ToolGetDocumentInfo: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// redactHistoryKBResults replaces full KB tool results in historical context
|
||||||
|
// with brief markers. This prevents the LLM from reusing stale retrieval data
|
||||||
|
// when the knowledge base has been modified or switched between turns.
|
||||||
|
func redactHistoryKBResults(llmContext []chat.Message) []chat.Message {
|
||||||
|
redacted := make([]chat.Message, 0, len(llmContext))
|
||||||
|
for _, msg := range llmContext {
|
||||||
|
if msg.Role == "tool" && kbToolNames[msg.Name] {
|
||||||
|
redacted = append(redacted, chat.Message{
|
||||||
|
Role: msg.Role,
|
||||||
|
Content: "[Previous retrieval result omitted — knowledge base may have changed. Please perform a fresh search.]",
|
||||||
|
ToolCallID: msg.ToolCallID,
|
||||||
|
Name: msg.Name,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
redacted = append(redacted, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redacted
|
||||||
|
}
|
||||||
|
|
||||||
// buildMessagesWithLLMContext builds the message array with LLM context
|
// buildMessagesWithLLMContext builds the message array with LLM context
|
||||||
func (e *AgentEngine) buildMessagesWithLLMContext(
|
func (e *AgentEngine) buildMessagesWithLLMContext(
|
||||||
systemPrompt, currentQuery, sessionID string,
|
systemPrompt, currentQuery, sessionID string,
|
||||||
@@ -335,7 +366,10 @@ func (e *AgentEngine) buildMessagesWithLLMContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(llmContext) > 0 {
|
if len(llmContext) > 0 {
|
||||||
for _, msg := range llmContext {
|
// Redact KB tool results from previous turns to prevent the LLM
|
||||||
|
// from reusing stale retrieval data when the KB has been modified.
|
||||||
|
sanitized := redactHistoryKBResults(llmContext)
|
||||||
|
for _, msg := range sanitized {
|
||||||
if msg.Role == "system" {
|
if msg.Role == "system" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -343,7 +377,7 @@ func (e *AgentEngine) buildMessagesWithLLMContext(
|
|||||||
messages = append(messages, msg)
|
messages = append(messages, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Infof(context.Background(), "Added %d history messages to context", len(llmContext))
|
logger.Infof(context.Background(), "Added %d history messages to context (KB tool results redacted)", len(llmContext))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build user message with runtime context safety tag
|
// Build user message with runtime context safety tag
|
||||||
|
|||||||
Reference in New Issue
Block a user