Multi-tool agents fail with toolResult/toolUse block mismatch
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3563504. -->
Reported by: [ronraney](https://www.drupal.org/user/3674214)
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Short Description: </strong>[One-line issue summary for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>I'm getting consistent errors using both the regular chat and deep chat blocks. It might have to do with using multiple tools or the "Send email" tool specifically. Here's the error:</p>
<blockquote><p>Error: Error invoking model response: litellm.BadRequestError: BedrockException - {"message":"The number of toolResult blocks at messages.2.content exceeds the number of toolUse blocks of previous turn."}. Received Model Group=claude-3-5-sonnet Available Model Group Fallbacks=None</p></blockquote>
<p>I am using an Assistant/Agent which is configured with two tools: Send email and RAG/Vector search. My provider is Amazee.ai and they use Amazon AWS with Claude. I have Sonnet 3.5 configured for chat. I am using a remove vector db and have a Search API index configured. </p>
<p>I've tried to simplify my approach in configuration. One key piece of information, perhaps, is that the Explorer works for the agent. It connects to the database and produces results. When I use the actual chatbot block, however, it just says there is a service error.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Please provide information like AI modules enabled, which AI provider, browser, etc.</p>
<p>I'm using Drupal 10.5.x with Drupal AI 1.2.4. I have keys configured for Amazee.ai. There isn't an issue, per se, with the connection to the database. I have a totally separate chatbot that's working fairly well at the moment (I am not entirely sure why this one is working and not the other). </p>
<p>Concerning the AI Agent configuration. I had two tools enabled: RAG/Vector search and Send email. I have since removed "Send email" and it appears to be working. I would like to be able to use this tool and other tools. </p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
issue