feat: 新增智能体功能模块,支持自定义智能体创建、配置和选择

This commit is contained in:
wizardchen
2025-12-24 10:34:41 +08:00
parent 236b190b26
commit d0c5c4f6b0
36 changed files with 5195 additions and 672 deletions
+94
View File
@@ -0,0 +1,94 @@
import { get, post, put, del } from "../../utils/request";
// 智能体类型
export type CustomAgentType = 'normal' | 'agent' | 'custom';
// 智能体配置
export interface CustomAgentConfig {
agent_mode?: 'normal' | 'agent'; // 运行模式:normal=RAG模式, agent=ReAct Agent模式
system_prompt?: string;
model_id?: string;
rerank_model_id?: string; // ReRank 模型 ID(当使用知识库时需要)
temperature?: number;
max_iterations?: number;
allowed_tools?: string[];
knowledge_bases?: string[];
// 当没有配置知识库时,是否允许用户自由选择知识库
// true (默认): 用户可以自由选择任意知识库
// false: 禁用知识库选择功能
allow_user_kb_selection?: boolean;
web_search_enabled?: boolean;
web_search_max_results?: number;
reflection_enabled?: boolean;
welcome_message?: string;
suggested_prompts?: string[];
multi_turn_enabled?: boolean; // 是否启用多轮对话
history_turns?: number; // 保留历史轮数
}
// 智能体
export interface CustomAgent {
id: string;
name: string;
description?: string;
avatar?: string;
is_builtin: boolean;
type: CustomAgentType;
tenant_id?: number;
created_by?: string;
config: CustomAgentConfig;
created_at?: string;
updated_at?: string;
}
// 创建智能体请求
export interface CreateAgentRequest {
name: string;
description?: string;
avatar?: string;
type?: CustomAgentType;
config?: CustomAgentConfig;
}
// 更新智能体请求
export interface UpdateAgentRequest {
name: string;
description?: string;
avatar?: string;
type?: CustomAgentType;
config?: CustomAgentConfig;
}
// 内置智能体 ID
export const BUILTIN_AGENT_NORMAL_ID = 'builtin-normal';
export const BUILTIN_AGENT_AGENT_ID = 'builtin-agent';
// 获取智能体列表(包括内置智能体)
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 isBuiltinAgent(agentId: string): boolean {
return agentId === BUILTIN_AGENT_NORMAL_ID || agentId === BUILTIN_AGENT_AGENT_ID;
}
+5 -1
View File
@@ -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;