diff --git a/routes/chat.py b/routes/chat.py index 764c0fc..6d98388 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -93,6 +93,7 @@ async def enhanced_generate_stream_response( chunk_id = 0 message_tag = "" current_tool_name = "" + current_is_ui_tool = False last_answer_first_char_duration_ms = None waiting_for_answer_first_char = False agent, checkpointer, sandbox = await init_agent(config) @@ -114,9 +115,12 @@ async def enhanced_generate_stream_response( chunk_args = tool_call_chunk.get("args") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "args", None) if chunk_name: current_tool_name = chunk_name + current_is_ui_tool = False # Always output ui:// protocol tool calls even when tool_response is disabled - is_ui_tool = isinstance(chunk_args, str) and '"ui://' in (chunk_args or '') - if config.tool_response or is_ui_tool: + # Detect ui:// in chunk args; once detected, all subsequent chunks for this tool are UI + if isinstance(chunk_args, str) and '"ui://' in chunk_args: + current_is_ui_tool = True + if config.tool_response or current_is_ui_tool: if chunk_name: new_content = f"[{message_tag}] {chunk_name}\n" if chunk_args: