Skip to content

Conversation

@finbarr
Copy link
Contributor

@finbarr finbarr commented Jun 12, 2025

Summary

  • Fixed Anthropic provider to properly handle multiple tool calls in a single response
  • Added test coverage for multiple tool calls scenario

Context

This PR addresses issue #236 where the Anthropic provider was only processing the first tool call when multiple tool calls were returned in a single LLM response.

Changes

  1. Modified parse_tool_calls method to handle arrays of tool blocks
  2. Updated format_tool_call to iterate through all tool calls
  3. Changed tool block selection to use select instead of find to get all tool_use blocks
  4. Added comprehensive test cases for multiple tool call handling

Test plan

  • Added new test cases for multiple tool calls
  • All existing tests pass
  • Verified fix works with Anthropic Claude models

🤖 Generated with Claude Code

Previously, the library only processed the first tool call when an LLM
returned multiple tool_use blocks in a single response. This limitation
prevented parallel function execution, a key feature of modern LLMs.

Changes:
- Update Anthropic provider to extract ALL tool_use blocks from responses
- Modify tool parser to handle arrays of content blocks
- Ensure all tools execute before continuing the conversation
- Add comprehensive tests for multi-tool scenarios across all providers

This enables use cases like:
- Executing multiple independent operations in parallel
- Rolling dice multiple times in one request
- Fetching data from multiple sources simultaneously

The implementation maintains backward compatibility while extending
support for advanced parallel tool calling capabilities.

Fixes the limitation where only the first tool call was processed
when multiple were requested.
@finbarr
Copy link
Contributor Author

finbarr commented Jun 12, 2025

One note here is that I couldn't get bedrock credentials to work, try as I might. So the bedrock VCR is faked for the multi tool calls. Every other VCR is real.

Copy link
Contributor

@tpaulshippy tpaulshippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this against Bedrock. Looks good.

@tpaulshippy
Copy link
Contributor

tpaulshippy commented Jun 12, 2025

One note here is that I couldn't get bedrock credentials to work, try as I might. So the bedrock VCR is faked for the multi tool calls. Every other VCR is real.

chat_function_calling_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_can_handle_multiple_tool_calls_in_a_single_response.yml.zip
Here's a real one...

@finbarr
Copy link
Contributor Author

finbarr commented Jun 12, 2025

Thank you @tpaulshippy I added the real cassette.

@crmne crmne added the bug Something isn't working label Jul 16, 2025
@tpaulshippy
Copy link
Contributor

Merging this into my fork to see if it helps with intermittent "text content blocks must be non-empty" errors.

@tpaulshippy
Copy link
Contributor

@finbarr Do you have time to address the feedback? If not, I can start a separate PR.

@finbarr
Copy link
Contributor Author

finbarr commented Jul 22, 2025

@tpaulshippy feel free to go ahead. Thank you!

@finbarr
Copy link
Contributor Author

finbarr commented Jul 22, 2025

@tpaulshippy I made a change. Feel free to modify further as needed.

@finbarr finbarr requested a review from crmne July 22, 2025 18:55
crmne added 4 commits July 22, 2025 22:14
- Updated test skip logic to check if provider is local using provider.local? method
- Consolidated separate skip statements for Ollama and GPUStack into single check
- Both providers have local? => true and share similar limitations with tool usage
@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.72%. Comparing base (c80b1e3) to head (919929c).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   87.67%   87.72%   +0.04%     
==========================================
  Files          78       78              
  Lines        3001     3005       +4     
  Branches      564      567       +3     
==========================================
+ Hits         2631     2636       +5     
+ Misses        370      369       -1     

☔ 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.

@crmne
Copy link
Owner

crmne commented Jul 22, 2025

@finbarr great PR, thank you! Merging

@crmne crmne merged commit 0ae5770 into crmne:main Jul 22, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Multiple simultaneous tool calls behaves unexpectedly and causes error

3 participants