Skip to content

Comments

feat: Improve tool call extraction and stripping to support multiple …#586

Open
RahulChand028 wants to merge 1 commit intosipeed:mainfrom
RahulChand028:fix/harden-tool-extraction-logic
Open

feat: Improve tool call extraction and stripping to support multiple …#586
RahulChand028 wants to merge 1 commit intosipeed:mainfrom
RahulChand028:fix/harden-tool-extraction-logic

Conversation

@RahulChand028
Copy link

@RahulChand028 RahulChand028 commented Feb 21, 2026

📝 Description

Harden the tool call extraction logic by implementing a robust, state-aware scanner and supporting complex model outputs.

Key Changes

  • Robust Parsing: Implemented a state-aware findMatchingBrace that correctly handles nested objects, JSON strings, and escaped characters.
  • Improved Detection: Added support for markdown code block wrappers (json ... ) and flexible JSON markers (e.g., { "tool_calls": ... }).
  • Multi-Block Extraction: Enhanced logic to extract and strip multiple tool call blocks from a single response.
  • Refactored Utility: Centralized scanning logic into a nextToolCallBlock helper to improve maintainability and performance.
  • Comprehensive Tests: Added a full test suite covering various edge cases and ensuring no regressions.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

I raised a fix earlier, but some unrelated changes were accidentally included while resolving conflicts. I’ve now created a new PR with the improvements and without those extra changes.
#497

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning: The previous simplistic brace counter was fragile when encountering braces in regex, grep commands, or escaped JSON strings. These improvements ensure CLI-based providers like Claude and Codex can reliably extract structured data from diverse LLM outputs.

🧪 Test Environment

  • Hardware: PC
  • OS: Linux (Ubuntu/Debian)
  • Model/Provider: Verified via Go Unit Tests and Claude CLI mock
  • Channels: CLI

📸 Evidence (Optional)

Details image

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

…blocks and markdown wrappers with robust JSON brace matching.
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