refactor(backend): update orchestrator endpoint and services

- endpoints/orchestrator.py: update orchestrator API endpoint
- services/agent_conversations.py: update agent conversations service
- services/orchestrator.py: update orchestrator service
- services/user_agent.py: update user agent service
This commit is contained in:
caoxiaozhu
2026-05-13 13:06:52 +00:00
parent 0f7bd43ce3
commit 70cff69b7f
4 changed files with 359 additions and 20 deletions

View File

@@ -85,6 +85,15 @@ GROUP_SCENE_LABELS = {
"other": "其他费用",
}
EXPENSE_STATUS_LABELS = {
"draft": "草稿",
"submitted": "已提交",
"review": "审核中",
"approved": "已通过",
"rejected": "已驳回",
"paid": "已付款",
}
SLOT_LABELS = {
"expense_type": "报销类型",
"customer_name": "客户名称",
@@ -389,10 +398,41 @@ class UserAgentService:
if scenario == "expense":
record_count = int(data.get("record_count") or 0)
total_amount = float(data.get("total_amount") or 0)
return (
f"{subject}共命中 {record_count} 笔报销,金额合计 {total_amount:.2f} 元。"
"如需继续处理,可以查看明细或生成处理意见草稿。"
)
scope_label = str(data.get("scope_label") or subject).strip() or subject
preview_records = data.get("records")
if record_count <= 0:
return f"当前没有查到{scope_label}。你可以补充时间范围、单号或状态继续筛选。"
summary = f"查到{scope_label}{record_count} 笔,金额合计 {total_amount:.2f} 元。"
if not isinstance(preview_records, list) or not preview_records:
return f"{summary} 如需继续处理,可以查看明细或生成处理意见草稿。"
preview_text: list[str] = []
for item in preview_records[:3]:
if not isinstance(item, dict):
continue
claim_no = str(item.get("claim_no") or "未编号").strip() or "未编号"
occurred_at = str(item.get("occurred_at") or "").strip()
expense_type = EXPENSE_TYPE_LABELS.get(
str(item.get("expense_type") or "").strip(),
str(item.get("expense_type") or "报销").strip() or "报销",
)
amount = float(item.get("amount") or 0)
status = EXPENSE_STATUS_LABELS.get(
str(item.get("status") or "").strip(),
str(item.get("status") or "处理中").strip() or "处理中",
)
date_prefix = f"{occurred_at}" if occurred_at else ""
preview_text.append(
f"{claim_no}{date_prefix}{expense_type}{amount:.2f} 元,{status}"
)
if not preview_text:
return f"{summary} 如需继续处理,可以查看明细或生成处理意见草稿。"
has_more = bool(data.get("has_more")) or record_count > len(preview_records)
more_hint = " 当前先展示最近几笔,可继续查看明细。" if has_more else ""
return f"{summary} 其中包括:{''.join(preview_text)}{more_hint}".strip()
if scenario == "accounts_receivable":
record_count = int(data.get("record_count") or 0)
@@ -1249,6 +1289,8 @@ class UserAgentService:
payload: UserAgentRequest,
review_payload: UserAgentReviewPayload | None,
) -> bool:
if payload.ontology.scenario == "expense" and payload.ontology.intent in {"query", "compare"}:
return True
if review_payload is None:
return False
return payload.ontology.scenario == "expense" and (