Better AI Logging for Agents and in general - As a new module
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3527937. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The logs currently are very basic and unless you are looking into how one specific call went they are not great. This means that complex things like Agents or even simpler RAG solutions are not easy to debug when they happened on a production site.</p>
<p>We want thoughts on how to improve this.</p>
<p>We have the issue <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-17"><a href="https://www.drupal.org/project/ai/issues/3493277" title="Status: Closed (outdated)">#3493277: Extend AI Logging Capabilities</a></span> that has improved it, but its not ready to be merged yet and would later need changes to work with tools calling.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Install Drupal CMS</li>
<li>Apply the AI Recipe with one of the providers</li>
<li>Enable the AI Logging module</li>
<li>Go to AI Logging settings under /admin/config/ai/logging/settings and check "Automatically log requests" and "Automatically log responses"</li>
<li>Try to hold a continues conversation where your questions are "What can you do?", "Could you create a vocabulary called Football Players?", "Could you give me a suggestion of 10 famous football players", "Could you add those as taxonomy terms to the Football Players vocabulary"</li>
<li>You might have to confirm some of those steps</li>
<li>Some steps might fail</li>
<li>Visit /admin/config/ai/logging/collection and try to figure out what has happened (independent on if it worked or failed)</li>
</ol>
<p>Note that this is for AI 1.0.0 without tools calling.</p>
<h3 id="background">Technical Background</h3>
<p>Currently logging is happening via the submodule AI Logging - this module listens to the event PostGenerateResponseEvent.php for none streaming responses and PostStreamingResponseEvent.php for the streaming responses. The later does not work in 1.0.0, but will work in 1.1.0.</p>
<p>The log is an entity, based on an entity type that is bundleable. The idea was to create bundles for the specific logs, but this has not been done yet. Currently its just doing JSON encode on the data it can find in the event.</p>
issue