feat: Refactor agent configuration by removing deprecated parameters and enhancing conversation model management
- Removed the `thinkingModelId` and `rerankModelId` from agent configuration, streamlining the settings structure. - Introduced a new `conversationModels` interface to manage summary and rerank model IDs. - Updated related UI components and API logic to accommodate the changes in agent configuration. - Enhanced localization for new conversation model settings in English, Russian, and Chinese.
This commit is contained in:
@@ -64,6 +64,8 @@ func NewAgentService(
|
||||
func (s *agentService) CreateAgentEngine(
|
||||
ctx context.Context,
|
||||
config *types.AgentConfig,
|
||||
chatModel chat.Chat,
|
||||
rerankModel rerank.Reranker,
|
||||
eventBus *event.EventBus,
|
||||
contextManager interfaces.ContextManager,
|
||||
sessionID string,
|
||||
@@ -76,20 +78,10 @@ func (s *agentService) CreateAgentEngine(
|
||||
return nil, fmt.Errorf("invalid agent config: %w", err)
|
||||
}
|
||||
|
||||
chatModel, err := s.modelService.GetChatModel(ctx, config.ThinkingModelID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get thinking model: %w", err)
|
||||
}
|
||||
|
||||
if chatModel == nil {
|
||||
return nil, fmt.Errorf("chat model is nil after initialization")
|
||||
}
|
||||
|
||||
rerankModel, err := s.modelService.GetRerankModel(ctx, config.RerankModelID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get rerank model: %w", err)
|
||||
}
|
||||
|
||||
if rerankModel == nil {
|
||||
return nil, fmt.Errorf("rerank model is nil after initialization")
|
||||
}
|
||||
@@ -264,10 +256,6 @@ func (s *agentService) ValidateConfig(config *types.AgentConfig) error {
|
||||
return fmt.Errorf("max iterations too high: %d (max %d)", config.MaxIterations, MAX_ITERATIONS)
|
||||
}
|
||||
|
||||
if config.ThinkingModelID == "" {
|
||||
return fmt.Errorf("ThinkingModelID is required but not set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -878,8 +878,6 @@ func (s *sessionService) AgentQA(ctx context.Context, session *types.Session, qu
|
||||
ReflectionEnabled: tenantInfo.AgentConfig.ReflectionEnabled,
|
||||
AllowedTools: tenantInfo.AgentConfig.AllowedTools,
|
||||
Temperature: tenantInfo.AgentConfig.Temperature,
|
||||
ThinkingModelID: tenantInfo.AgentConfig.ThinkingModelID,
|
||||
RerankModelID: tenantInfo.AgentConfig.RerankModelID,
|
||||
KnowledgeBases: session.AgentConfig.KnowledgeBases, // Use session's knowledge bases
|
||||
WebSearchEnabled: session.AgentConfig.WebSearchEnabled, // Web search enabled from session config
|
||||
}
|
||||
@@ -931,19 +929,36 @@ func (s *sessionService) AgentQA(ctx context.Context, session *types.Session, qu
|
||||
logger.Infof(ctx, "Agent configured with %d knowledge base(s): %v", len(agentConfig.KnowledgeBases), agentConfig.KnowledgeBases)
|
||||
}
|
||||
|
||||
// Set ThinkingModelID from session's SummaryModelID if not already set in tenant config
|
||||
if agentConfig.ThinkingModelID == "" && session.SummaryModelID != "" {
|
||||
agentConfig.ThinkingModelID = session.SummaryModelID
|
||||
logger.Infof(ctx, "Using session's SummaryModelID as ThinkingModelID: %s", session.SummaryModelID)
|
||||
summaryModelID := session.SummaryModelID
|
||||
if summaryModelID == "" && tenantInfo.ConversationConfig != nil {
|
||||
summaryModelID = tenantInfo.ConversationConfig.SummaryModelID
|
||||
}
|
||||
if summaryModelID == "" {
|
||||
logger.Warnf(ctx, "No summary model configured for tenant %d or session %s", tenantInfo.ID, session.ID)
|
||||
return errors.New("summary model is not configured in conversation settings")
|
||||
}
|
||||
|
||||
// Get chat model
|
||||
summaryModel, err := s.modelService.GetChatModel(ctx, agentConfig.ThinkingModelID)
|
||||
summaryModel, err := s.modelService.GetChatModel(ctx, summaryModelID)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to get chat model: %v", err)
|
||||
return fmt.Errorf("failed to get chat model: %w", err)
|
||||
}
|
||||
|
||||
rerankModelID := session.RerankModelID
|
||||
if rerankModelID == "" && tenantInfo.ConversationConfig != nil {
|
||||
rerankModelID = tenantInfo.ConversationConfig.RerankModelID
|
||||
}
|
||||
if rerankModelID == "" {
|
||||
logger.Warnf(ctx, "No rerank model configured for tenant %d or session %s", tenantInfo.ID, session.ID)
|
||||
return errors.New("rerank model is not configured in conversation settings")
|
||||
}
|
||||
|
||||
rerankModel, err := s.modelService.GetRerankModel(ctx, rerankModelID)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to get rerank model: %v", err)
|
||||
return fmt.Errorf("failed to get rerank model: %w", err)
|
||||
}
|
||||
|
||||
// Get or create contextManager for this session
|
||||
contextManager := s.getContextManagerForSession(ctx, session, summaryModel)
|
||||
// Get LLM context from context manager
|
||||
@@ -956,7 +971,7 @@ func (s *sessionService) AgentQA(ctx context.Context, session *types.Session, qu
|
||||
|
||||
// Create agent engine with EventBus and ContextManager
|
||||
logger.Info(ctx, "Creating agent engine")
|
||||
engine, err := s.agentService.CreateAgentEngine(ctx, agentConfig, eventBus, contextManager, session.ID, s)
|
||||
engine, err := s.agentService.CreateAgentEngine(ctx, agentConfig, summaryModel, rerankModel, eventBus, contextManager, session.ID, s)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Failed to create agent engine: %v", err)
|
||||
return err
|
||||
|
||||
@@ -226,7 +226,10 @@ func (h *Handler) AgentQA(c *gin.Context) {
|
||||
}
|
||||
summaryModelID := request.SummaryModelID
|
||||
if summaryModelID == "" {
|
||||
summaryModelID = tenantInfo.AgentConfig.ThinkingModelID
|
||||
summaryModelID = session.SummaryModelID
|
||||
}
|
||||
if summaryModelID == "" && tenantInfo.ConversationConfig != nil {
|
||||
summaryModelID = tenantInfo.ConversationConfig.SummaryModelID
|
||||
}
|
||||
if summaryModelID != session.SummaryModelID {
|
||||
configChanged = true
|
||||
|
||||
@@ -238,8 +238,6 @@ type AgentConfigRequest struct {
|
||||
ReflectionEnabled bool `json:"reflection_enabled"`
|
||||
AllowedTools []string `json:"allowed_tools"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
ThinkingModelID string `json:"thinking_model_id"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"`
|
||||
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"`
|
||||
UseCustomPrompt *bool `json:"use_custom_system_prompt"`
|
||||
@@ -287,8 +285,6 @@ func (h *TenantHandler) GetTenantAgentConfig(c *gin.Context) {
|
||||
"reflection_enabled": agent.DefaultAgentReflectionEnabled,
|
||||
"allowed_tools": agenttools.DefaultAllowedTools(),
|
||||
"temperature": agent.DefaultAgentTemperature,
|
||||
"thinking_model_id": "",
|
||||
"rerank_model_id": "",
|
||||
"system_prompt_web_enabled": agent.ProgressiveRAGSystemPromptWithWeb,
|
||||
"system_prompt_web_disabled": agent.ProgressiveRAGSystemPromptWithoutWeb,
|
||||
"use_custom_system_prompt": false,
|
||||
@@ -320,8 +316,6 @@ func (h *TenantHandler) GetTenantAgentConfig(c *gin.Context) {
|
||||
"reflection_enabled": tenant.AgentConfig.ReflectionEnabled,
|
||||
"allowed_tools": tenant.AgentConfig.AllowedTools,
|
||||
"temperature": tenant.AgentConfig.Temperature,
|
||||
"thinking_model_id": tenant.AgentConfig.ThinkingModelID,
|
||||
"rerank_model_id": tenant.AgentConfig.RerankModelID,
|
||||
"system_prompt_web_enabled": systemPromptWithWeb,
|
||||
"system_prompt_web_disabled": systemPromptWithoutWeb,
|
||||
"use_custom_system_prompt": useCustomPrompt,
|
||||
@@ -353,8 +347,6 @@ func (h *TenantHandler) updateTenantAgentConfigInternal(c *gin.Context) {
|
||||
c.Error(errors.NewAgentInvalidTemperatureError())
|
||||
return
|
||||
}
|
||||
// thinking_model_id 不再强制要求,允许先启用 Agent 再设置模型
|
||||
// 实际使用时会在 AgentQA 中进行验证
|
||||
if len(req.AllowedTools) == 0 {
|
||||
c.Error(errors.NewAgentMissingAllowedToolsError())
|
||||
return
|
||||
@@ -378,8 +370,6 @@ func (h *TenantHandler) updateTenantAgentConfigInternal(c *gin.Context) {
|
||||
ReflectionEnabled: req.ReflectionEnabled,
|
||||
AllowedTools: req.AllowedTools,
|
||||
Temperature: req.Temperature,
|
||||
ThinkingModelID: req.ThinkingModelID,
|
||||
RerankModelID: req.RerankModelID,
|
||||
SystemPromptWebEnabled: req.SystemPromptWebEnabled,
|
||||
SystemPromptWebDisabled: req.SystemPromptWebDisabled,
|
||||
UseCustomSystemPrompt: useCustomPrompt,
|
||||
|
||||
@@ -15,8 +15,6 @@ type AgentConfig struct {
|
||||
ReflectionEnabled bool `json:"reflection_enabled"` // Whether to enable reflection
|
||||
AllowedTools []string `json:"allowed_tools"` // List of allowed tool names
|
||||
Temperature float64 `json:"temperature"` // LLM temperature for agent
|
||||
ThinkingModelID string `json:"thinking_model_id"` // Model ID for reasoning
|
||||
RerankModelID string `json:"rerank_model_id"` // Model ID for reranking search results
|
||||
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs
|
||||
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"` // Custom prompt when web search is enabled
|
||||
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"` // Custom prompt when web search is disabled
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/event"
|
||||
"github.com/Tencent/WeKnora/internal/models/chat"
|
||||
"github.com/Tencent/WeKnora/internal/models/rerank"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ type AgentEngine interface {
|
||||
// AgentService defines the interface for agent-related operations
|
||||
type AgentService interface {
|
||||
// CreateAgentEngine creates an agent engine with the given configuration, EventBus, and ContextManager
|
||||
CreateAgentEngine(ctx context.Context, config *types.AgentConfig, eventBus *event.EventBus, contextManager ContextManager, sessionID string, sessionService SessionService) (AgentEngine, error)
|
||||
CreateAgentEngine(ctx context.Context, config *types.AgentConfig, chatModel chat.Chat, rerankModel rerank.Reranker, eventBus *event.EventBus, contextManager ContextManager, sessionID string, sessionService SessionService) (AgentEngine, error)
|
||||
|
||||
// ValidateConfig validates an agent configuration
|
||||
ValidateConfig(config *types.AgentConfig) error
|
||||
|
||||
Reference in New Issue
Block a user