Infinite AJAX request loop when the Agent is unable to resolve a job
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3547457. -->
Reported by: [codebymikey](https://www.drupal.org/user/3573206)
Related to !192
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When a tool is attached to the API request with looping enabled, if the max loop is reached, and the job is flagged as not solvable.</p>
<p>Because the last message from the AI API can include a request for it to make requests to the AI "tool", the API keeps requesting for it to retry but to no avail because the limit has already been reached.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>1. Set up a RAG based agent similar to <a href="https://www.qed42.com/insights/setting-up-ai-powered-semantic-search-in-drupal">https://www.qed42.com/insights/setting-up-ai-powered-semantic-search-in-drupal</a><br>
2. Ask the agent some content related questions, that it might not be able to resolve. Sometimes, rather than returning a final message stating that it could not resolve. The last request before the max loop might be for it to make a further request to the RAG tool.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>If the loop limit has been reached, it should ensure that there are no tools attached in the final response, as well as mark the request as finished since it can no longer process any more requests.</p>
<p>Any advice is more than welcome if this approach isn't ideal.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Provide MR.</p>
issue