Skip to content

fix(assistant): execute provider text tool calls#34

Merged
omarluq merged 1 commit into
mainfrom
fix/provider-tool-calls
May 21, 2026
Merged

fix(assistant): execute provider text tool calls#34
omarluq merged 1 commit into
mainfrom
fix/provider-tool-calls

Conversation

@omarluq

@omarluq omarluq commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • execute XML/text fallback tool calls from providers that do not emit native tool-call JSON
  • preserve write/edit/bash content when parsing fallback tool calls, including JSON container payloads
  • reject empty writes to avoid accidental zero-byte files
  • add Anthropic native tool-name compatibility in the stacked branch

Validation

  • mise exec -- go test ./...
  • mise exec -- task build
  • mise exec -- task ci

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Text-based tool-call fallback to handle tool requests embedded in assistant text.
  • Improvements

    • Better provider-aware tool name mapping for Anthropic/OAuth scenarios.
    • Tool payloads now signal eager input streaming for faster interactions.
  • Tests

    • Expanded test coverage for tool parsing, mapping, execution, and error cases.

Walkthrough

OAuth-aware Anthropic tool naming maps provider/local names per request, adds eager input streaming flags, and propagates CompletionRequest through the tool loop. Separately, text-fallback parsing now iteratively extracts and normalizes XML-like <tool_use> blocks into canonical tool-call arguments. Tests updated and expanded.

Changes

Anthropic OAuth Tool Naming and Text Fallback Parsing

Layer / File(s) Summary
Tool name and JSON key constants
internal/assistant/client.go
Adds jsonInputKey and extends tool-name constants (including find/ls and capitalized Anthropic variants).
Anthropic OAuth-aware naming & payload wiring
internal/assistant/anthropic.go, internal/assistant/anthropic_tools_test.go
Propagates *CompletionRequest to appendAnthropicToolConversation, makes anthropicTools(request) request-dependent, adds eager_input_streaming: true, introduces anthropicProviderToolName/anthropicLocalToolName mapping (OAuth-aware, includes List alias), and updates tool-call/message translation and tests.
Text-fallback parsing and argument normalization
internal/assistant/text_tool_calls.go
Implements iterative extraction of <tool_use> blocks, manual tag matching, HTML-unescape, JSON-embedded payload normalization (stringify non-strings), canonical tool-name normalization, per-tool aliasing to standardized argument keys, and JSON-encoded arguments with {} fallback.
Text-fallback unit tests
internal/assistant/text_tool_calls_test.go
Adds table-driven tests covering multiline write content preservation, multiple markup variants, name/argument normalization, JSON payload parsing, and textToolResultPrompt behavior for errors and empty output.
Integration test workspace and shared constants
internal/assistant/provider_tool_calls_test.go, internal/assistant/tool_loop_test.go
Introduces testToolWorkspace() with README.md fixture, switches tests to per-test CWD, marshals OpenAI tool arguments as JSON in mocks, and centralizes testCallID and jsonReadToolName usage in tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • omarluq/librecode#32: Updates Anthropic tool-use parsing and conversation wiring, overlapping with OAuth-aware tool name mapping in this PR.

"🐰
With OAuth names mapped clean,
XML fields parsed between,
Tool calls now find the right name,
Multiline writes kept the same,
Tests hop through the green!"

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: executing provider text tool calls as a fix to the assistant module.
Description check ✅ Passed The description clearly relates to the changeset, outlining the execution of XML/text fallback tool calls, content preservation, and Anthropic compatibility additions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/provider-tool-calls

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 21, 2026
@omarluq omarluq force-pushed the fix/provider-tool-calls branch from 19b09cc to 2f28833 Compare May 21, 2026 23:07
@sonarqubecloud

Copy link
Copy Markdown

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.41935% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.12%. Comparing base (0a4eae4) to head (2f28833).

Files with missing lines Patch % Lines
internal/assistant/anthropic.go 67.27% 17 Missing and 1 partial ⚠️
internal/assistant/text_tool_calls.go 83.00% 13 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
+ Coverage   59.97%   60.12%   +0.15%     
==========================================
  Files         168      168              
  Lines       16532    16667     +135     
==========================================
+ Hits         9915    10021     +106     
- Misses       5611     5636      +25     
- Partials     1006     1010       +4     
Flag Coverage Δ
unittests 60.12% <77.41%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@omarluq

omarluq commented May 21, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@omarluq omarluq merged commit 61fcc80 into main May 21, 2026
13 checks passed
@omarluq omarluq deleted the fix/provider-tool-calls branch May 21, 2026 23:26
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.

2 participants