Skip to content

Conversation

@finbarr
Copy link
Contributor

@finbarr finbarr commented Jun 11, 2025

Summary

  • Fixed handling of multiple simultaneous tool calls from LLM responses
  • Fixed empty content text block bug that was causing BadRequestError
  • Properly iterate through all tool calls in a message instead of processing only the first one

Related Issue

Fixes #236

Changes

  1. Updated format_tool_call in lib/ruby_llm/providers/anthropic/tools.rb to:

    • Check for empty/nil content before adding text blocks (incorporates the text blank bug fix from main)
    • Iterate through all tool calls using each_value instead of processing just one
  2. Updated parse_tool_calls to handle both single tool calls (for backward compatibility) and arrays of multiple tool calls

  3. Added comprehensive test coverage for multiple tool calls scenario

Test plan

  • All existing tests pass
  • New tests added for multiple tool calls
  • Tests verify empty content is not included in formatted messages
  • Backward compatibility maintained for single tool calls

🤖 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 finbarr closed this Jun 11, 2025
@tpaulshippy
Copy link
Contributor

You still working on this? Looking forward to this improvement.

@tpaulshippy
Copy link
Contributor

Or is this not actually an issue?

@finbarr
Copy link
Contributor Author

finbarr commented Jun 12, 2025

@tpaulshippy I opened a separate PR here: #241

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.

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

2 participants