feat: 更新前端页面和agent应用

- Agents.vue: 更新agent列表和创建功能
- Skill.vue: 更新skill页面
- skill.ts: 更新skill编辑逻辑
- agent/app/main.py: 更新agent应用

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 17:17:08 +08:00
parent 7795685f43
commit 19f5c79d58
4 changed files with 234 additions and 35 deletions

View File

@@ -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"))