fix(agent): strip leaked tool call text and thinking tags from messages #905
+266
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
[Tool Call: ...]and[Tool Result for ID ...]text blocks that leak into assistant messages when Gemini history downgrading converts tool calls withoutthought_signatureto text<think>,<thinking>,<thought>, and<antthinking>tags from text content as a safety net for models that emit thinking tags in text blocksChanges
stripDowngradedToolCallText()function to filter downgraded tool call representationsstripThinkingTagsFromText()function to filter thinking tag leaksextractAssistantText()to chain all three filters (Minimax XML, downgraded tool calls, thinking tags)Test Plan
pi-embedded-utils.test.tspassContext
When using Gemini models via the google-antigravity provider, tool calls that lack a
thought_signatureare 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
google-antigravityfromdowngradeGeminiHistoryentirely). Both PRs can coexist - fix: exclude google-antigravity from history downgrade hack #894 prevents the leak at the source for google-antigravity, while this PR adds defense-in-depth filtering that catches leaks from any provider.🤖 Generated with Claude Code