Skip to content

feat(core): detect tool calls leaked into reasoning and text#9

Merged
Grigory-Rylov merged 2 commits into
devfrom
reasoning-tool-call-detection
Jul 13, 2026
Merged

feat(core): detect tool calls leaked into reasoning and text#9
Grigory-Rylov merged 2 commits into
devfrom
reasoning-tool-call-detection

Conversation

@Grigory-Rylov

Copy link
Copy Markdown
Owner

Problem

LLM sometimes emits tool calls as XML-style text in reasoning output instead of using the structured tool_calls API field:

<tool_call>
<function=grep>
<parameter=path>...</parameter>
<parameter=pattern>...</parameter>
</function>
</tool_call>

This causes the agent to hang because the tool call is never executed.

Solution

  • Added findToolCallName() to detect XML-style tool calls (<function=name>, [Assistant tool call]: name(, and JSON {"name": "..."} patterns)
  • Applied detection to both text and reasoning fragments in publish-llm-event.ts
  • When detected: replaces the content with an [ERROR] message and sets textBasedToolCall = true, triggering a retry turn

Changes

  • packages/core/src/session/runner/publish-llm-event.tsfindToolCallName() + reasoning fragment check
  • packages/core/test/publish-llm-event.test.ts — 12 tests for findToolCallName

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@Grigory-Rylov
Grigory-Rylov merged commit 05f352a into dev Jul 13, 2026
3 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant