fad458b2a7
- UIUX 文档:填充 19 个缺口(多主体画像/健康度/AI+看板/增长域/洞察域/创始人端/OODA/助推/商密) - UIUX 文档:插入 6 个新章节(十四~十九),旧章节重编号为二十~三十一,更新目录和交叉引用 - 作业指导书 x5:导航改为 6 域分组,新增 Context Bar/工作模式/Insight Rail/决策线程/多工作区等 UI 概念 - 新建 docs/2-task-uiux.md:50 个代码落地开发任务,按 P0-P6 分优先级 + 8 Sprint 规划 - 后端/前端:大量新增模型、路由、组件(来自之前 Phase 开发)
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
"""Agent 执行记录路由。"""
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.database import get_db
|
|
from app.core.dependencies import get_current_user
|
|
from app.models.agent_execution import AgentExecution
|
|
from app.models.user import User
|
|
from app.schemas.common import ApiResponse, success
|
|
from app.services.agent_orchestrator import orchestrate_agent
|
|
|
|
router = APIRouter(prefix="/agent-executions", tags=["agent-executions"])
|
|
|
|
|
|
@router.get("", response_model=ApiResponse[list])
|
|
async def list_executions(
|
|
page: int = Query(default=1, ge=1),
|
|
page_size: int = Query(default=20, ge=1, le=100),
|
|
db: AsyncSession = Depends(get_db),
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
"""获取 Agent 执行记录列表。"""
|
|
offset = (page - 1) * page_size
|
|
result = await db.execute(
|
|
select(AgentExecution)
|
|
.where(AgentExecution.tenant_id == user.tenant_id)
|
|
.order_by(AgentExecution.created_at.desc())
|
|
.offset(offset)
|
|
.limit(page_size)
|
|
)
|
|
items = result.scalars().all()
|
|
return success(data=[
|
|
{
|
|
"id": str(i.id),
|
|
"agent_name": i.agent_name,
|
|
"autonomy_level": i.autonomy_level,
|
|
"input_summary": i.input_summary,
|
|
"output_summary": i.output_summary,
|
|
"review_status": i.review_status,
|
|
"reviewer_id": i.reviewer_id,
|
|
"duration_ms": i.duration_ms,
|
|
}
|
|
for i in items
|
|
])
|
|
|
|
|
|
@router.post("/orchestrate", response_model=ApiResponse[dict])
|
|
async def orchestrate(req: dict, user: User = Depends(get_current_user)):
|
|
"""编排 Agent 执行。"""
|
|
result = await orchestrate_agent(
|
|
req.get("agent_name", ""),
|
|
req.get("autonomy_level", "L1"),
|
|
req.get("input_data", {}),
|
|
)
|
|
return success(data=result)
|
|
|
|
|
|
@router.put("/{execution_id}/review", response_model=ApiResponse[dict])
|
|
async def review_execution(
|
|
execution_id: str,
|
|
req: dict,
|
|
db: AsyncSession = Depends(get_db),
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
"""审核 Agent 执行。"""
|
|
result = await db.execute(
|
|
select(AgentExecution).where(AgentExecution.id == execution_id, AgentExecution.tenant_id == user.tenant_id)
|
|
)
|
|
execution = result.scalar_one_or_none()
|
|
if not execution:
|
|
from fastapi import HTTPException
|
|
raise HTTPException(status_code=404, detail="执行记录不存在")
|
|
execution.review_status = req.get("review_status", "approved")
|
|
execution.reviewer_id = str(user.id)
|
|
from datetime import datetime, timezone
|
|
execution.reviewed_at = datetime.now(timezone.utc)
|
|
await db.flush()
|
|
return success(data={"id": str(execution.id), "review_status": execution.review_status}, message="审核完成")
|