Skip to content

fix(agent): strip leaked tool call text and thinking tags from messages#905

Closed
erikpr1994 wants to merge 3 commits intoopenclaw:mainfrom
erikpr1994:fix/tool-call-text-leak
Closed

fix(agent): strip leaked tool call text and thinking tags from messages#905
erikpr1994 wants to merge 3 commits intoopenclaw:mainfrom
erikpr1994:fix/tool-call-text-leak

Conversation

@erikpr1994
Copy link
Copy Markdown
Contributor

@erikpr1994 erikpr1994 commented Jan 14, 2026

Summary

  • Strip [Tool Call: ...] and [Tool Result for ID ...] text blocks that leak into assistant messages when Gemini history downgrading converts tool calls without thought_signature to text
  • Strip <think>, <thinking>, <thought>, and <antthinking> tags from text content as a safety net for models that emit thinking tags in text blocks

Changes

  • Added stripDowngradedToolCallText() function to filter downgraded tool call representations
  • Added stripThinkingTagsFromText() function to filter thinking tag leaks
  • Updated extractAssistantText() to chain all three filters (Minimax XML, downgraded tool calls, thinking tags)
  • Added comprehensive test coverage (25 tests total for the module)

Test Plan

  • Unit tests added for all new filter functions
  • All 25 tests in pi-embedded-utils.test.ts pass
  • Full test suite passes (2872 tests)
  • Lint and type-check pass
  • Local security review passed (no new vulnerabilities)
  • Local code review passed

Context

When using Gemini models via the google-antigravity provider, tool calls that lack a thought_signature are downgraded to text blocks during history replay. This caused raw tool invocation syntax to leak into user-facing messages on Telegram and other surfaces.

Similarly, some models emit thinking/reasoning content wrapped in <think> tags which should not appear in final responses.

Related

🤖 Generated with Claude Code

When replaying conversation history to Gemini, tool calls without
thought_signature are downgraded to text blocks like [Tool Call: ...].
This leaked internal technical info into user-facing chat messages.

Added stripDowngradedToolCallText filter alongside existing Minimax
filter to remove these text representations before extraction.
steipete added a commit that referenced this pull request Jan 15, 2026
Thanks @erikpr1994.

Co-authored-by: Erik Pastor Rios <erikpastorrios1994@gmail.com>
@steipete
Copy link
Copy Markdown
Contributor

Landed on main after rebase onto a temp branch.

Changes:

  • Preserve trailing text after downgraded tool call blocks.
  • Strip thinking tags with attributes.
  • Added coverage + changelog entry.

Commit: 2bd9e8485
Tests: pnpm lint && pnpm build && pnpm test

Thanks @erikpr1994!

@steipete steipete closed this Jan 15, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Thanks @erikpr1994.

Co-authored-by: Erik Pastor Rios <erikpastorrios1994@gmail.com>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Thanks @erikpr1994.

Co-authored-by: Erik Pastor Rios <erikpastorrios1994@gmail.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Thanks @erikpr1994.

Co-authored-by: Erik Pastor Rios <erikpastorrios1994@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Google Antigravity tool calls displayed as text instead of executed

2 participants