fix: strip tool_call JSON fragments from reply text before display and history

This commit is contained in:
ymq 2026-08-10 00:08:40 +08:00
parent 3e8fc551ef
commit cb5846c39e

View File

@ -154,7 +154,10 @@ def _parse(raw):
d = json.loads(raw)
if isinstance(d,dict) and 'action' in d: return d
except: pass
return {"action":"reply","message":raw}
# Strip any {"action":"tool_call"...} JSON fragments from reply text
import re as _re2
clean = _re2.sub(r'\s*\{[^}]*"action"\s*:\s*"tool_call"[^}]*\}\s*', ' ', raw).strip()
return {"action":"reply","message":clean or raw}
def _w_text(t): return {"widgettype":"Text","options":{"text":t,"css":"agent-text","halign":"left"}}
def _w_card(title, body, kind="success"):