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:
wizardchen
2026-04-09 12:27:50 +08:00
parent 4715b10642
commit 5545b852c8
2 changed files with 45 additions and 13 deletions
+36 -2
View File
@@ -324,6 +324,37 @@ func countTotalToolCalls(steps []types.AgentStep) int {
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
func (e *AgentEngine) buildMessagesWithLLMContext(
systemPrompt, currentQuery, sessionID string,
@@ -335,7 +366,10 @@ func (e *AgentEngine) buildMessagesWithLLMContext(
}
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" {
continue
}
@@ -343,7 +377,7 @@ func (e *AgentEngine) buildMessagesWithLLMContext(
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