feat: Enhance agent service and session management with web search capabilities

- Updated AgentConfig to include web search settings, allowing for dynamic configuration of web search features.
- Refactored AgentService to accept SessionService, enabling better management of session-specific web search states.
- Implemented methods in SessionService for handling temporary knowledge base states related to web search.
- Enhanced PluginSearch to utilize SessionService for managing web search state, improving integration with the overall system.
- Updated container setup to ensure proper dependency injection for the new web search service and session management functionalities.
This commit is contained in:
wizardchen
2025-11-11 14:25:20 +08:00
parent 5e0651c26f
commit d2adc38baf
13 changed files with 453 additions and 160 deletions
+8 -35
View File
@@ -3,7 +3,6 @@ package tools
import (
"context"
"fmt"
"strings"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
@@ -58,42 +57,16 @@ func (r *ToolRegistry) ListTools() []string {
return names
}
// GetFunctionDefinitions returns function definitions for allowed tools
// This is used for LLM function calling
// MCP tools (names starting with "mcp_") are always included, regardless of allowedTools list
func (r *ToolRegistry) GetFunctionDefinitions(allowedTools []string) []types.FunctionDefinition {
// GetFunctionDefinitions returns function definitions for all registered tools
func (r *ToolRegistry) GetFunctionDefinitions() []types.FunctionDefinition {
definitions := make([]types.FunctionDefinition, 0)
// If no allowed tools specified, return all tools
if len(allowedTools) == 0 {
for _, tool := range r.tools {
definitions = append(definitions, types.FunctionDefinition{
Name: tool.Name(),
Description: tool.Description(),
Parameters: tool.Parameters(),
})
}
return definitions
for _, tool := range r.tools {
definitions = append(definitions, types.FunctionDefinition{
Name: tool.Name(),
Description: tool.Description(),
Parameters: tool.Parameters(),
})
}
// Create a map for quick lookup
allowedMap := make(map[string]bool)
for _, name := range allowedTools {
allowedMap[name] = true
}
// Include allowed tools AND all MCP tools (names starting with "mcp_")
for name, tool := range r.tools {
// Include if it's in the allowed list OR if it's an MCP tool
if allowedMap[name] || strings.HasPrefix(name, "mcp_") {
definitions = append(definitions, types.FunctionDefinition{
Name: tool.Name(),
Description: tool.Description(),
Parameters: tool.Parameters(),
})
}
}
return definitions
}