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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user