Files
multiAgentTry/backend/app/routers/roles.py
Claude Code 1719d1f1f9 重构 API 路由并新增工作流编排功能
后端:
- 重构 agents, heartbeats, locks, meetings, resources, roles, workflows 路由
- 新增 orchestrator 和 providers 路由
- 新增 CLI 调用器和流程编排服务
- 添加日志配置和依赖项

前端:
- 更新 AgentsPage、SettingsPage、WorkflowPage 页面
- 扩展 api.ts 新增 API 接口

其他:
- 清理测试 agent 数据文件
- 新增示例工作流和项目审计报告

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 16:36:25 +08:00

62 lines
1.6 KiB
Python

"""
角色分配 API 路由
接入 RoleAllocator 服务,基于任务分析分配角色
"""
from fastapi import APIRouter
from pydantic import BaseModel
from typing import List
from ..services.role_allocator import get_role_allocator
router = APIRouter()
class RoleRequest(BaseModel):
task: str
class RoleAllocateRequest(BaseModel):
task: str
agents: List[str]
@router.post("/primary")
async def get_primary_role(request: RoleRequest):
"""获取任务主要角色"""
allocator = get_role_allocator()
primary = allocator.get_primary_role(request.task)
role_scores = allocator._analyze_task_roles(request.task)
return {
"task": request.task,
"primary_role": primary,
"role_scores": {k: round(v, 2) for k, v in role_scores.items()}
}
@router.post("/allocate")
async def allocate_roles(request: RoleAllocateRequest):
"""分配角色"""
allocator = get_role_allocator()
allocation = await allocator.allocate_roles(
task=request.task,
available_agents=request.agents
)
primary = allocator.get_primary_role(request.task)
return {
"task": request.task,
"primary_role": primary,
"allocation": allocation
}
@router.post("/explain")
async def explain_roles(request: RoleAllocateRequest):
"""解释角色分配"""
allocator = get_role_allocator()
allocation = await allocator.allocate_roles(
task=request.task,
available_agents=request.agents
)
explanation = allocator.explain_allocation(request.task, allocation)
return {"explanation": explanation}