Repository navigation
fix(ui): hold native tool-call markup and long calls out of the chat - #5131
Conversation
A reply that called a tool with a long argument (a write_file carrying a
whole file) reached the TUI as a raw {"thought": ...} line above the tool
rows. The stream filter flushed any tool-call JSON past 2 KB as text, and
a plan envelope whose head the cleanup regex ate leaked its tail.
The handler now recognises the response envelope at the head of the
stream (optionally fenced), holds it until its closing brace with a
string-aware, resumable scan, and drops it; an "answer" field is still
emitted as the answer. Ordinary JSON answers and text that merely starts
with "{" are untouched.
A hosted model that writes its tool calls as DeepSeek DSML markup had every
call stream into the answer area, up to 50 times a turn, with long Python
mangled by markdown. A narration line sharing a token with a JSON envelope,
and a long thought with an unescaped quote, leaked the same way.
The stream filter now holds native call markup (DSML, the older DeepSeek
special tokens, XML invoke/function_calls/tool_call, harmony channels) from
opener to closer and drops it; markup quoted in a code block still shows.
An envelope that opens on its own line after prose is split off, and an
envelope led by a protocol key that will not parse is held whole.
While a call is held, the activity line now says what is being written and
how big it is ("Writing Python code — 4,210 characters so far"), or
"Reasoning — N words so far" while the envelope's thought streams, instead
of a bare timer.
A reply that mentioned a tag like <tool_call> in passing, or in its reasoning, lost everything after it from the stream, since the filter took it for a call with no closer. Plain-XML openers now count only at the start of a line; DSML and DeepSeek's special tokens still count anywhere. Code fences are tracked the way Markdown does (a marker at a line start, closed by the same kind), on the text actually shown, so stray backticks in prose or a dropped fenced envelope no longer make later calls look like examples. Markup arriving in the token that closes an envelope is filtered too.
|
Verdict: Approve with suggestions Tool calls that a model writes as text (DeepSeek DSML, Qwen/Claude XML, harmony channels) no longer stream into the chat. Long calls now show a progress line that gives the size, never the content. The filter is careful: it is fence-aware, handles tags split across tokens, resets state between model calls, and isn't quadratic. All 347 tests in the test plan pass locally. I found nothing blocking. Two things to know:
Real-world evidenceThe evidence stage ran the real
The rendered Agent UI screenshot is pending the strix-halo lane; this runner has no real inference. The route-level evidence above is enough for merge. 🔍 Technical details🟢 Inline DSML / special-token / harmony openers in prose swallow the rest of the stream ( I fed these through
Only families 4–6 are restricted to line starts. Inline code spans aren't treated like fences either. With no closer in the reply, the opener holds everything until end-of-stream, and the user sees "Preparing a tool call — N characters so far" in the meantime. One fix: skip an opener that sits inside an open single-backtick span on the current line. Or apply the line-start rule to every family except the 🟢 Final-answer path doesn't strip markup (
🟢 Behaviour change worth a line in the description A reply led by Strengths
|
# Conflicts: # src/gaia/agents/base/agent.py
# Conflicts: # src/gaia/ui/sse_handler.py
The envelope filter held every leading JSON object until its closing brace, so an answer-first reply no longer streamed token by token as the answer decoder on main does. Answer-first envelopes now go to that path; every other envelope is still held and filtered.
…5131 # Conflicts: # src/gaia/agents/base/agent.py # src/gaia/ui/sse_handler.py
# Conflicts: # src/gaia/ui/sse_handler.py # tests/unit/chat/ui/test_sse_handler.py
When a hosted model wrote its tool calls as text (DeepSeek's DSML markup), every call streamed into the answer area while it was being written: up to 50 times in one turn, with long Python mangled by Markdown into headings. Long calls in GAIA's own JSON format either leaked the same way or sat behind a bare "Reading the tool results · 90s" timer. Now the call is held back and dropped, and the activity line says what is being written and how big it is ("Writing Python code — 4,210 characters so far"), never its content. Markup quoted in a code block, or a tag named in prose, still shows.
Stacked on #5121 (the JSON-envelope half of this filter); pairs with #5103, which makes the agent run DSML calls instead of answering with them. This changes what the LLM's output looks like to the user, not what the LLM sees; the flagship eval that runs on main covers it.
Test plan
python -m pytest tests/unit/chat/ui/test_sse_tool_call_text.py tests/unit/chat/ui/test_sse_handler.py tests/unit/test_model_phase_progress.py tests/unit/test_tool_call_progress.pychunkevent, and every final answer still streamsrun_pythonreply: before, the code scrolled past as headings; after, only the narration line and "Writing Python code — N characters so far" showpython util/lint.py --black --isort