Agent/Assistant Conversion Operations
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3574046. -->
Reported by: [yautja_cetanu](https://www.drupal.org/user/626050)
Related to !1209
>>>
<p>[Tracker]<br>
<strong>Update Summary: AI provided solution that physically works and has undergone manual testing to convert between the two.<br>
<strong>Short Description: Allow Agents to be converted to Assistants so they can be used directly with a chatbot in a simpler manner better for context.<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</strong></strong></p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Site builders can see both AI Agents and AI Assistants in admin listings, but there is no first-class way to:</p>
<p>1. Convert an existing Agent into an Assistant linked to that same Agent.<br>
2. Remove an Assistant wrapper while keeping its linked Agent.</p>
<p>This makes migration between models awkward and pushes conversion logic into custom UIs.</p>
<h3 id="background-info">Background Information</h3>
<p>There are legacy reasons that we have this confusing separation of Agents and Assistants. The history is due to Assistants being modelled on the "Assistants API" from OpenAI before Agents really took off. We kept Assistants as it had a much cleaner UI for existing users. However most of the functionality and improvements in the AI ecosystem have gone into Agents and most of what an assistant is, is really an "Agent"</p>
<p>Therefore we've created a confusing middle ground. When an Assistant is created behind the scenes an identical "Agent" is created that mimics the configuration. Changes to the Assistant, change its connected Agent and visa versa. However Agents have more complex settings (able to attach tools, Assistants can only attach sub-agent tools and indexes) whilst Assistants are always assumed to have an end-user using them through a chatbot and so we can get context such as the page they are on, the user's permissions. (Agents could be used behind the scenes in automation).</p>
<p>Therefore the current approach to doing advanced tools in a chatbot is:</p>
<p>Chatbot - Connects to via config-> Assistant<br>
Assistant ---> Connected to via config> Assistaant's Agent<br>
Assistaant's Agent ->> Connnect to via Tools calling. --> Simple Agent<br>
Simple Agent -> Connect to Tools.</p>
<p>However a major limitation is that the Assistant's Agent and the Sub-agent do not share context and so for simple cases this approach just adds complexity, reduces reliability and increases cost.</p>
<p>Note: We are trying to do this in flowdrop UI, hooking into the Assistants entities and Agent entities behind the scenes rather than bringing this into the AI module (though maybe we should follow up by supporting this in the AI module itself)</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Add upstream conversion operations in `ai_assistant_api`:</p>
<p>1. **Agent operation**: `Convert to Assistant`<br>
2. **Assistant operation**: `Downgrade to Agent`</p>
<p>Both operations use confirmation forms and explicit server-side entity updates.</p>
<p><strong>Behavior</strong></p>
<p><strong>1. Convert to Assistant</strong><br>
- Looks for an existing assistant linked to the selected agent (`ai_agent` field).<br>
- If one exists, reuses it.<br>
- Otherwise creates a new assistant linked to that agent.<br>
- Redirects to assistant edit form.</p>
<p><strong>2. Downgrade to Agent</strong><br>
- Deletes the selected assistant entity.<br>
- Preserves linked agent config.<br>
- Unlinks DeepChat blocks that referenced the deleted assistant.<br>
- Shows links to each unlinked chatbot block config page so admins can use `Remove block` if desired.<br>
- Redirects to linked agent edit form.</p>
<h3 id="manual-testing">Manual Testing</h3>
<p>1. Go to `/admin/config/ai/agents`.<br>
2. In an agent row dropdown, click `Convert to Assistant`.<br>
3. Confirm and verify assistant is created/linked and opens in assistant edit form.<br>
4. Go to `/admin/config/ai/ai-assistant`.<br>
5. In that assistant row dropdown, click `Downgrade to Agent`.<br>
6. Confirm and verify:<br>
- assistant is removed,<br>
- linked agent still exists,<br>
- DeepChat blocks previously linked to assistant are unlinked,<br>
- status message includes links to those block config pages.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[X ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
issue
GitLab AI Context
Project: project/ai
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/ai/-/raw/1.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/ai
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD