fix: improve XML tool call error recovery with comprehensive guidance#11480
Draft
roomote[bot] wants to merge 1 commit intomainfrom
Draft
fix: improve XML tool call error recovery with comprehensive guidance#11480roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
…#11106) When models produce XML-style tool markup instead of using native tool calling, the error message now includes explicit tool-use instructions and next-step guidance (similar to noToolsUsed), making it much more likely the model can self-correct on the next turn. Changes: - Add formatResponse.xmlToolCallError() with tool instructions reminder - Use comprehensive error in presentAssistantMessage userMessageContent - Improve error messages in BaseTool for missing nativeArgs - Add dedicated test suite for xmlToolCallError()
Contributor
Author
Reviewed all changed files. No bugs or issues found. The changes are clean, well-scoped, and follow existing patterns (mirrors Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related GitHub Issue
Closes: #11106
Description
This PR attempts to address Issue #11106 where models (Grok, Gemini, and others) intermittently produce XML-style tool markup instead of using native tool calling, causing a blocking error loop.
Root cause: When the model emits XML tool tags in its text response, the error message pushed to the conversation history was too brief for the model to self-correct. The model would repeat the same mistake, hit the consecutive mistake limit, and stall the task.
Changes:
src/core/prompts/responses.ts: AddedformatResponse.xmlToolCallError()that returns a comprehensive error message including:noToolsUsed())src/core/assistant-message/presentAssistantMessage.ts: Updated the missingtool_use.iderror path to use the new comprehensive error message inuserMessageContent(what the model sees), while keeping the user-facing error concisesrc/core/tools/BaseTool.ts: Improved error messages for XML detection in params and missing nativeArgssrc/core/prompts/__tests__/responses-xml-tool-call-error.spec.ts: Added dedicated test suite for the newxmlToolCallError()functionTest Procedure
presentAssistantMessage-unknown-tool.spec.tsandpresentAssistantMessage-images.spec.tscontinue to pass unchangedPre-Submission Checklist
Documentation Updates
No documentation updates are required.
Additional Notes
Feedback and guidance are welcome. The key insight is that when the model makes XML tool call mistakes, we now provide it with the same quality of guidance (tool instructions reminder + next steps) that we give for other error types like
noToolsUsed()andmissingToolParameterError(). This makes it much more likely the model can self-correct on the next turn rather than entering a stall loop.