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-&gt;create([<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'label' =&gt; 'Ran ' . $file . '.yaml',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'tool' =&gt; $event-&gt;getOutput()-&gt;getNormalized()-&gt;getTools()[0]-&gt;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('&lt;tr&gt;&lt;td&gt;&lt;a href="' + drupalSettings.path.baseUrl + 'ai-agent-decision/' + response.entries[x].id + '" target="_blank"&gt;' + response.entries[x].label + '&lt;/a&gt;&lt;br&gt;'+ toolName +'&lt;br&gt;&lt;details&gt;&lt;summary&gt;' + Drupal.t('Response') + '&lt;/summary&gt;&lt;pre&gt;' + response.entries[x].json + '&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;' + newTime + '&lt;/td&gt;&lt;/tr&gt;');</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