feat: 增强注册审核节点式结果输出
This commit is contained in:
@@ -167,6 +167,8 @@ def _format_tool_calls(tool_calls: list[dict]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _build_node_results(output_type: str, structured_output: dict) -> list[dict]:
|
def _build_node_results(output_type: str, structured_output: dict) -> list[dict]:
|
||||||
|
if output_type.startswith("registration_") or output_type == "feishu_notification_report":
|
||||||
|
return _build_registration_node_results(output_type, structured_output)
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"code": output_type,
|
"code": output_type,
|
||||||
@@ -190,3 +192,58 @@ def _build_notification_payload(structured_output: dict, options: dict, status:
|
|||||||
"owners": owners,
|
"owners": owners,
|
||||||
"status": status,
|
"status": status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _build_registration_node_results(output_type: str, structured_output: dict) -> list[dict]:
|
||||||
|
nodes = [
|
||||||
|
{"code": "package_import", "label": "资料包导入", "status": "已完成"},
|
||||||
|
{"code": "overview", "label": "目录汇总", "status": "待处理"},
|
||||||
|
{"code": "completeness", "label": "法规完整性检查", "status": "待处理"},
|
||||||
|
{"code": "field_extraction", "label": "字段抽取", "status": "待处理"},
|
||||||
|
{"code": "consistency", "label": "一致性核查", "status": "待处理"},
|
||||||
|
{"code": "risk", "label": "风险预警", "status": "待处理"},
|
||||||
|
{"code": "word_export", "label": "Word 回填导出", "status": "待处理"},
|
||||||
|
{"code": "feishu_notify", "label": "飞书通知", "status": "待处理"},
|
||||||
|
]
|
||||||
|
progression_map = {
|
||||||
|
"registration_overview_report": 1,
|
||||||
|
"registration_completeness_report": 2,
|
||||||
|
"registration_field_extraction_report": 3,
|
||||||
|
"registration_consistency_report": 4,
|
||||||
|
"registration_risk_report": 5,
|
||||||
|
"registration_word_export_report": 6,
|
||||||
|
"feishu_notification_report": 7,
|
||||||
|
}
|
||||||
|
completed_index = progression_map.get(output_type, 0)
|
||||||
|
for index in range(1, completed_index + 1):
|
||||||
|
nodes[index]["status"] = "已完成"
|
||||||
|
|
||||||
|
if output_type == "registration_risk_report":
|
||||||
|
pass_status = structured_output.get("pass_status", "")
|
||||||
|
if pass_status in {"blocked", "failed"}:
|
||||||
|
nodes[5]["status"] = "已阻断"
|
||||||
|
elif pass_status in {"review_required", "manual_review"}:
|
||||||
|
nodes[5]["status"] = "待复核"
|
||||||
|
else:
|
||||||
|
nodes[5]["status"] = "已完成"
|
||||||
|
return nodes
|
||||||
|
|
||||||
|
if output_type == "registration_word_export_report":
|
||||||
|
export_status = structured_output.get("export_status", "")
|
||||||
|
if export_status in {"blocked", "draft_only"}:
|
||||||
|
nodes[6]["status"] = "已阻断" if export_status == "blocked" else "待复核"
|
||||||
|
else:
|
||||||
|
nodes[6]["status"] = "已完成"
|
||||||
|
return nodes
|
||||||
|
|
||||||
|
if output_type == "feishu_notification_report":
|
||||||
|
message_status = structured_output.get("message_status", "")
|
||||||
|
if message_status in {"failed", "error"}:
|
||||||
|
nodes[7]["status"] = "失败"
|
||||||
|
elif message_status in {"sent", "success"}:
|
||||||
|
nodes[7]["status"] = "已完成"
|
||||||
|
else:
|
||||||
|
nodes[7]["status"] = "待处理"
|
||||||
|
return nodes
|
||||||
|
|
||||||
|
return nodes
|
||||||
|
|||||||
@@ -305,3 +305,50 @@ def test_registration_risk_result_includes_owner_fields_and_notification_payload
|
|||||||
def test_supported_output_types_include_word_export_and_feishu_notification():
|
def test_supported_output_types_include_word_export_and_feishu_notification():
|
||||||
assert "registration_word_export_report" in SUPPORTED_OUTPUT_TYPES
|
assert "registration_word_export_report" in SUPPORTED_OUTPUT_TYPES
|
||||||
assert "feishu_notification_report" in SUPPORTED_OUTPUT_TYPES
|
assert "feishu_notification_report" in SUPPORTED_OUTPUT_TYPES
|
||||||
|
|
||||||
|
|
||||||
|
def test_registration_risk_report_builds_eight_business_nodes():
|
||||||
|
scenario = {
|
||||||
|
"id": "document_review",
|
||||||
|
"name": "注册审核智能体",
|
||||||
|
"agent": {
|
||||||
|
"role": "注册审核助手",
|
||||||
|
"goal": "输出风险结果",
|
||||||
|
"instructions": ["输出结构化风险结果"],
|
||||||
|
},
|
||||||
|
"rag": {"enabled": False},
|
||||||
|
"tools": [],
|
||||||
|
"output": {"type": "registration_risk_report"},
|
||||||
|
}
|
||||||
|
provider_response = """
|
||||||
|
{
|
||||||
|
"summary": "存在高风险项,需人工复核。",
|
||||||
|
"highest_risk_level": "high",
|
||||||
|
"pass_status": "blocked",
|
||||||
|
"owner_roles": [],
|
||||||
|
"notify_reason": "task_completed"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
class FakeProvider:
|
||||||
|
def generate(self, messages, response_format=None):
|
||||||
|
from agent_core.llm_provider import LLMResponse
|
||||||
|
|
||||||
|
return LLMResponse(content=provider_response, model_name="demo-model", success=True)
|
||||||
|
|
||||||
|
result = run_agent(scenario, "请输出风险结果", options={"llm_provider": FakeProvider()})
|
||||||
|
|
||||||
|
assert len(result.node_results) == 8
|
||||||
|
assert [node["label"] for node in result.node_results] == [
|
||||||
|
"资料包导入",
|
||||||
|
"目录汇总",
|
||||||
|
"法规完整性检查",
|
||||||
|
"字段抽取",
|
||||||
|
"一致性核查",
|
||||||
|
"风险预警",
|
||||||
|
"Word 回填导出",
|
||||||
|
"飞书通知",
|
||||||
|
]
|
||||||
|
assert result.node_results[5]["status"] == "已阻断"
|
||||||
|
assert result.node_results[6]["status"] == "待处理"
|
||||||
|
assert result.node_results[7]["status"] == "待处理"
|
||||||
|
|||||||
Reference in New Issue
Block a user