Agent structured output
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3544184. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !180 >>> <p>--- AI TRACKER METADATA ---<br> <strong>Update Summary: </strong>Make it so that AI will produces more valid structured results which is essential for any AI automation where spelling mistakes can break whole processes.<br> <strong>Check-in Date: </strong>MM/DD/YYYY (US format) [When we should see progress/get an update]<br> <strong>Due Date:</strong> MM/DD/YYYY (US format) [When the issue should be fully completed]<br> <strong>Blocked by:</strong> [#XXXXXX] (New issues on new lines)<br> <strong>Additional Collaborators:</strong> @username1, @username2<br> AI Tracker found here: <a href="https://www.drupalstarforge.ai/" title="AI Tracker">https://www.drupalstarforge.ai/</a><br> --- END METADATA ---</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Because we have the possibility to ask the AI provider to answer with structured output and because we have a way to transfer data from one agent to another without writing tokens in <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_agents/issues/3528726" title="Status: Closed (fixed)">#3528726: Add artifacts to agents</a></span>, we should put both in use for the agent.</p> <p>Sometimes the agent might need to produce JSON for the next agent to use or even in the future use a portion of the structured data to fill out a tool. In the future we also want it to be possible to add input parameters to agents, so they can take structured input.</p> <p>To be able to do this, we need to start with the "simple" part, which is the structured output of an agent.</p> <p>This means that you do not have to ask in the system prompt with examples on how to generate the output, but rather using the providers structured output.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>Add two parameters to the agent config, called structured_output_enabled (bool) and structured_output_schema (string). Both nullable since we are adding them now.</li> <li>Add it to the config schema.</li> <li>On the agent form make it a checkbox that you can enable and disable.</li> <li>On the agent add a long textarea where you can input a json schema. (At a later stage we can look into JS tools for json-schema)</li> <li>Validate the json schema.</li> <li>Store it all.</li> <li>If its enabled during runtime, use the structured call functionality on the agent</li> </ul> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue