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
|
||||
|
||||
Reference in New Issue
Block a user