From 20a60e7ff54fac90f6e11c6006ff968e6105c8d4 Mon Sep 17 00:00:00 2001 From: devorun <130918800+devorun@users.noreply.github.com> Date: Fri, 20 Mar 2026 19:11:21 +0300 Subject: [PATCH] Fix: Add iteration boundary linebreak to prevent stream concatenation after tool calls Fixes #2177 When streaming is enabled, the `GatewayStreamConsumer` continuously appends text to a single buffer. Previously, when the agent paused to execute tool calls and then resumed streaming, the new text was concatenated directly onto the prior text without any separation, resulting in unreadable formatting. This PR adds a simple `self._fire_stream_delta("\n\n")` signal immediately after `_execute_tool_calls()` in `run_agent.py`. This ensures a clean paragraph break is inserted into the stream buffer whenever an iteration boundary occurs, fixing the multi-iteration formatting on platforms like Telegram and Discord --- run_agent.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run_agent.py b/run_agent.py index 1c3b25fe227ae..71e4d3e84e174 100644 --- a/run_agent.py +++ b/run_agent.py @@ -6572,6 +6572,9 @@ def _stop_spinner(): _msg_count_before_tools = len(messages) self._execute_tool_calls(assistant_message, messages, effective_task_id, api_call_count) + # Signal iteration boundary to stream consumers to prevent text concatenation + self._fire_stream_delta("\n\n") + # Refund the iteration if the ONLY tool(s) called were # execute_code (programmatic tool calling). These are # cheap RPC-style calls that shouldn't eat the budget.