Commit 9241875
committed
Fix handling of multiple tool calls in single LLM response
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.1 parent a35aa11 commit 9241875
File tree
10 files changed
+1293
-15
lines changed- lib/ruby_llm/providers/anthropic
- spec
- fixtures/vcr_cassettes
- ruby_llm
- providers/anthropic
10 files changed
+1293
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
| 16 | + | |
18 | 17 | | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
72 | | - | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
79 | 87 | | |
80 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
81 | 91 | | |
82 | 92 | | |
83 | 93 | | |
| |||
Lines changed: 170 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments