-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add XML tool call fallback for OpenAI-compatible providers #11013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Some API providers (like kie.ai with Gemini 3 Pro) do not fully support native function calling and instead output XML-formatted tool calls in text responses. This change adds support for parsing these XML tool calls and executing them as a fallback. Changes: - Add XmlToolCallParser to parse XML tool calls from text content - Modify presentAssistantMessage to detect and parse XML tool calls instead of rejecting them with an error - Add comprehensive tests for the XmlToolCallParser Fixes #11011
Review complete. Found 2 issues to address:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| public static parseXmlToolCalls(text: string): XmlToolCallParseResult { | ||
| // Collect all matches with their positions to maintain document order | ||
| const matches: Array<{ | ||
| position: number | ||
| fullMatch: string | ||
| innerContent: string | ||
| toolName: string | ||
| }> = [] | ||
|
|
||
| // Find all tool matches across all tool names | ||
| for (const toolName of XML_TOOL_NAMES) { | ||
| // Pattern to match complete tool tags: <tool_name>...</tool_name> | ||
| // Uses a non-greedy match for content to handle multiple tool calls | ||
| const regex = new RegExp(`<${toolName}>([\\s\\S]*?)</${toolName}>`, "gi") | ||
|
|
||
| let match | ||
| while ((match = regex.exec(text)) !== null) { | ||
| matches.push({ | ||
| position: match.index, | ||
| fullMatch: match[0], | ||
| innerContent: match[1], | ||
| toolName, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike containsXmlToolMarkup() which strips code blocks before detection, this method parses XML tool calls from the raw text without stripping code blocks first. When text contains both a code block with example tool calls AND an actual tool call outside, both will be parsed and executed. For example, if the model shows an example <read_file> in a code block while also making an actual <read_file> call, both would be extracted. Consider stripping code blocks before parsing, similar to the detection logic.
Fix it with Roo Code or mention @roomote and request a fix.
| case "run_slash_command": { | ||
| const command = get("command") | ||
| if (command !== undefined) { | ||
| return { | ||
| command, | ||
| args: get("args"), | ||
| } | ||
| } | ||
| return undefined | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is unreachable because run_slash_command is not included in XML_TOOL_NAMES. Since the parser only processes tools from that list, this handler will never execute. Consider removing this dead code or adding run_slash_command to XML_TOOL_NAMES if XML parsing for this tool is intended.
Fix it with Roo Code or mention @roomote and request a fix.
|
Closing in favor of PR #11014, which contains the proper fix with the openAiStrictToolMode setting. This PR (XML fallback parsing) was an intermediate attempt before understanding the root cause. |
Related GitHub Issue
Closes: #11011
Roo Code Task Context (Optional)
N/A
Description
Some API providers (like kie.ai with Gemini 3 Pro) do not fully support native function calling and instead output XML-formatted tool calls in text responses. Previously, these were rejected with an error message. This PR adds support for parsing these XML tool calls and executing them as a fallback.
Key Implementation Details:
New XmlToolCallParser class (
src/core/assistant-message/XmlToolCallParser.ts):<read_file><path>src/file.ts</path></read_file>)ToolUseformat used by the existing tool execution infrastructuretoolu_*) for native protocol compatibilityModified presentAssistantMessage (
src/core/assistant-message/presentAssistantMessage.ts):assistantMessageContentfor normal executionDesign Choices:
Test Procedure
Unit Tests Added: 32 comprehensive tests for
XmlToolCallParser:Test Commands:
Manual Testing: Configure an OpenAI-compatible provider that outputs XML tool calls (like kie.ai) and verify tools execute correctly.
Pre-Submission Checklist
Screenshots / Videos
N/A - No UI changes
Documentation Updates
Additional Notes
This addresses the feedback from @kangarko in issue #11011 who suggested adapting to the Gemini 3 Pro scheme that kie.ai uses, rather than just improving error messages (which was done in PR #11012).
Get in Touch
N/A - Bot submission