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:
+79
-53
@@ -71,59 +71,85 @@ func AllKBSelectionModes() []KBSelectionMode {
|
||||
// AgentConfig represents the configuration for an agent.
|
||||
// Field names and JSON tags mirror internal/types.CustomAgentConfig.
|
||||
type AgentConfig struct {
|
||||
AgentMode string `json:"agent_mode"`
|
||||
AgentType string `json:"agent_type,omitempty"`
|
||||
SystemPrompt string `json:"system_prompt"`
|
||||
SystemPromptID string `json:"system_prompt_id,omitempty"`
|
||||
ContextTemplate string `json:"context_template"`
|
||||
ContextTemplateID string `json:"context_template_id,omitempty"`
|
||||
ModelID string `json:"model_id"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
MaxCompletionTokens int `json:"max_completion_tokens"`
|
||||
Thinking *bool `json:"thinking"`
|
||||
MaxIterations int `json:"max_iterations"`
|
||||
LLMCallTimeout int `json:"llm_call_timeout,omitempty"`
|
||||
AllowedTools []string `json:"allowed_tools"`
|
||||
MCPSelectionMode string `json:"mcp_selection_mode"`
|
||||
MCPServices []string `json:"mcp_services"`
|
||||
SkillsSelectionMode string `json:"skills_selection_mode"`
|
||||
SelectedSkills []string `json:"selected_skills"`
|
||||
KBSelectionMode string `json:"kb_selection_mode"`
|
||||
KnowledgeBases []string `json:"knowledge_bases"`
|
||||
RetrieveKBOnlyWhenMentioned bool `json:"retrieve_kb_only_when_mentioned"`
|
||||
RetainRetrievalHistory bool `json:"retain_retrieval_history"`
|
||||
ImageUploadEnabled bool `json:"image_upload_enabled"`
|
||||
VLMModelID string `json:"vlm_model_id"`
|
||||
AudioUploadEnabled bool `json:"audio_upload_enabled"`
|
||||
ASRModelID string `json:"asr_model_id"`
|
||||
ImageStorageProvider string `json:"image_storage_provider"`
|
||||
SupportedFileTypes []string `json:"supported_file_types"`
|
||||
DataAnalysisEnabled bool `json:"data_analysis_enabled"`
|
||||
FAQPriorityEnabled bool `json:"faq_priority_enabled"`
|
||||
FAQDirectAnswerThreshold float64 `json:"faq_direct_answer_threshold"`
|
||||
FAQScoreBoost float64 `json:"faq_score_boost"`
|
||||
WebSearchEnabled bool `json:"web_search_enabled"`
|
||||
WebSearchMaxResults int `json:"web_search_max_results"`
|
||||
WebSearchProviderID string `json:"web_search_provider_id,omitempty"`
|
||||
WebFetchEnabled bool `json:"web_fetch_enabled"`
|
||||
WebFetchTopN int `json:"web_fetch_top_n,omitempty"`
|
||||
MultiTurnEnabled bool `json:"multi_turn_enabled"`
|
||||
HistoryTurns int `json:"history_turns"`
|
||||
EmbeddingTopK int `json:"embedding_top_k"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
RerankTopK int `json:"rerank_top_k"`
|
||||
RerankThreshold float64 `json:"rerank_threshold"`
|
||||
EnableQueryExpansion bool `json:"enable_query_expansion"`
|
||||
EnableRewrite bool `json:"enable_rewrite"`
|
||||
RewritePromptSystem string `json:"rewrite_prompt_system"`
|
||||
RewritePromptUser string `json:"rewrite_prompt_user"`
|
||||
QueryUnderstandModelID string `json:"query_understand_model_id,omitempty"`
|
||||
FallbackStrategy string `json:"fallback_strategy"`
|
||||
FallbackResponse string `json:"fallback_response"`
|
||||
FallbackPrompt string `json:"fallback_prompt"`
|
||||
SuggestedPrompts []string `json:"suggested_prompts,omitempty"`
|
||||
AgentMode string `json:"agent_mode"`
|
||||
AgentType string `json:"agent_type,omitempty"`
|
||||
SystemPrompt string `json:"system_prompt"`
|
||||
SystemPromptID string `json:"system_prompt_id,omitempty"`
|
||||
ContextTemplate string `json:"context_template"`
|
||||
ContextTemplateID string `json:"context_template_id,omitempty"`
|
||||
ModelID string `json:"model_id"`
|
||||
RerankModelID string `json:"rerank_model_id"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
MaxCompletionTokens int `json:"max_completion_tokens"`
|
||||
Thinking *bool `json:"thinking"`
|
||||
MaxIterations int `json:"max_iterations"`
|
||||
LLMCallTimeout int `json:"llm_call_timeout,omitempty"`
|
||||
AllowedTools []string `json:"allowed_tools"`
|
||||
MCPSelectionMode string `json:"mcp_selection_mode"`
|
||||
MCPServices []string `json:"mcp_services"`
|
||||
SkillsSelectionMode string `json:"skills_selection_mode"`
|
||||
SelectedSkills []string `json:"selected_skills"`
|
||||
KBSelectionMode string `json:"kb_selection_mode"`
|
||||
KnowledgeBases []string `json:"knowledge_bases"`
|
||||
RetrieveKBOnlyWhenMentioned bool `json:"retrieve_kb_only_when_mentioned"`
|
||||
RetainRetrievalHistory bool `json:"retain_retrieval_history"`
|
||||
ImageUploadEnabled bool `json:"image_upload_enabled"`
|
||||
VLMModelID string `json:"vlm_model_id"`
|
||||
AudioUploadEnabled bool `json:"audio_upload_enabled"`
|
||||
ASRModelID string `json:"asr_model_id"`
|
||||
ImageStorageProvider string `json:"image_storage_provider"`
|
||||
SupportedFileTypes []string `json:"supported_file_types"`
|
||||
DataAnalysisEnabled bool `json:"data_analysis_enabled"`
|
||||
FAQPriorityEnabled bool `json:"faq_priority_enabled"`
|
||||
FAQDirectAnswerThreshold float64 `json:"faq_direct_answer_threshold"`
|
||||
FAQScoreBoost float64 `json:"faq_score_boost"`
|
||||
WebSearchEnabled bool `json:"web_search_enabled"`
|
||||
WebSearchMaxResults int `json:"web_search_max_results"`
|
||||
WebSearchProviderID string `json:"web_search_provider_id,omitempty"`
|
||||
WebFetchEnabled bool `json:"web_fetch_enabled"`
|
||||
WebFetchTopN int `json:"web_fetch_top_n,omitempty"`
|
||||
MultiTurnEnabled bool `json:"multi_turn_enabled"`
|
||||
HistoryTurns int `json:"history_turns"`
|
||||
EmbeddingTopK int `json:"embedding_top_k"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
RerankTopK int `json:"rerank_top_k"`
|
||||
RerankThreshold float64 `json:"rerank_threshold"`
|
||||
EnableQueryExpansion bool `json:"enable_query_expansion"`
|
||||
EnableRewrite bool `json:"enable_rewrite"`
|
||||
RewritePromptSystem string `json:"rewrite_prompt_system"`
|
||||
RewritePromptUser string `json:"rewrite_prompt_user"`
|
||||
QueryUnderstandModelID string `json:"query_understand_model_id,omitempty"`
|
||||
FallbackStrategy string `json:"fallback_strategy"`
|
||||
FallbackResponse string `json:"fallback_response"`
|
||||
FallbackPrompt string `json:"fallback_prompt"`
|
||||
QuestionSuggestions *QuestionSuggestionConfig `json:"question_suggestions,omitempty"`
|
||||
}
|
||||
|
||||
type QuestionSuggestionConfig struct {
|
||||
Starters StarterSuggestionConfig `json:"starters"`
|
||||
FollowUps FollowUpSuggestionConfig `json:"follow_ups"`
|
||||
}
|
||||
|
||||
type StarterSuggestionConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Mode string `json:"mode"`
|
||||
Items []string `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type FollowUpSuggestionConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Mode string `json:"mode"`
|
||||
Count int `json:"count"`
|
||||
ModelID string `json:"model_id,omitempty"`
|
||||
AdditionalInstruction string `json:"additional_instruction,omitempty"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
MaxContextTurns int `json:"max_context_turns"`
|
||||
SuppressOnFallback bool `json:"suppress_on_fallback"`
|
||||
SuppressWhenAnswerAsksQuestion bool `json:"suppress_when_answer_asks_question"`
|
||||
KnowledgeFallback bool `json:"knowledge_fallback"`
|
||||
AllowRegenerate bool `json:"allow_regenerate"`
|
||||
}
|
||||
|
||||
// CreateAgentRequest represents the request to create an agent.
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type MessageSuggestionItem struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Source string `json:"source"`
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids,omitempty"`
|
||||
}
|
||||
|
||||
type MessageSuggestionSet struct {
|
||||
ID string `json:"id"`
|
||||
SessionID string `json:"session_id"`
|
||||
AssistantMessageID string `json:"assistant_message_id"`
|
||||
Status string `json:"status"`
|
||||
AllowRegenerate bool `json:"allow_regenerate"`
|
||||
SuppressionReason string `json:"suppression_reason,omitempty"`
|
||||
Questions []MessageSuggestionItem `json:"questions"`
|
||||
}
|
||||
|
||||
type messageSuggestionResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Data MessageSuggestionSet `json:"data"`
|
||||
}
|
||||
|
||||
func (c *Client) EnsureMessageSuggestions(
|
||||
ctx context.Context,
|
||||
sessionID string,
|
||||
messageID string,
|
||||
regenerate bool,
|
||||
) (*MessageSuggestionSet, error) {
|
||||
path := fmt.Sprintf("/api/v1/sessions/%s/messages/%s/suggestions", url.PathEscape(sessionID), url.PathEscape(messageID))
|
||||
resp, err := c.doRequest(ctx, http.MethodPost, path, map[string]bool{"regenerate": regenerate}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response messageSuggestionResponse
|
||||
if err := parseResponse(resp, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetMessageSuggestions(
|
||||
ctx context.Context,
|
||||
sessionID string,
|
||||
messageID string,
|
||||
) (*MessageSuggestionSet, error) {
|
||||
path := fmt.Sprintf("/api/v1/sessions/%s/messages/%s/suggestions", url.PathEscape(sessionID), url.PathEscape(messageID))
|
||||
resp, err := c.doRequest(ctx, http.MethodGet, path, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response messageSuggestionResponse
|
||||
if err := parseResponse(resp, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) RecordMessageSuggestionEvent(
|
||||
ctx context.Context,
|
||||
sessionID string,
|
||||
setID string,
|
||||
questionID string,
|
||||
eventType string,
|
||||
) error {
|
||||
path := fmt.Sprintf("/api/v1/sessions/%s/suggestion-events", url.PathEscape(sessionID))
|
||||
resp, err := c.doRequest(ctx, http.MethodPost, path, map[string]string{
|
||||
"suggestion_set_id": setID,
|
||||
"question_id": questionID,
|
||||
"event_type": eventType,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return parseResponse(resp, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user