Files
AgentLab/backend/app/api/inquiry.py
T
ThearchyHelios a7333368f1 审批质询测试补全:封存之后的追问途中运行被继续了不写进记录、/verify 接口核对一致、批准和驳回都在回答期间被拦;接口说明写明质询工件的形状
- 失败的探索运行封存后追问,回答途中被继续运行:回答照样交回,recorded 为假,继续运行重新封存后核对一致
- 停在审批时质询、批准、封存之后,经 /api/runs/{id}/verify 核对,封存范围盖住这条质询
- 质询期间批准、驳回都回 409 inquiry_busy
- api/inquiry.py 的说明补上质询工件的返回形状 {id, content, masked[, mask_note]},以及回答文档原样给
2026-10-05 19:00:36 +08:00

64 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""审批质询:审批人针对待审报告里的一句话提问,只读 agent 现查现答(规则和做法见 engine/inquiry.py)。
- POST /api/runs/{run_id}/inquiries:{report, unit, quote?, question, approval_id?} → {inquiry, recorded, note}
- GET /api/runs/{run_id}/inquiries?report=&unit=:{items: [Inquiry]},封存前后的都算,按先后
- GET /api/runs/{run_id}/inquiries/artifacts/{artifact_id}:质询引用过的工件 {id, content, masked[, mask_note]}——
查询快照的遮罩列照证据面板遮好(masked 是遮掉的列名);回答文档(answer.doc_artifact)组装时就遮好了,原样给。
不是这次运行的质询引用过的回 404:工件 id 不能拿来取任意快照
不受理:409 {detail, code}(inquiry_not_open / inquiry_busy / inquiry_disabled);输入不合法 422 {detail, field},
field 指明是哪一项(前后端约定的形状,不是 FastAPI 自己那种校验错误数组,所以请求体自己解析)。
"""
from __future__ import annotations
from typing import Any
from fastapi import APIRouter, Header, HTTPException, Request
from fastapi.responses import JSONResponse
from app.api.coded import CodedHTTPException
from app.api.runs import actor_of
from app.engine import inquiry
from app.engine.inquiry import InquiryRefused
router = APIRouter(prefix="/api/runs", tags=["inquiry"])
def _refused(e: InquiryRefused) -> Any:
"""不受理 → HTTP 响应。422 照约定只回 {detail, field};其余带机读码的回 {detail, code}。"""
if e.status == 422:
return JSONResponse(status_code=422, content={"detail": e.message, "field": e.field})
if e.code:
raise CodedHTTPException(e.status, e.message, e.code)
raise HTTPException(e.status, e.message)
@router.post("/{run_id}/inquiries", response_model=None)
async def ask_inquiry(run_id: str, request: Request, x_actor: str | None = Header(default=None)) -> Any:
"""问一个问题。回答要等 agent 查完库(最长约为设置里的时长上限再加半分钟收尾),接口一直等到回答完才返回。"""
try:
body = await request.json()
except (ValueError, UnicodeDecodeError):
body = None
try:
return await inquiry.ask(run_id, inquiry.parse_ask(body), actor=actor_of(x_actor))
except InquiryRefused as e:
return _refused(e)
@router.get("/{run_id}/inquiries", response_model=None)
async def list_inquiries(run_id: str, report: str | None = None, unit: str | None = None) -> Any:
try:
return {"items": await inquiry.list_inquiries(run_id, report=report or None, unit=unit or None)}
except InquiryRefused as e:
return _refused(e)
@router.get("/{run_id}/inquiries/artifacts/{artifact_id}", response_model=None)
async def inquiry_artifact(run_id: str, artifact_id: str) -> Any:
try:
return await inquiry.inquiry_artifact(run_id, artifact_id)
except InquiryRefused as e:
return _refused(e)