fix(api): stop emitting StreamChunkEvent from tool path to prevent answer duplication

The EventAdapter was converting every LLMResultChunk from the agent
strategy into StreamChunkEvent. Combined with the answer node's
{{#agent.text#}} variable output, this caused the final answer to
appear twice (e.g., "It is 2026-04-09 04:27:45.It is 2026-04-09 04:27:45.").

Now LLMResultChunk from strategy output is silently consumed (text still
accumulates in AgentResult.text via the strategy). Only AgentLogEvent
(thought/tool_call/round) is forwarded to the pipeline.

Known remaining issues:
- workflow/message level total_tokens=0 (node level is correct at 33)
  because pipeline aggregation doesn't include agent-v2 node tokens
- Turn 2 SSE delivery timing with Redis pubsub (celery executes OK)

Made-with: Cursor
This commit is contained in:
Yansong Zhang 2026-04-09 12:31:49 +08:00
parent 3d4be88d97
commit 4f010cd4f5

View File

@ -39,7 +39,7 @@ class AgentV2EventAdapter:
if isinstance(item, AgentLog):
yield self._convert_agent_log(item, node_id=node_id, node_execution_id=node_execution_id)
elif isinstance(item, LLMResultChunk):
yield from self._convert_llm_chunk(item, node_id=node_id)
pass
except StopIteration as e:
result: AgentResult = e.value
return result