Problem/Motivation
A mode (ai_agent_mode config entity) is keyed to a parent agent. When two AI Assistants are backed by the same parent agent, every mode is offered in both assistants' chats, so a mode written for one assistant's job shows up in the other. There is no way to say "offer this mode for this assistant only". The existing surfaces field does not help: it is a free list of surface IDs that most surfaces do not filter on.
Steps to reproduce
- Install AI Agent Modes with the AI Assistant API and AI Chatbot.
- Create two AI Assistants backed by the same parent agent.
- Save a mode for that parent agent.
- Open both assistants' chats: the same mode is offered in both, with no way to limit it to one.
Proposed resolution
Add an optional assistants list to the mode entity: the AI Assistants the mode is offered for. Empty (the default) means every assistant, so existing modes are unchanged. A non-empty list means those assistants only, and the mode is withheld where there is no assistant at all (the Drupal Canvas AI panel is driven by the canvas_ai_orchestrator agent, not by an assistant). Unlike surfaces, every surface passes the assistant along, so this is real filtering.
What the change covers:
ai_agent_modeentity: newassistantsproperty inconfig_export,getAssistants(),appliesToAssistant(), plus the config schema.ModeManagerInterface::listModes($parent_agent_id, $surface, $assistant_id)gains the assistant filter.- Admin: an AI Assistants checkboxes field on the mode add/edit form (only rendered when the site has assistants), and an AI Assistants column on the Modes listing showing "Any assistant" when open.
- Surfaces all pass the assistant: the AI Assistant chat form (
#assistanton theai_agent_mode_selectelement), the AI Chatbot DeepChat block (drupalSettings.aiAgentModesChatbot.assistant, script sends?assistant=<id>), the selector block (its configured AI Assistant), andGET /ai-agent-modes/options/{agent}?assistant=<id>(the response also echoesassistant). - Tests: a kernel test case for the assistant filtering, an updated chatbot hooks unit test, and a new webship-js BDD feature
tests/features/drupal/05-01-02-assistant-limited-modes.feature. - Docs: managing modes, developing with modes, troubleshooting, choosing a mode, README.
AI-Generated: Yes. Per the Policy on the use of AI when contributing to Drupal, this issue summary and the forthcoming patch were drafted with AI assistance.
Remaining tasks
- ✅ File an issue about this project
- ❌ Addition/Change/Update/Fix to this project
- ❌ Testing to ensure no regression
- ❌ Automated unit/functional testing coverage
- ❌ Developer Documentation support on feature change/addition
- ➖ User Guide Documentation support on feature change/addition
- ➖ UX/UI designer responsibilities
- ➖ Accessibility and Readability
- ❌ Reviewed by a human
- ❌ Code review by maintainers
- ❌ Full testing and approval
- ❌ Credit contributors
- ❌ Review with the product owner
- ❌ Update Release Notes
- ❌ Release
User interface changes
- Yes: new AI Assistants field on the mode add/edit form, new AI Assistants column on the Modes listing.
API changes
- Yes, additive:
AiAgentModeInterface::getAssistants()and::appliesToAssistant(); a third$assistant_idargument onModeManagerInterface::listModes()(optional, defaults to NULL); a new#assistantproperty on theai_agent_mode_selectelement; a new optionalassistantquery parameter and response key on the options endpoint.
Data model changes
- Yes, additive:
assistantssequence onai_agent_modes.ai_agent_mode.*. Defaults to empty, so existing modes keep behaving exactly as before. No update hook needed.
Release notes snippet
- A mode can now be offered for selected AI Assistants only, so two assistants sharing one parent agent can each offer the modes that belong to their job. Naming no assistant, the default, keeps offering the mode everywhere.
Issue fork ai_agent_modes-3613643
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
rajab natshahComment #5
rajab natshah✅ Released ai_agent_modes-1.0.0-alpha4