Skip to content

Accept common XML tool name aliases (fixes #967)#970

Open
bouclem wants to merge 1 commit into
voideditor:mainfrom
bouclem:fix/xml-tool-aliases-967
Open

Accept common XML tool name aliases (fixes #967)#970
bouclem wants to merge 1 commit into
voideditor:mainfrom
bouclem:fix/xml-tool-aliases-967

Conversation

@bouclem
Copy link
Copy Markdown

@bouclem bouclem commented May 22, 2026

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 as
plain text instead of executing the tool. The XML parser in
extractGrammar.ts only recognized exact canonical tool/param tags
from availableTools(), so any drift went straight through as raw
output.

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.ts asking the model to use the exact tool and parameter
names listed and not invent new tags. Cheap nudge for compliant
models, doesn't replace the alias map.

Notes

  • No public API changes.
  • Aliases only kick in when a tag is otherwise unrecognized, so
    there's no behavior change for models that follow the prompt.
  • Easy to extend later if more common wrong names show up.

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_file tool call with
uri and new_content populated. Without the change, the same
stream renders as plain text, matching the bug report.

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.
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.

<write_file> is not accepted in IDE

1 participant