Skip to content

fix: parse GLM tool calls inside reasoning - #1651

Open
shihaobai wants to merge 5 commits into
mainfrom
codex/glm-reasoning-tool-calls
Open

shihaobai wants to merge 5 commits into
mainfrom
codex/glm-reasoning-tool-calls

Conversation

@shihaobai

@shihaobai shihaobai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

GLM can emit <tool_call> before </think>, causing reasoning extraction to hide tool calls or alter literal markers inside arguments. Route tool envelopes through the GLM reasoning detector intact, and use an argument-aware scanner for streaming and non-streaming tool parsing. Preserve literal strings and schema-directed argument values.

Keep the request's thinking switch separate from the initial generation phase. Resolve the phase through the detector after rendering the prompt, then share it across reasoning parsing, string-stop matching and grammar activation. Flush buffered text before tool parsing when generation ends so truncated XML arguments do not leak into content.

Validation:

  • 307 parser, API, reasoning-token, multi-choice, stop, grammar and error-response regressions passed.
  • 122 additional checks passed using the installed GLM-5.3 tokenizer and real chat template, including token, character and random chunk boundaries, long arguments, thinking-toggle mismatches, and streaming/non-streaming agreement.
  • Black and flake8 passed through the repository's pre-commit hooks.

@shihaobai shihaobai changed the title fix: parse GLM tool calls inside reasoning fix: preserve GLM tool calls across reasoning and stream boundaries Oct 21, 2026
@shihaobai shihaobai changed the title fix: preserve GLM tool calls across reasoning and stream boundaries fix: parse GLM tool calls inside reasoning Oct 21, 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