Accept common XML tool name aliases (fixes #967)#970
Open
bouclem wants to merge 1 commit into
Open
Conversation
Some models output XML tool calls using invented tag names like `<write_file>` with `<path>` and `<content>` instead of the canonical `<rewrite_file>` with `<uri>` and `<new_content>`. Today these get rendered as plain text in the chat because the parser only matches exact tool/param tags from `availableTools()`. This adds a small alias table in `extractGrammar.ts` so the parser recognizes a few well-known wrong names and emits the canonical tool call with canonical param keys. Behavior is unchanged for compliant models. - `write_file` -> `rewrite_file` (with `path` -> `uri`, `content` -> `new_content`) - `create_file` -> `create_file_or_folder` (`path` -> `uri`) - `delete_file` -> `delete_file_or_folder` (`path` -> `uri`) Also adds one line to the XML system prompt asking the model to use the exact tool/parameter names listed and not invent new tags.
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.
What
Fixes #967.
When a model outputs an XML tool call using a hallucinated tag like
<write_file>with<path>/<content>, the IDE rendered it asplain text instead of executing the tool. The XML parser in
extractGrammar.tsonly recognized exact canonical tool/param tagsfrom
availableTools(), so any drift went straight through as rawoutput.
This adds a small alias table so a few well-known wrong names get
mapped back to the real tools, with canonical param keys, before the
result is handed off to the rest of the pipeline. Compliant models
are unaffected.
Aliases added
write_file->rewrite_file(path->uri,content->new_content)create_file->create_file_or_folder(path->uri)delete_file->delete_file_or_folder(path->uri)Param aliases are scoped per tool to avoid cross-tool collisions.
Also
One line added to the XML tool-calling guidelines in
prompts.tsasking the model to use the exact tool and parameternames listed and not invent new tags. Cheap nudge for compliant
models, doesn't replace the alias map.
Notes
there's no behavior change for models that follow the prompt.
Test
Reproduced the failure mode from #967 by piping an LLM-style stream
that contains
<write_file><path>...</path><content>...</content></write_file>.With the change, the parser emits a
rewrite_filetool call withuriandnew_contentpopulated. Without the change, the samestream renders as plain text, matching the bug report.