feat: 重构处理历史与通知留痕追踪
This commit is contained in:
@@ -57,6 +57,14 @@ def run_agent(scenario_config: dict, user_input: str, options: dict | None = Non
|
||||
latency_ms=latency_ms,
|
||||
status="failed",
|
||||
error=str(llm_response.error or "未知模型错误"),
|
||||
conversation_id=str(options.get("conversation_id", "")),
|
||||
batch_id=str(options.get("batch_id", "")),
|
||||
product_name=str(options.get("product_name", "")),
|
||||
notification_payload=_build_notification_payload(
|
||||
{"notify_reason": "task_failed", "owner_roles": []},
|
||||
options=options,
|
||||
status="failed",
|
||||
),
|
||||
)
|
||||
|
||||
structured_output, _ = parse_structured_output(llm_response.content, output_type)
|
||||
@@ -70,6 +78,11 @@ def run_agent(scenario_config: dict, user_input: str, options: dict | None = Non
|
||||
model_name=llm_response.model_name or "unknown-model",
|
||||
latency_ms=latency_ms,
|
||||
status="success",
|
||||
conversation_id=str(options.get("conversation_id", "")),
|
||||
batch_id=str(options.get("batch_id", "")),
|
||||
product_name=str(options.get("product_name", "")),
|
||||
node_results=_build_node_results(output_type, structured_output),
|
||||
notification_payload=_build_notification_payload(structured_output, options=options, status="success"),
|
||||
)
|
||||
|
||||
|
||||
@@ -151,3 +164,29 @@ def _format_tool_calls(tool_calls: list[dict]) -> str:
|
||||
f"{index}. 工具={tool_call.get('tool_name')} 失败={tool_call.get('error', '未知错误')}"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _build_node_results(output_type: str, structured_output: dict) -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"code": output_type,
|
||||
"label": output_type,
|
||||
"status": "已完成",
|
||||
"summary": structured_output.get("summary") or structured_output.get("answer", ""),
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def _build_notification_payload(structured_output: dict, options: dict, status: str) -> dict:
|
||||
notify_reason = structured_output.get("notify_reason") or (
|
||||
"task_completed" if status == "success" else "task_failed"
|
||||
)
|
||||
owners = structured_output.get("owner_roles") or []
|
||||
return {
|
||||
"batch_id": str(options.get("batch_id", "")),
|
||||
"conversation_id": str(options.get("conversation_id", "")),
|
||||
"product_name": str(options.get("product_name", "")),
|
||||
"notify_reason": notify_reason,
|
||||
"owners": owners,
|
||||
"status": status,
|
||||
}
|
||||
|
||||
@@ -20,3 +20,8 @@ class AgentResult:
|
||||
latency_ms: int = 0
|
||||
status: str = "success"
|
||||
error: str = ""
|
||||
conversation_id: str = ""
|
||||
batch_id: str = ""
|
||||
product_name: str = ""
|
||||
node_results: list = field(default_factory=list)
|
||||
notification_payload: dict = field(default_factory=dict)
|
||||
|
||||
@@ -6,6 +6,8 @@ SUPPORTED_OUTPUT_TYPES = {
|
||||
"registration_field_extraction_report",
|
||||
"registration_consistency_report",
|
||||
"registration_risk_report",
|
||||
"registration_word_export_report",
|
||||
"feishu_notification_report",
|
||||
"ticket_response",
|
||||
"quality_report",
|
||||
"risk_audit_report",
|
||||
|
||||
@@ -41,6 +41,60 @@ OUTPUT_FIELD_TEMPLATES = {
|
||||
"suggestions": [],
|
||||
"references": [],
|
||||
},
|
||||
"registration_overview_report": {
|
||||
"batch_id": "",
|
||||
"product_name": "",
|
||||
"file_count": 0,
|
||||
"total_page_count": 0,
|
||||
"chapter_summary": [],
|
||||
"documents": [],
|
||||
"warnings": [],
|
||||
},
|
||||
"registration_completeness_report": {
|
||||
"summary": "",
|
||||
"missing_items": [],
|
||||
"misplaced_items": [],
|
||||
"risk_level": "medium",
|
||||
"references": [],
|
||||
},
|
||||
"registration_field_extraction_report": {
|
||||
"summary": "",
|
||||
"field_items": [],
|
||||
"low_confidence_items": [],
|
||||
"references": [],
|
||||
},
|
||||
"registration_consistency_report": {
|
||||
"summary": "",
|
||||
"conflict_items": [],
|
||||
"mixed_document_risks": [],
|
||||
"risk_level": "medium",
|
||||
"references": [],
|
||||
},
|
||||
"registration_risk_report": {
|
||||
"summary": "",
|
||||
"risk_items": [],
|
||||
"highest_risk_level": "medium",
|
||||
"pass_status": "review_required",
|
||||
"manual_review_items": [],
|
||||
"owner_roles": [],
|
||||
"suggestions": [],
|
||||
"notify_reason": "task_completed",
|
||||
},
|
||||
"registration_word_export_report": {
|
||||
"summary": "",
|
||||
"export_status": "draft_only",
|
||||
"blocked_items": [],
|
||||
"download_url": "",
|
||||
},
|
||||
"feishu_notification_report": {
|
||||
"batch_id": "",
|
||||
"conversation_id": "",
|
||||
"notify_reason": "task_completed",
|
||||
"mentioned_users": [],
|
||||
"message_status": "pending",
|
||||
"web_detail_url": "",
|
||||
"receipt": {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user