Skip to content

fix(llm, anthropic): Enable multiple tool calls in single turn#268

Merged
JeanMertz merged 3 commits intomainfrom
fix-reasoning2
Oct 3, 2025
Merged

fix(llm, anthropic): Enable multiple tool calls in single turn#268
JeanMertz merged 3 commits intomainfrom
fix-reasoning2

Conversation

@JeanMertz
Copy link
Collaborator

Previously, when Anthropic models requested multiple tool calls during a single turn, the system would group multiple tool call argument JSON objects into a single tool call, causing argument parsing to fail. This occurred because only the MessageDelta event with stop_reason: tool_use was handled for tool call completion, but individual tool calls in a multi-call response generate separate ContentBlockStop events.

The fix adds handling for ContentBlockStop events when the provider is accumulating tool call content, ensuring each tool call is properly finalized before the next one begins. This prevents JSON object concatenation and allows multiple tool calls to execute successfully in sequence, significantly speeding up tool call completion, and reducing token usage.

Instructions containing XML tags, CDATA sequences, or other special
characters now serialize without escaping special characters. This
improves readability of instructions in the generated XML.

The fix switches to a (temporary) `quick-xml` fork with CDATA
serialization support and rewrites the XML serialization logic to wrap
text content in CDATA sections. This ensures instruction text is
preserved literally regardless of special characters.

Additional formatting changes include proper nesting of items and
examples, and setting the title as an attribute of the root element.

The end-goal is better adherence to the instructions by LLM models.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Previously, when Anthropic models requested multiple tool calls during a
single turn, the system would group multiple tool call argument JSON
objects into a single tool call, causing argument parsing to fail. This
occurred because only the MessageDelta event with stop_reason:
`tool_use` was handled for tool call completion, but individual tool
calls in a multi-call response generate separate `ContentBlockStop`
events.

The fix adds handling for `ContentBlockStop` events when the provider is
accumulating tool call content, ensuring each tool call is properly
finalized before the next one begins. This prevents JSON object
concatenation and allows multiple tool calls to execute successfully in
sequence, significantly speeding up tool call completion, and reducing
token usage.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Base automatically changed from fix-reasoning to main October 3, 2025 10:43
@JeanMertz JeanMertz merged commit ae246a8 into main Oct 3, 2025
12 checks passed
@JeanMertz JeanMertz deleted the fix-reasoning2 branch October 3, 2025 10:53
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