Add tool to ai_agent_decision
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3554882. -->
Reported by: [unqunq](https://www.drupal.org/user/933228)
Related to !204
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When using the agent explorer I get a step by step response from the agent when using various tools.<br>
However the heading is always the same so it's not very useful, I need to open the hidden part in order to see which tool was run.</p>
<p><img src="https://www.drupal.org/files/issues/2025-10-28/Screenshot%202025-10-28%20at%2021.29.45.png" width="500" height="500" alt="Add tool to ai_agent_decision"></p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Add the last run tool to the decision entity and surface it in the agent explorer.</p>
<ol>
<li>New field to be added to AgentDecision entity.</li>
<li>
In PostRequestEventSubscriber.php we can add it to the decision:
<pre>$decision = $storage->create([<br> 'label' => 'Ran ' . $file . '.yaml',<br> 'tool' => $event->getOutput()->getNormalized()->getTools()[0]->getName(),<br>....</pre></li>
<li>I assume it can be added in `pollAgent` function in `AiAgentExplorerController` and then picked up in the js file.</li>
<li>We should also do some checks to make sure there is a tool in the output.</li>
</ol>
<h3 id="summary-alternative-solution">Alternative solution</h3>
<p>I discovered that the string called json is actually nicely formatted when it gets to the js file so we can use regex to extract the tool id.</p>
<pre>const match = response.entries[x].json.match(/(Tool:\s*[^\s]+)/);<br>const toolName = match ? match[1] : null;<br>$('.explorer-messages tbody').append('<tr><td><a href="' + drupalSettings.path.baseUrl + 'ai-agent-decision/' + response.entries[x].id + '" target="_blank">' + response.entries[x].label + '</a><br>'+ toolName +'<br><details><summary>' + Drupal.t('Response') + '</summary><pre>' + response.entries[x].json + '</pre></td><td>' + newTime + '</td></tr>');</pre><p>
This code gives me:<br>
<img src="https://www.drupal.org/files/issues/2025-10-29/Screenshot%202025-10-29%20at%2000.41.43.png" width="500" height="500" alt="x"></p>
issue