refactor: Update agent stream processing to support 'v2' chunk format and prevent emitting empty content.

This commit is contained in:
jxxghp
2026-03-23 17:23:44 +08:00
parent 565e10b6a5
commit 9b00a5f3f1

View File

@@ -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(