惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
Y
Y Combinator Blog
博客园_首页
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
B
Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
WordPress大学
WordPress大学
L
LangChain Blog
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 test: merge chat context notice checks · openclaw/openclaw@5c2f4af feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248
fix: strip standalone <function> tool call tags from visi...
2026-04-16 · via Recent Commits to openclaw:main

@@ -15,19 +15,23 @@ const MEMORY_TAG_QUICK_RE = /<\s*\/?\s*relevant[-_]memories\b/i;

1515

* This stateful pass hides content from an opening tag through the matching

1616

* closing tag, or to end-of-string if the stream was truncated mid-tag.

1717

*/

18-

const TOOL_CALL_QUICK_RE = /<\s*\/?\s*(?:tool_call|tool_result|function_calls?|tool_calls)\b/i;

18+

const TOOL_CALL_QUICK_RE =

19+

/<\s*\/?\s*(?:tool_call|tool_result|function_calls?|function|tool_calls)\b/i;

1920

const TOOL_CALL_TAG_NAMES = new Set([

2021

"tool_call",

2122

"tool_result",

2223

"function_call",

2324

"function_calls",

25+

"function",

2426

"tool_calls",

2527

]);

2628

const TOOL_CALL_JSON_PAYLOAD_START_RE =

2729

/^(?:\s+[A-Za-z_:][-A-Za-z0-9_:.]*\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))*\s*(?:\r?\n\s*)?[[{]/;

2830

const TOOL_CALL_XML_PAYLOAD_START_RE =

2931

/^\s*(?:\r?\n\s*)?<(?:function|invoke|parameters?|arguments?)\b/i;

303233+

type ToolCallPayloadKind = "json" | "xml" | null;

34+3135

function endsInsideQuotedString(text: string, start: number, end: number): boolean {

3236

let quoteChar: "'" | '"' | null = null;

3337

let isEscaped = false;

@@ -108,9 +112,36 @@ function findTagCloseIndex(text: string, start: number): number {

108112

return -1;

109113

}

110114111-

function looksLikeToolCallPayloadStart(text: string, start: number): boolean {

115+

function detectToolCallPayloadKind(text: string, start: number): ToolCallPayloadKind {

112116

const rest = text.slice(start);

113-

return TOOL_CALL_JSON_PAYLOAD_START_RE.test(rest) || TOOL_CALL_XML_PAYLOAD_START_RE.test(rest);

117+

if (TOOL_CALL_JSON_PAYLOAD_START_RE.test(rest)) {

118+

return "json";

119+

}

120+

if (TOOL_CALL_XML_PAYLOAD_START_RE.test(rest)) {

121+

return "xml";

122+

}

123+

return null;

124+

}

125+126+

function isLikelyStandaloneFunctionToolCall(

127+

text: string,

128+

tagStart: number,

129+

tag: ParsedToolCallTag,

130+

): boolean {

131+

if (tag.tagName !== "function" || tag.isClose || tag.isSelfClosing || tag.isTruncated) {

132+

return false;

133+

}

134+135+

if (!/\bname\s*=/.test(text.slice(tag.contentStart, tag.end))) {

136+

return false;

137+

}

138+139+

let idx = tagStart - 1;

140+

while (idx >= 0 && (text[idx] === " " || text[idx] === "\t")) {

141+

idx -= 1;

142+

}

143+144+

return idx < 0 || text[idx] === "\n" || text[idx] === "\r" || /[.!?:]/.test(text[idx]);

114145

}

115146116147

function parseToolCallTagAt(text: string, start: number): ParsedToolCallTag | null {

@@ -174,7 +205,9 @@ export function stripToolCallXmlTags(text: string): string {

174205

let result = "";

175206

let lastIndex = 0;

176207

let inToolCallBlock = false;

177-

let toolCallContentStart = 0;

208+

let toolCallBlockContentStart = 0;

209+

let toolCallBlockNeedsQuoteBalance = false;

210+

let toolCallBlockStart = 0;

178211

let toolCallBlockTagName: string | null = null;

179212

const visibleTagBalance = new Map<string, number>();

180213

@@ -216,13 +249,19 @@ export function stripToolCallXmlTags(text: string): string {

216249

continue;

217250

}

218251

const payloadStart = tag.isTruncated ? tag.contentStart : tag.end;

219-

const hasToolCallPayloadStart =

220-

tag.tagName === "tool_call"

221-

? looksLikeToolCallPayloadStart(text, payloadStart)

222-

: TOOL_CALL_JSON_PAYLOAD_START_RE.test(text.slice(payloadStart));

223-

if (!tag.isClose && hasToolCallPayloadStart) {

252+

const payloadKind =

253+

tag.tagName === "tool_call" || tag.tagName === "function"

254+

? detectToolCallPayloadKind(text, payloadStart)

255+

: TOOL_CALL_JSON_PAYLOAD_START_RE.test(text.slice(payloadStart))

256+

? "json"

257+

: null;

258+

const shouldStripStandaloneFunction =

259+

tag.tagName !== "function" || isLikelyStandaloneFunctionToolCall(text, idx, tag);

260+

if (!tag.isClose && payloadKind && shouldStripStandaloneFunction) {

224261

inToolCallBlock = true;

225-

toolCallContentStart = tag.end;

262+

toolCallBlockContentStart = tag.end;

263+

toolCallBlockNeedsQuoteBalance = payloadKind === "json";

264+

toolCallBlockStart = idx;

226265

toolCallBlockTagName = tag.tagName;

227266

if (tag.isTruncated) {

228267

lastIndex = text.length;

@@ -242,9 +281,11 @@ export function stripToolCallXmlTags(text: string): string {

242281

tag.isClose &&

243282

(tag.tagName === toolCallBlockTagName ||

244283

(toolCallBlockTagName === "tool_result" && tag.tagName === "tool_call")) &&

245-

!endsInsideQuotedString(text, toolCallContentStart, idx)

284+

(!toolCallBlockNeedsQuoteBalance ||

285+

!endsInsideQuotedString(text, toolCallBlockContentStart, idx))

246286

) {

247287

inToolCallBlock = false;

288+

toolCallBlockNeedsQuoteBalance = false;

248289

toolCallBlockTagName = null;

249290

}

250291

@@ -254,6 +295,8 @@ export function stripToolCallXmlTags(text: string): string {

254295255296

if (!inToolCallBlock) {

256297

result += text.slice(lastIndex);

298+

} else if (toolCallBlockTagName === "function") {

299+

result += text.slice(toolCallBlockStart);

257300

}

258301259302

return result;