Add Twig output rewrite field to advanced tool settings
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3554750. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>With tools, its vital to be able to tweak the output of the tool, to better feed the current context of the tool. </p>
<p>Think of a webform agent - if you take the plugin definitions for elements for instance, you might actually want two instances of the same tool - one that gives back all the definitions with just label/description to get an overview, and then the same tool that takes input of instances to list and outputs all the information. So you can have the AI do an initial pick on the first loop, and get more information on the second.</p>
<p>We should be able to do this by allowing instances of tools + being able to setup the output rendering of the tool.</p>
<p>With Tool API, we now have structured ouputs, meaning that we can use Twig + that structured output to render the message to the Tool.</p>
<p>To be able to do this, we should add two settings to the advanced settings of the tool:</p>
<p>1. Enable Custom Output<br>
2. (if checked) A twig field, where you setup how you want to render it.</p>
<p>At later stages, we should be able to do something with better UX, where you can test with test values and see in realtime how it renders.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>1. For now just add the two fields, and add the values to the tool settings part of the tools.<br>
2. Render it using Twig on runtime.<br>
3. If there is an exception log this and use the original message.</p>
issue