Skip to content

fix: enable tool execution with stop sequences, name mapping, and XML suppression#3

Merged
DaveZheng merged 1 commit intomainfrom
fix-tool-execution
Feb 6, 2026
Merged

fix: enable tool execution with stop sequences, name mapping, and XML suppression#3
DaveZheng merged 1 commit intomainfrom
fix-tool-execution

Conversation

@DaveZheng
Copy link
Copy Markdown
Owner

Summary

  • Add stop: ["</tool_call>"] to OpenAI requests so the model pauses after a tool call instead of continuing to hallucinate errors
  • Map tool names from mallex format (read_file, bash, grep) to Claude Code format (Read, Bash, Grep) in parsed responses
  • Suppress tool call XML from streaming text deltas — the stream translator now detects <tool_call> / <function= markers and buffers instead of emitting them as visible text
  • Handle stop sequence truncation where closing XML tags may be missing

The problem

The model would generate tool call XML, then keep going — imagining the tool failed, trying again, and eventually giving up and answering manually. Claude Code never got a chance to execute anything. Additionally, raw XML tags were visible to the user during streaming.

Test plan

  • Ask mallex to read a file — model should generate one tool call, stop, Claude Code executes it
  • Verify no raw XML (<tool_call>, <function=) appears in the streamed output
  • Ask mallex to run a shell command — bash maps to Bash
  • Plain text responses (no tool calls) still stream normally

🤖 Generated with Claude Code

… suppression

Three issues prevented tools from working:

1. No stop sequences — the model would generate tool call XML then keep
   generating (imagining errors, retrying, giving up). Adding
   stop=["</tool_call>"] makes the model stop after a tool call so
   Claude Code can execute it and send back results.

2. Tool name mismatch — the model called tools by mallex names
   (read_file, bash, grep) but Claude Code expects its own names
   (Read, Bash, Grep). Added name mapping in the parser.

3. Raw XML in stream — tool call XML (<tool_call><function=...>) was
   streamed as visible text before tool_use blocks were emitted. The
   stream translator now buffers text once it detects a tool call marker
   and suppresses the XML from text deltas.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DaveZheng DaveZheng merged commit e7da628 into main Feb 6, 2026
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.

1 participant