feat: Day 10-11 - Agent Configuration System completed
Backend: - Create agents.yaml config file with 12 agents definition - Create Prompt templates for topic-evaluation agent - Implement agentService.ts for loading and managing agent configs - Create agentController.ts with CRUD operations - Create agent routes (GET /agents, /agents/:id, etc.) - Register agent routes in main server Frontend: - Create agentApi.ts service module - Update AgentChatPage to dynamically load agent config from API - Add loading state and error handling - Display agent details (description, category, model) Build: Both frontend and backend build successfully
This commit is contained in:
77
frontend/src/api/agentApi.ts
Normal file
77
frontend/src/api/agentApi.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import request from './request';
|
||||
|
||||
export interface AgentConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
nameEn: string;
|
||||
description: string;
|
||||
category: string;
|
||||
icon: string;
|
||||
enabled: boolean;
|
||||
systemPromptFile: string;
|
||||
userPromptTemplateFile: string;
|
||||
models: {
|
||||
[modelName: string]: {
|
||||
temperature: number;
|
||||
maxTokens: number;
|
||||
topP?: number;
|
||||
};
|
||||
};
|
||||
ragEnabled: boolean;
|
||||
requiresProject: boolean;
|
||||
outputFormat: 'text' | 'structured' | 'document';
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
export interface ApiResponse<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export const agentApi = {
|
||||
// 获取所有智能体列表
|
||||
getAll: async (): Promise<ApiResponse<AgentConfig[]>> => {
|
||||
const response = await request.get('/agents');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 获取启用的智能体列表
|
||||
getEnabled: async (): Promise<ApiResponse<AgentConfig[]>> => {
|
||||
const response = await request.get('/agents/enabled');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 获取单个智能体详情
|
||||
getById: async (id: string): Promise<ApiResponse<AgentConfig>> => {
|
||||
const response = await request.get(`/agents/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 根据分类获取智能体
|
||||
getByCategory: async (category: string): Promise<ApiResponse<AgentConfig[]>> => {
|
||||
const response = await request.get(`/agents/by-category?category=${encodeURIComponent(category)}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 获取智能体的系统Prompt
|
||||
getSystemPrompt: async (id: string): Promise<ApiResponse<{ agentId: string; systemPrompt: string }>> => {
|
||||
const response = await request.get(`/agents/${id}/system-prompt`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 渲染用户Prompt
|
||||
renderPrompt: async (
|
||||
id: string,
|
||||
data: {
|
||||
projectBackground?: string;
|
||||
userInput: string;
|
||||
knowledgeBaseContext?: string;
|
||||
}
|
||||
): Promise<ApiResponse<{ agentId: string; renderedPrompt: string }>> => {
|
||||
const response = await request.post(`/agents/${id}/render-prompt`, data);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user