From 5db59bc9cf9045a723839766aa170598ca88f62f Mon Sep 17 00:00:00 2001 From: wxy Date: Fri, 3 Apr 2026 14:32:41 +0800 Subject: [PATCH] fix(workflow): persist citations in conversation message meta_data --- api/app/services/workflow_service.py | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/api/app/services/workflow_service.py b/api/app/services/workflow_service.py index 97715ee9..8c1ab7c7 100644 --- a/api/app/services/workflow_service.py +++ b/api/app/services/workflow_service.py @@ -722,12 +722,18 @@ class WorkflowService: content=human_message, meta_data=human_meta ) + # 过滤 citations + citations = result.get("citations", []) + citation_cfg = feature_configs.get("citation", {}) + filtered_citations = ( + citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else [] + ) self.conversation_service.add_message( message_id=message_id, conversation_id=conversation_id_uuid, role="assistant", content=assistant_message, - meta_data={"usage": token_usage, "audio_url": None} + meta_data={"usage": token_usage, "audio_url": None, "citations": filtered_citations} ) self.update_execution_status( execution.execution_id, @@ -746,13 +752,7 @@ class WorkflowService: ) logger.error(f"Workflow Run Failed, execution_id: {execution.execution_id}," f" error: {result.get('error')}") - - # 过滤 citations - citations = result.get("citations", []) - citation_cfg = feature_configs.get("citation", {}) - filtered_citations = ( - citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else [] - ) + filtered_citations = [] # 返回增强的响应结构 return { @@ -917,12 +917,18 @@ class WorkflowService: content=human_message, meta_data=human_meta ) + # 过滤 citations + citations = event.get("data", {}).get("citations", []) + citation_cfg = feature_configs.get("citation", {}) + filtered_citations = ( + citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else [] + ) self.conversation_service.add_message( message_id=message_id, conversation_id=conversation_id_uuid, role="assistant", content=assistant_message, - meta_data={"usage": token_usage, "audio_url": None} + meta_data={"usage": token_usage, "audio_url": None, "citations": filtered_citations} ) self.update_execution_status( execution.execution_id, @@ -930,12 +936,6 @@ class WorkflowService: output_data=event.get("data"), token_usage=token_usage.get("total_tokens", None) ) - # 注入 citations 到 workflow_end 事件 - citations = event.get("data", {}).get("citations", []) - citation_cfg = feature_configs.get("citation", {}) - filtered_citations = ( - citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else [] - ) event.setdefault("data", {})["citations"] = filtered_citations logger.info(f"Workflow Run Success, " f"execution_id: {execution.execution_id}, message count: {len(final_messages)}")