feat(agent): add question suggestions with after-answer follow-ups
Enable agents to configure starter prompts and async follow-up questions after completed answers, with durable caching, analytics events, and chat/embed UI integration.
This commit is contained in:
@@ -22,12 +22,13 @@ var regThinkIndex = regexp.MustCompile(`(?s)<think>.*?</think>`)
|
||||
// It reads the chat history knowledge base configuration from the tenant's ChatHistoryConfig,
|
||||
// which is managed via the settings UI.
|
||||
type messageService struct {
|
||||
messageRepo interfaces.MessageRepository // Repository for message storage operations
|
||||
sessionRepo interfaces.SessionRepository // Repository for session validation
|
||||
tenantService interfaces.TenantService // Service for tenant operations (read ChatHistoryConfig)
|
||||
kbService interfaces.KnowledgeBaseService // Service for knowledge base operations (search chat history KB)
|
||||
knowService interfaces.KnowledgeService // Service for knowledge operations (index/delete passages)
|
||||
modelService interfaces.ModelService // Service for model operations (rerank model)
|
||||
messageRepo interfaces.MessageRepository // Repository for message storage operations
|
||||
sessionRepo interfaces.SessionRepository // Repository for session validation
|
||||
tenantService interfaces.TenantService // Service for tenant operations (read ChatHistoryConfig)
|
||||
kbService interfaces.KnowledgeBaseService // Service for knowledge base operations (search chat history KB)
|
||||
knowService interfaces.KnowledgeService // Service for knowledge operations (index/delete passages)
|
||||
modelService interfaces.ModelService // Service for model operations (rerank model)
|
||||
suggestionRepo interfaces.MessageSuggestionRepository
|
||||
}
|
||||
|
||||
// NewMessageService creates a new message service instance with the required repositories
|
||||
@@ -37,14 +38,16 @@ func NewMessageService(messageRepo interfaces.MessageRepository,
|
||||
kbService interfaces.KnowledgeBaseService,
|
||||
knowService interfaces.KnowledgeService,
|
||||
modelService interfaces.ModelService,
|
||||
suggestionRepo interfaces.MessageSuggestionRepository,
|
||||
) interfaces.MessageService {
|
||||
return &messageService{
|
||||
messageRepo: messageRepo,
|
||||
sessionRepo: sessionRepo,
|
||||
tenantService: tenantService,
|
||||
kbService: kbService,
|
||||
knowService: knowService,
|
||||
modelService: modelService,
|
||||
messageRepo: messageRepo,
|
||||
sessionRepo: sessionRepo,
|
||||
tenantService: tenantService,
|
||||
kbService: kbService,
|
||||
knowService: knowService,
|
||||
modelService: modelService,
|
||||
suggestionRepo: suggestionRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,6 +292,11 @@ func (s *messageService) DeleteMessage(ctx context.Context, sessionID string, me
|
||||
})
|
||||
return err
|
||||
}
|
||||
if s.suggestionRepo != nil {
|
||||
if err := s.suggestionRepo.DeleteByMessageID(ctx, tenantID, sessionID, messageID); err != nil {
|
||||
logger.Warnf(ctx, "Failed to delete suggestions for message %s: %v", messageID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Async cleanup: delete the associated Knowledge entry from the chat history KB.
|
||||
// Use WithoutCancel so the goroutine survives after the HTTP request context is done.
|
||||
@@ -319,6 +327,11 @@ func (s *messageService) ClearSessionMessages(ctx context.Context, sessionID str
|
||||
logger.Errorf(ctx, "Failed to delete messages for session %s: %v", sessionID, err)
|
||||
return err
|
||||
}
|
||||
if s.suggestionRepo != nil {
|
||||
if err := s.suggestionRepo.DeleteBySessionID(ctx, tenantID, sessionID); err != nil {
|
||||
logger.Warnf(ctx, "Failed to delete suggestions for session %s: %v", sessionID, err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "All messages cleared for session: %s", sessionID)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user