From a4a67c1a0050c77b931339c0b74e62fd6ab23147 Mon Sep 17 00:00:00 2001 From: fengxiangdebaozi <10845145+fengxiangdebaozi@user.noreply.gitee.com> Date: Thu, 25 Jun 2026 00:48:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai=E5=86=99=E4=BD=9C):=20=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E6=B5=81=E5=BC=8F=E6=AF=8F=E6=AD=A5=E4=B8=BB=E5=8A=A8=E8=AE=A9?= =?UTF-8?q?=E5=87=BA=E4=BA=8B=E4=BB=B6=E5=BE=AA=E7=8E=AF=EF=BC=8Ccustom=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=AE=9E=E6=97=B6=E5=88=B7=E7=BB=99=E5=89=8D?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端 skill_search_step 已是 pushImmediate(实时渲染),但事件在节点内的嵌套 agent.astream 里发出后没及时让出事件循环,被攒到整段跑完才一次性吐到 SSE, 前端看着像卡死。每个 chunk 处理完 await asyncio.sleep(0) 主动让出,促使刚 emit 的 custom 事件实时刷给前端(对齐 draft_chunk 的实时行为)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../deerflow/agents/ai_writing/nodes/_skill_agent.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/_skill_agent.py b/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/_skill_agent.py index 617dbb4b..6fd6a915 100644 --- a/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/_skill_agent.py +++ b/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/_skill_agent.py @@ -210,6 +210,7 @@ async def run_skill_via_real_agent( init_state, config=run_config, context=run_context, stream_mode="values" ): msgs = chunk.get("messages") or [] + emitted = False for m in msgs: mid = getattr(m, "id", None) if not mid or mid in seen_msg_ids: @@ -221,11 +222,16 @@ async def run_skill_via_real_agent( break tname = (tc.get("name") or "").strip() or "工具" emit_query(f"技能「{skill_name}」调用 {tname}:{_summarize_tool_args(tc.get('args') or {})}") + emitted = True # 记录最后一条 AIMessage 正文(含最终 JSON 素材) if isinstance(m, AIMessage): text = _content_to_text(m.content) if text.strip(): final_text = text + # 关键:每个 chunk 处理完主动让出事件循环,促使刚 emit 的 custom 事件**实时** + # 刷给前端 SSE;否则嵌套 astream 会把它们攒到整段跑完才一次性吐出(前端看着像卡死)。 + if emitted: + await asyncio.sleep(0) try: await asyncio.wait_for(_drive(), timeout=max(timeout_s, _REAL_AGENT_TIMEOUT_SECONDS))