From 19f5c79d587e3812c7d827e1c7b413abd8af5cbc Mon Sep 17 00:00:00 2001 From: "DESKTOP-72TV0V4\\caoxiaozhu" Date: Thu, 12 Mar 2026 17:17:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=92=8Cagent=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agents.vue: 更新agent列表和创建功能 - Skill.vue: 更新skill页面 - skill.ts: 更新skill编辑逻辑 - agent/app/main.py: 更新agent应用 Co-Authored-By: Claude Opus 4.6 --- agent/app/main.py | 92 +++++++++++++++++++++ web/src/views/Agents.vue | 154 ++++++++++++++++++++++++++++------- web/src/views/Skill.vue | 3 +- web/src/views/skill/skill.ts | 20 ++++- 4 files changed, 234 insertions(+), 35 deletions(-) diff --git a/agent/app/main.py b/agent/app/main.py index e77dd41..b059b22 100644 --- a/agent/app/main.py +++ b/agent/app/main.py @@ -142,6 +142,31 @@ class TeamChatRequest(BaseModel): strategy: str = "parallel" +class CreateAgentRequest(BaseModel): + """创建智能体请求""" + name: str + description: Optional[str] = None + avatar: str = "🤖" + # 技能配置 + skills_mode: str = "all" # all / include / exclude + skills: list[str] = [] # 技能ID列表 + # 知识库 + knowledge: str = "general" # general / codebase / docs / api + # 自定义提示词 + prompt: Optional[str] = None + # 模型配置 + model_provider: Optional[str] = None + model_name: Optional[str] = None + user_id: int = 1 + + +class CreateAgentResponse(BaseModel): + """创建智能体响应""" + agent_id: int + name: str + message: str = "Agent created successfully" + + class ChatResponse(BaseModel): """对话响应""" agent_id: int @@ -443,6 +468,73 @@ async def team_chat(request: TeamChatRequest): } +@app.post("/agent/create", response_model=CreateAgentResponse) +async def create_agent(request: CreateAgentRequest): + """ + 创建新的智能体 + """ + import json + import uuid + + # 生成唯一的 agent_id + agent_id = int(datetime.now().timestamp() * 1000) % 100000 + + # 构建 Agent 配置 + agent_config = { + "id": agent_id, + "name": request.name, + "description": request.description or "", + "avatar": request.avatar, + "skills_mode": request.skills_mode, + "skills": request.skills, + "knowledge": request.knowledge, + "role_description": request.prompt or f"You are {request.name}. {request.description or ''}", + "model_provider": request.model_provider or "anthropic", + "model_name": request.model_name or "claude-sonnet-4-20250514", + } + + # 保存到 agents 目录 + agents_dir = os.path.join(os.path.dirname(__file__), "agents") + os.makedirs(agents_dir, exist_ok=True) + + config_file = os.path.join(agents_dir, f"agent_{agent_id}.json") + with open(config_file, "w", encoding="utf-8") as f: + json.dump(agent_config, f, ensure_ascii=False, indent=2) + + logger.info(f"Agent created: {request.name} (ID: {agent_id})") + + return CreateAgentResponse( + agent_id=agent_id, + name=request.name, + message="Agent created successfully" + ) + + +@app.get("/agent/list") +async def list_agents(): + """ + 获取智能体列表 + """ + import json + + agents_dir = os.path.join(os.path.dirname(__file__), "agents") + if not os.path.exists(agents_dir): + return {"agents": []} + + agents = [] + for file in os.listdir(agents_dir): + if file.endswith(".json"): + config_file = os.path.join(agents_dir, file) + try: + with open(config_file, "r", encoding="utf-8") as f: + agent = json.load(f) + agents.append(agent) + except: + continue + + return {"agents": agents} + + if __name__ == "__main__": import uvicorn port = int(os.getenv("AGENT_PORT", "8081")) diff --git a/web/src/views/Agents.vue b/web/src/views/Agents.vue index caae301..2211da8 100644 --- a/web/src/views/Agents.vue +++ b/web/src/views/Agents.vue @@ -1,5 +1,6 @@