Merge branch 'custom_agent'
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
import { get, post, put, del } from "../../utils/request";
|
||||
|
||||
// 智能体配置
|
||||
export interface CustomAgentConfig {
|
||||
// ===== 基础设置 =====
|
||||
agent_mode?: 'quick-answer' | 'smart-reasoning'; // 运行模式:quick-answer=RAG模式, smart-reasoning=ReAct Agent模式
|
||||
system_prompt?: string; // 统一系统提示词(使用 {{web_search_status}} 占位符动态控制行为)
|
||||
context_template?: string; // 上下文模板(普通模式)
|
||||
|
||||
// ===== 模型设置 =====
|
||||
model_id?: string;
|
||||
rerank_model_id?: string; // ReRank 模型 ID
|
||||
temperature?: number;
|
||||
max_completion_tokens?: number; // 最大生成token数(普通模式)
|
||||
|
||||
// ===== Agent模式设置 =====
|
||||
max_iterations?: number; // 最大迭代次数
|
||||
allowed_tools?: string[]; // 允许的工具
|
||||
reflection_enabled?: boolean; // 是否启用反思
|
||||
// MCP服务选择模式:all=全部启用的MCP服务, selected=指定服务, none=不使用MCP
|
||||
mcp_selection_mode?: 'all' | 'selected' | 'none';
|
||||
mcp_services?: string[]; // 选择的MCP服务ID列表
|
||||
|
||||
// ===== 知识库设置 =====
|
||||
// 知识库选择模式:all=全部知识库, selected=指定知识库, none=不使用知识库
|
||||
kb_selection_mode?: 'all' | 'selected' | 'none';
|
||||
knowledge_bases?: string[];
|
||||
|
||||
// ===== 网络搜索设置 =====
|
||||
web_search_enabled?: boolean;
|
||||
web_search_max_results?: number;
|
||||
|
||||
// ===== 多轮对话设置 =====
|
||||
multi_turn_enabled?: boolean; // 是否启用多轮对话
|
||||
history_turns?: number; // 保留历史轮数
|
||||
|
||||
// ===== 检索策略设置 =====
|
||||
embedding_top_k?: number; // 向量召回TopK
|
||||
keyword_threshold?: number; // 关键词召回阈值
|
||||
vector_threshold?: number; // 向量召回阈值
|
||||
rerank_top_k?: number; // 重排TopK
|
||||
rerank_threshold?: number; // 重排阈值
|
||||
|
||||
// ===== 高级设置(主要用于普通模式)=====
|
||||
enable_query_expansion?: boolean; // 是否启用查询扩展
|
||||
enable_rewrite?: boolean; // 是否启用问题改写
|
||||
rewrite_prompt_system?: string; // 改写系统提示词
|
||||
rewrite_prompt_user?: string; // 改写用户提示词模板
|
||||
fallback_strategy?: 'fixed' | 'model'; // 兜底策略
|
||||
fallback_response?: string; // 固定兜底回复
|
||||
fallback_prompt?: string; // 兜底提示词(模型生成时)
|
||||
|
||||
// ===== 已废弃字段(保留兼容)=====
|
||||
welcome_message?: string;
|
||||
suggested_prompts?: string[];
|
||||
}
|
||||
|
||||
// 智能体
|
||||
export interface CustomAgent {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
avatar?: string;
|
||||
is_builtin: boolean;
|
||||
tenant_id?: number;
|
||||
created_by?: string;
|
||||
config: CustomAgentConfig;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
// 创建智能体请求
|
||||
export interface CreateAgentRequest {
|
||||
name: string;
|
||||
description?: string;
|
||||
avatar?: string;
|
||||
config?: CustomAgentConfig;
|
||||
}
|
||||
|
||||
// 更新智能体请求
|
||||
export interface UpdateAgentRequest {
|
||||
name: string;
|
||||
description?: string;
|
||||
avatar?: string;
|
||||
config?: CustomAgentConfig;
|
||||
}
|
||||
|
||||
// 内置智能体 ID
|
||||
export const BUILTIN_QUICK_ANSWER_ID = 'builtin-quick-answer';
|
||||
export const BUILTIN_SMART_REASONING_ID = 'builtin-smart-reasoning';
|
||||
|
||||
// AgentMode 常量
|
||||
export const AGENT_MODE_QUICK_ANSWER = 'quick-answer';
|
||||
export const AGENT_MODE_SMART_REASONING = 'smart-reasoning';
|
||||
|
||||
// Deprecated: Use BUILTIN_QUICK_ANSWER_ID instead
|
||||
export const BUILTIN_AGENT_NORMAL_ID = BUILTIN_QUICK_ANSWER_ID;
|
||||
// Deprecated: Use BUILTIN_SMART_REASONING_ID instead
|
||||
export const BUILTIN_AGENT_AGENT_ID = BUILTIN_SMART_REASONING_ID;
|
||||
|
||||
// 所有内置智能体 ID 列表(便于扩展)
|
||||
export const BUILTIN_AGENT_IDS = [
|
||||
BUILTIN_QUICK_ANSWER_ID,
|
||||
BUILTIN_SMART_REASONING_ID,
|
||||
] as const;
|
||||
|
||||
// 获取智能体列表(包括内置智能体)
|
||||
export function listAgents() {
|
||||
return get<{ data: CustomAgent[] }>('/api/v1/agents');
|
||||
}
|
||||
|
||||
// 获取智能体详情
|
||||
export function getAgentById(id: string) {
|
||||
return get<{ data: CustomAgent }>(`/api/v1/agents/${id}`);
|
||||
}
|
||||
|
||||
// 创建智能体
|
||||
export function createAgent(data: CreateAgentRequest) {
|
||||
return post<{ data: CustomAgent }>('/api/v1/agents', data);
|
||||
}
|
||||
|
||||
// 更新智能体
|
||||
export function updateAgent(id: string, data: UpdateAgentRequest) {
|
||||
return put<{ data: CustomAgent }>(`/api/v1/agents/${id}`, data);
|
||||
}
|
||||
|
||||
// 删除智能体
|
||||
export function deleteAgent(id: string) {
|
||||
return del<{ success: boolean }>(`/api/v1/agents/${id}`);
|
||||
}
|
||||
|
||||
// 复制智能体
|
||||
export function copyAgent(id: string) {
|
||||
return post<{ data: CustomAgent }>(`/api/v1/agents/${id}/copy`);
|
||||
}
|
||||
|
||||
// 判断是否为内置智能体
|
||||
export function isBuiltinAgent(agentId: string): boolean {
|
||||
return (BUILTIN_AGENT_IDS as readonly string[]).includes(agentId);
|
||||
}
|
||||
|
||||
// 占位符定义
|
||||
export interface PlaceholderDefinition {
|
||||
name: string;
|
||||
label: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
// 占位符响应
|
||||
export interface PlaceholdersResponse {
|
||||
all: PlaceholderDefinition[];
|
||||
system_prompt: PlaceholderDefinition[];
|
||||
agent_system_prompt: PlaceholderDefinition[];
|
||||
context_template: PlaceholderDefinition[];
|
||||
rewrite_system_prompt: PlaceholderDefinition[];
|
||||
rewrite_prompt: PlaceholderDefinition[];
|
||||
fallback_prompt: PlaceholderDefinition[];
|
||||
}
|
||||
|
||||
// 获取占位符定义
|
||||
export function getPlaceholders() {
|
||||
return get<{ data: PlaceholdersResponse }>('/api/v1/agents/placeholders');
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export function useStream() {
|
||||
let renderTimer: number | null = null
|
||||
|
||||
// 启动流式请求
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; web_search_enabled?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; method: string; url: string }) => {
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; method: string; url: string }) => {
|
||||
// 重置状态
|
||||
output.value = '';
|
||||
error.value = null;
|
||||
@@ -89,6 +89,10 @@ export function useStream() {
|
||||
if (params.knowledge_ids !== undefined && params.knowledge_ids.length > 0) {
|
||||
postBody.knowledge_ids = params.knowledge_ids;
|
||||
}
|
||||
// Include agent_id if provided (for custom agent configuration)
|
||||
if (params.agent_id) {
|
||||
postBody.agent_id = params.agent_id;
|
||||
}
|
||||
// Include web_search_enabled if provided
|
||||
if (params.web_search_enabled !== undefined) {
|
||||
postBody.web_search_enabled = params.web_search_enabled;
|
||||
|
||||
@@ -29,9 +29,7 @@ export interface AgentConfig {
|
||||
allowed_tools: string[]
|
||||
temperature: number
|
||||
knowledge_bases?: string[]
|
||||
system_prompt_web_enabled?: string // Custom system prompt when web search is enabled
|
||||
system_prompt_web_disabled?: string // Custom system prompt when web search is disabled
|
||||
use_custom_system_prompt?: boolean
|
||||
system_prompt?: string // Unified system prompt (uses {{web_search_status}} placeholder)
|
||||
available_tools?: ToolDefinition[] // GET 响应中包含,POST/PUT 不需要
|
||||
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
|
||||
}
|
||||
@@ -41,8 +39,6 @@ export interface ConversationConfig {
|
||||
context_template: string
|
||||
temperature: number
|
||||
max_completion_tokens: number
|
||||
use_custom_system_prompt?: boolean
|
||||
use_custom_context_template?: boolean
|
||||
max_rounds: number
|
||||
embedding_top_k: number
|
||||
keyword_threshold: number
|
||||
@@ -60,6 +56,23 @@ export interface ConversationConfig {
|
||||
enable_query_expansion?: boolean
|
||||
}
|
||||
|
||||
export interface PromptTemplate {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
content: string
|
||||
has_knowledge_base?: boolean
|
||||
has_web_search?: boolean
|
||||
}
|
||||
|
||||
export interface PromptTemplatesConfig {
|
||||
system_prompt: PromptTemplate[]
|
||||
context_template: PromptTemplate[]
|
||||
rewrite_system: PromptTemplate[]
|
||||
rewrite_user: PromptTemplate[]
|
||||
fallback: PromptTemplate[]
|
||||
}
|
||||
|
||||
export function getSystemInfo(): Promise<{ data: SystemInfo }> {
|
||||
return get('/api/v1/system/info')
|
||||
}
|
||||
@@ -79,3 +92,7 @@ export function getConversationConfig(): Promise<{ data: ConversationConfig }> {
|
||||
export function updateConversationConfig(config: ConversationConfig): Promise<{ data: ConversationConfig }> {
|
||||
return put('/api/v1/tenants/kv/conversation-config', config)
|
||||
}
|
||||
|
||||
export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> {
|
||||
return get('/api/v1/tenants/kv/prompt-templates')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user