refactor(backend): update services and register OCR router

- router.py: register ocr_router with OCR tag
- ontology.py: update ontology service logic
- orchestrator.py: update orchestrator service logic
- user_agent.py: update user agent schema and service
- schemas/user_agent.py: update user agent data schemas
This commit is contained in:
caoxiaozhu
2026-05-12 03:03:15 +00:00
parent 33826929ba
commit ca29025063
5 changed files with 56 additions and 14 deletions

View File

@@ -142,8 +142,11 @@ class UserAgentService:
return self._build_implicit_expense_draft_guidance(payload)
attachment_names = self._resolve_attachment_names(payload)
ocr_summary = str(payload.context_json.get("ocr_summary") or "").strip()
attachment_hint = ""
if attachment_names:
if ocr_summary:
attachment_hint = f" 我已读取附件 OCR 摘要:{ocr_summary}"
elif attachment_names:
attachment_hint = (
f" 我已带入 {len(attachment_names)} 份附件名称,但目前还不能直接读取附件内容,"
"仍需要你补充关键信息。"
@@ -238,6 +241,8 @@ class UserAgentService:
"request_context": payload.context_json.get("request_context"),
"attachment_count": payload.context_json.get("attachment_count"),
"attachment_names": self._resolve_attachment_names(payload),
"ocr_summary": payload.context_json.get("ocr_summary", ""),
"ocr_documents": payload.context_json.get("ocr_documents", []),
},
"tool_payload": payload.tool_payload,
"citations": [item.model_dump(mode="json") for item in citations],
@@ -348,7 +353,11 @@ class UserAgentService:
def _build_draft_payload(self, payload: UserAgentRequest) -> UserAgentDraftPayload:
scenario_label = SCENARIO_LABELS.get(payload.ontology.scenario, "业务")
subject = self._resolve_subject(payload)
claim_no = str(payload.tool_payload.get("claim_no") or "").strip() or None
claim_status = str(payload.tool_payload.get("status") or "").strip() or None
title = f"{scenario_label}处理意见草稿"
if claim_no:
title = f"{scenario_label}草稿 {claim_no}"
body = (
f"主题:{subject}\n"
"结论:已根据当前语义解析结果生成草稿,尚未自动执行。\n"
@@ -360,6 +369,9 @@ class UserAgentService:
title=title,
body=body,
confirmation_required=True,
claim_id=str(payload.tool_payload.get("claim_id") or "").strip() or None,
claim_no=claim_no,
status=claim_status,
)
def _build_suggested_actions(