feat: Enhance MCP tools registration and management with context support
- Updated RegisterMCPTools and GetMCPToolsInfo functions to accept a context parameter, improving control over timeouts and cancellations. - Implemented timeout handling for ListTools operations to prevent hanging during long-running requests. - Enhanced GetFunctionDefinitions to include all MCP tools regardless of the allowed tools list, ensuring comprehensive tool access. - Improved MCP service management by adding checks for service enabled state and critical configuration changes, ensuring robust client connection handling. - Refactored session handling to utilize AgentModeEnabled for better session configuration management.
This commit is contained in:
@@ -62,7 +62,7 @@ func (h *Handler) CreateSession(c *gin.Context) {
|
||||
// - Knowledge base can be specified in each query request (AgentQA/KnowledgeQA)
|
||||
// - Agent mode can access multiple knowledge bases via AgentConfig.KnowledgeBases
|
||||
// - Knowledge base can be switched during conversation
|
||||
isAgentMode := request.AgentConfig != nil && request.AgentConfig.Enabled
|
||||
isAgentMode := request.AgentConfig != nil && request.AgentConfig.AgentModeEnabled
|
||||
hasAgentKnowledgeBases := request.AgentConfig != nil && len(request.AgentConfig.KnowledgeBases) > 0
|
||||
|
||||
logger.Infof(
|
||||
|
||||
@@ -151,6 +151,8 @@ func (h *Handler) AgentQA(c *gin.Context) {
|
||||
|
||||
logger.Infof(ctx, "Agent QA request, session ID: %s, query: %s", sessionID, request.Query)
|
||||
|
||||
tenantInfo := ctx.Value(types.TenantInfoContextKey).(*types.Tenant)
|
||||
|
||||
// Get session information first
|
||||
session, err := h.sessionService.GetSession(ctx, sessionID)
|
||||
if err != nil {
|
||||
@@ -213,6 +215,14 @@ func (h *Handler) AgentQA(c *gin.Context) {
|
||||
logger.Infof(ctx, "Web search mode changed from %v to %v", currentWebSearchEnabled, request.WebSearchEnabled)
|
||||
configChanged = true
|
||||
}
|
||||
summaryModelID := request.SummaryModelID
|
||||
if summaryModelID == "" {
|
||||
summaryModelID = tenantInfo.AgentConfig.ThinkingModelID
|
||||
}
|
||||
if summaryModelID != session.SummaryModelID {
|
||||
configChanged = true
|
||||
session.SummaryModelID = summaryModelID
|
||||
}
|
||||
|
||||
// If configuration changed, clear context and update session
|
||||
if configChanged {
|
||||
@@ -230,6 +240,7 @@ func (h *Handler) AgentQA(c *gin.Context) {
|
||||
session.AgentConfig.KnowledgeBases = request.KnowledgeBaseIDs
|
||||
session.AgentConfig.AgentModeEnabled = request.AgentEnabled
|
||||
session.AgentConfig.WebSearchEnabled = request.WebSearchEnabled
|
||||
session.SummaryModelID = summaryModelID
|
||||
// Persist the session changes
|
||||
if err := h.sessionService.UpdateSession(ctx, session); err != nil {
|
||||
logger.Errorf(ctx, "Failed to update session %s: %v", sessionID, err)
|
||||
|
||||
Reference in New Issue
Block a user