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
+20 -20
View File
@@ -23,15 +23,15 @@ func generateEventID(suffix string) string {
// AgentEngine is the core engine for running ReAct agents
type AgentEngine struct {
config *types.AgentConfig
toolRegistry *tools.ToolRegistry
chatModel chat.Chat
knowledgeService interfaces.KnowledgeBaseService
eventBus *event.EventBus
knowledgeBasesInfo []*KnowledgeBaseInfo // Detailed knowledge base information for prompt
contextManager interfaces.ContextManager // Context manager for writing agent conversation to LLM context
sessionID string // Session ID for context management
systemPromptTemplate string // System prompt template (optional, uses default if empty)
config *types.AgentConfig
toolRegistry *tools.ToolRegistry
chatModel chat.Chat
knowledgeService interfaces.KnowledgeBaseService
eventBus *event.EventBus
knowledgeBasesInfo []*KnowledgeBaseInfo // Detailed knowledge base information for prompt
contextManager interfaces.ContextManager // Context manager for writing agent conversation to LLM context
sessionID string // Session ID for context management
systemPromptTemplate string // System prompt template (optional, uses default if empty)
}
// listToolNames returns tool.function names for logging
@@ -59,14 +59,14 @@ func NewAgentEngine(
eventBus = event.NewEventBus()
}
return &AgentEngine{
config: config,
toolRegistry: toolRegistry,
chatModel: chatModel,
knowledgeService: knowledgeService,
eventBus: eventBus,
knowledgeBasesInfo: knowledgeBasesInfo,
contextManager: contextManager,
sessionID: sessionID,
config: config,
toolRegistry: toolRegistry,
chatModel: chatModel,
knowledgeService: knowledgeService,
eventBus: eventBus,
knowledgeBasesInfo: knowledgeBasesInfo,
contextManager: contextManager,
sessionID: sessionID,
systemPromptTemplate: systemPromptTemplate,
}
}
@@ -391,7 +391,7 @@ func (e *AgentEngine) executeLoop(
// buildToolsForLLM builds the tools list for LLM function calling
func (e *AgentEngine) buildToolsForLLM() []chat.Tool {
functionDefs := e.toolRegistry.GetFunctionDefinitions(e.config.AllowedTools)
functionDefs := e.toolRegistry.GetFunctionDefinitions()
tools := make([]chat.Tool, 0, len(functionDefs))
for _, def := range functionDefs {
tools = append(tools, chat.Tool{
@@ -601,8 +601,8 @@ func (e *AgentEngine) streamThinkingToEventBus(
opts,
func(chunk *types.StreamResponse, fullContent string) {
if chunk.Content != "" {
logger.Debugf(ctx, "[Agent][Thinking][Iteration-%d] Emitting thought chunk: %d chars",
iteration+1, len(chunk.Content))
// logger.Debugf(ctx, "[Agent][Thinking][Iteration-%d] Emitting thought chunk: %d chars",
// iteration+1, len(chunk.Content))
e.eventBus.Emit(ctx, event.Event{
ID: thinkingID, // Same ID for all chunks in this stream
Type: event.EventAgentThought,