From 9b00a5f3f1cc06fc2fad285ee0d84d8a4fe36fec Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 23 Mar 2026 17:23:44 +0800 Subject: [PATCH] refactor: Update agent stream processing to support 'v2' chunk format and prevent emitting empty content. --- app/agent/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/agent/__init__.py b/app/agent/__init__.py index e36822d5..59a28875 100644 --- a/app/agent/__init__.py +++ b/app/agent/__init__.py @@ -166,12 +166,16 @@ class MoviePilotAgent: async for chunk in agent.astream( {"messages": messages}, stream_mode="messages", - config=agent_config + config=agent_config, + version="v2" ): - token, metadata = chunk # 处理流式token(过滤工具调用token,只保留模型生成的内容) - if token and hasattr(token, "tool_call_chunks") and not token.tool_call_chunks: - self.stream_handler.emit(token.content) + if chunk["type"] == "messages": + token, metadata = chunk["data"] + if (token and hasattr(token, "tool_call_chunks") + and not token.tool_call_chunks): + if token.content: + self.stream_handler.emit(token.content) # 发送最终消息给用户 await self.send_agent_message(