Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(chat): strip the tool-call wrapper, not just the JSON inside it

purple35737ac123b3
diff --git a/src/lib/__tests__/tool-call-repair.test.ts b/src/lib/__tests__/tool-call-repair.test.ts
index 073f9ade..58d34a82 100644
--- a/src/lib/__tests__/tool-call-repair.test.ts
+++ b/src/lib/__tests__/tool-call-repair.test.ts
@@ -13,6 +13,8 @@ import {
repairJson,
repairToolCallArgs,
extractToolCallsFromContent,
+ extractToolCallsWithRanges,
+ stripRanges,
} from '../tool-call-repair'
describe('tool-call-repair', () => {
@@ -321,3 +323,30 @@ And after.`
})
})
})
+
+// Live Agent run on the ship exe, 2026-07-25: a model wrapped its call in the
+// Hermes tags, stripRanges removed only the JSON, and the leftover `<tool_call>`
+// rendered as a stray `ool_call>` in the transcript (the renderer eats the first
+// two chars of an unknown tag).
+describe('stripRanges clears the tool-call wrapper, not just the JSON', () => {
+ const strip = (content: string) => {
+ const { ranges } = extractToolCallsWithRanges(content)
+ return stripRanges(content, ranges)
+ }
+
+ it('leaves no Hermes tag behind', () => {
+ const out = strip('Let me look.\n<tool_call>\n{"name": "file_list", "arguments": {"path": "."}}\n</tool_call>')
+ expect(out).not.toContain('tool_call')
+ expect(out).toBe('Let me look.')
+ })
+
+ it('handles the pipe and bracket spellings too', () => {
+ expect(strip('<|tool_call|>{"name": "file_read", "arguments": {"path": "a"}}<|/tool_call|>')).toBe('')
+ expect(strip('[TOOL_CALL]{"name": "file_read", "arguments": {"path": "a"}}[/TOOL_CALL]')).toBe('')
+ })
+
+ it('does not touch ordinary prose that merely mentions the words', () => {
+ const prose = 'the tool call failed, try again'
+ expect(stripRanges(prose, [])).toBe(prose)
+ })
+})
diff --git a/src/lib/tool-call-repair.ts b/src/lib/tool-call-repair.ts
index 80b74ea0..fc03b226 100644
--- a/src/lib/tool-call-repair.ts
+++ b/src/lib/tool-call-repair.ts
@@ -200,6 +200,16 @@ export function stripRanges(content: string, ranges: Array<[number, number]>): s
}
// Remove orphan fence lines left behind by the JSON strip.
out = out.replace(/```(?:json)?\s*\n?\s*```/g, '')
+ // Remove the tool-call TAGS the JSON sat inside. We only strip the JSON range
+ // itself above, so a model that wraps its call in the Hermes tags leaves
+ // `<tool_call>` and `</tool_call>` behind — and the renderer eats the first
+ // two characters of an unknown tag, so the user sees a stray `ool_call>` in
+ // the transcript (live Agent run on the ship exe, 2026-07-25). Also covers
+ // the `<|tool_call|>` / `[TOOL_CALL]` spellings other families use.
+ // The slash sits outside the pipes in some spellings (`</tool_call>`) and
+ // inside in others (`<|/tool_call|>`), so allow any mix on either side.
+ out = out.replace(/<[|/\s]*tool_calls?[|/\s]*>/gi, '')
+ out = out.replace(/\[[/\s]*TOOL_CALLS?[/\s]*\]/gi, '')
// Collapse 3+ consecutive blank lines down to one blank line so the chat
// bubble doesn't have a sea of whitespace where the JSON used to be.
out = out.replace(/\n{3,}/g, '\n\n')