task(AI): #3592030 Canvas AI: Remove obsolete region-based AI instructions and the unused page variant descriptions form
Summary
Canvas replaced theme-global regions with page variants: a page's own content still renders in the content region, and the page variant supplies everything around it. canvas_ai still carried the old multi-region model in two places:
- The
canvas_page_builder_agentandcanvas_template_builder_agentsystem prompts described header, footer and sidebar regions and consumed a[canvas_ai:available_regions]token whose value only ever listedcontent. CanvasAiPageVariantSettingsForm(/admin/config/ai/canvas-ai-page-variant-settings) collected per-variant AI descriptions incanvas_ai.page_variant.settings. Those descriptions reached the prompts only through that same token, so once the token goes they have no consumer.
This MR removes the token and the code that fed it, makes both agents always build in the content region and never generate site chrome, deletes the form with its route, tab, schema and test, and ships post-updates that refresh existing sites.
Closes #3592030.
Out of scope, per the issue: the placement tools keep their region parameter, getRegionIndex() and validateRegionExists() stay, and the multi-region placement tests stay.
What changed
Token and its supplier chain (commit 1)
modules/canvas_ai/src/Hook/CanvasAiHooks.php: theavailable_regionsentry is removed fromcanvas_ai_token_info()and itscasefromcanvas_ai_tokens(). The other ten tokens are untouched.modules/canvas_ai/src/CanvasAiPageBuilderHelper.php:getAvailableRegions(),resolveVariantForContext()andgetVariantDescription()are removed together with thePageVariantResolverconstructor dependency and four now-unused imports. The service is autowired, socanvas_ai.services.ymlneeds no change.modules/canvas_ai/src/Controller/CanvasBuilder.phpandmodules/canvas_dev_ai/src/Controller/CanvasDevAiBuilder.php: theavailable_regionstoken context is removed. The dev controller'sbuildTokenContexts()lost its now-unused$current_layoutparameter.ui/src/components/aiExtension/currentLayout.ts: a dangling@seedocblock line is removed (comment only, no behavior change).CanvasAiPageBuilderHelperTest::testGetAvailableRegionsSurfacesVariantDescription()is removed with the method it covered.
Prompts (commit 2)
modules/canvas_ai/config/install/ai_agents.ai_agent.canvas_page_builder_agent.yml
- The "Available regions" context item and the trailing
## Available regions/ token block are gone. - A Region rule paragraph states that every component goes in the
contentregion and that header, navigation, footer and sidebars are supplied by the page variant and must never be generated or targeted. - Layout comprehension and the placement table now speak of the
contentregion only. Thetarget: [REGION_NAME or SLOT_ID]tool syntax stays, becauseset_component_structurestill accepts it.
modules/canvas_ai/config/install/ai_agents.ai_agent.canvas_template_builder_agent.yml
descriptionno longer advertises "with or without header and footer"; it states the agent builds the page body in the content region and that the page variant supplies the chrome.- "Component Placement Strategy" is reduced to Content Region Only, No Site Chrome (even when the user asks for a page "with a header and footer", build the body and say the page variant provides them) and the existing minimum-sections rule. The "Region Awareness ... active theme" and "Region descriptions" bullets are gone.
- "Layout Integration" keeps one bullet about what
contentalready holds; the YAML format example uses a singlecontent:key; the## Available regionsblock is gone.
Form removal (commit 3)
- Deleted:
modules/canvas_ai/src/Form/CanvasAiPageVariantSettingsForm.php, thecanvas_ai.page_variant_settingsroute, its local task incanvas_ai.links.task.yml, thecanvas_ai.page_variant.settingsblock inconfig/schema/canvas_ai.schema.yml, andtests/src/Functional/Form/CanvasAiPageVariantSettingsFormTest.php. - The
use Drupal Canvas AIpermission is shared by the other routes and stays.
Post-updates (commit 4)
canvas_ai_post_update_0011_reimport_region_free_builder_agents(): re-importssystem_promptfor both agents anddescriptionfor the template builder fromconfig/install, setting only those keys so the per-site uuid and_corehash survive (the 0003/0006 lesson), and logs the usual "customizations overwritten" warning.canvas_ai_post_update_0012_delete_page_variant_settings(): deletescanvas_ai.page_variant.settingsfrom the default storage and every language collection, resets the config factory and rebuilds the router because the route and tab are gone.CanvasAiOrchestratorPostUpdateTestis renamed toCanvasAiPostUpdateTest(existing 0003/0006 cases kept) and gainstestPostUpdate0011RefreshesBuilderAgentPrompts()andtestPostUpdate0012DeletesPageVariantSettings(). The 0012 test seeds the object through raw config storage in the default and alanguage.frcollection, since the schema is gone.
Docs and eval harness (commits 5 and 6)
docs/page-variants.md: thecanvas_aiclause now says agents build only thecontentregion.docs/user/src/content/docs/ai-assistant/index.mdx: the template builder builds the page body; the header and footer example prompts are removed.modules/canvas_ai/tests/modules/canvas_ai_agents_test/tests/test_drupal_canvas_page_builder_agent_test_group.yaml(manual LLM eval harness, not CI): theavailable_regionstoken values are stripped from every case, and the one case that existed only to check that a region description drives the heading level is deleted, because that mechanism no longer exists. The multi-region placement cases stay for the follow-up.
No echoai fixture changes: the provider matches on messages and tools, not the system prompt, and no fixture references either agent. No changeset: nothing under packages/* changed.
Testing instructions
Automated
- [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/CanvasAiPostUpdateTest.php - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/CanvasAiPageBuilderHelperTest.php - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/CanvasAiBuilderControllerTest.php - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/CanvasAiDevControllerTest.php - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/Agents/CanvasDevPageBuilderAgentEndToEndTest.phpand.../CanvasComponentAgentEndToEndTest.php(dev controller token contexts changed) - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/Plugin/AiFunctionCall(region validation messages unchanged) - [ ]
composer run phpunit -- modules/canvas_ai/tests/src/Kernel/CanvasAiDefaultInformationToolsTest.php,.../EventSubscriber/LayoutFixtureSubscriberTest.php,modules/canvas_ai/tests/src/Functional/Form/CanvasDevAiAgentSelectionFormTest.php - [ ]
composer run lintandnpm run lint
Manual, in the UI
Setup:
- [ ] Check out the branch and run
drush cr. - [ ] Optional, to exercise the update path: on
1.xfirst, open/admin/config/ai/canvas-ai-settings→ Page Variant Descriptions tab (create a page variant at/admin/structure/canvas/page-variantsif none exists), typeLead with a hero section.into a variant's Description and Save configuration; confirm withdrush config:get canvas_ai.page_variant.settings. Then check out this branch anddrush cr. - [ ] A default chat provider is configured at
/admin/config/ai/settings(Test 4 makes real provider calls).
Test 1: the post-updates refresh an existing site
- [ ] Run
drush updb -y. Expected:canvas_ai_post_update_0011_reimport_region_free_builder_agentsruns with a warning starting "The Canvas AI page builder and template builder agent system prompts have been updated", thencanvas_ai_post_update_0012_delete_page_variant_settings, then "Finished performing updates." - [ ]
drush config:get canvas_ai.page_variant.settingsreports that the config does not exist.
Test 2: the form, tab and route are gone
- [ ]
/admin/config/ai/canvas-ai-settingsshows General Settings and Component Descriptions (plus Agents & Tools whencanvas_dev_aiis installed) and no Page Variant Descriptions tab. - [ ]
/admin/config/ai/canvas-ai-page-variant-settingsis a 404 even for an administrator. - [ ]
/admin/config/ai/canvas-ai-component-description-settingsstill loads.
Test 3: the agent prompts no longer mention regions
- [ ]
/admin/config/ai/agents→ Edit on Drupal Canvas Page Builder Agent. In Agent Instructions,available_regionshas no match;Region rulematches the paragraph "Every component goes in thecontentregion ...". - [ ] Edit on Drupal Canvas Template Builder Agent. Description begins "This tool specializes in building the body of a complete web page" and does not contain "with or without header and footer". In Agent Instructions,
available_regionsandanother_regionhave no match;Content Region OnlyandNo Site Chromematch once each. - [ ] Leave both forms without saving.
Test 4: both agents build in the content region (real provider)
A. Site running the shipped chat (no canvas_dev_ai):
- [ ] Open a Canvas page in the editor and click Open AI Panel (sparkle icon in the top bar).
- [ ] Send
Add a hero section at the top of the page. Expected: a hero appears at the top of the page body; in the Layers panel it sits under Content. - [ ] Send
Create a landing page for a bakery with a header and footer. Expected: several sections appear in the page body, all under Content; the reply says the header and footer are provided by the page variant; no header, navigation or footer components are created.
B. Site with canvas_dev_ai installed:
-
[ ] Note the current Tools list:
drush config:get canvas_dev_ai.settings tools. -
[ ] Offer both agents as Tools (the Agents & Tools form does not list them, so set config directly and do not save that form during the test):
drush config:set --input-format=yaml -y canvas_dev_ai.settings tools '[canvas_page_builder_agent, canvas_template_builder_agent]' drush cr -
[ ] Open a Canvas page in the editor and click Open AI Panel. Click the sliders icon at the bottom-left of the chat input and pick Drupal Canvas Page Builder Agent; send
Add a hero section at the top of the page. Expected as in A. -
[ ] Remove the pill with its ×, pick Drupal Canvas Template Builder Agent, send
Create a landing page for a bakery with a header and footer. Expected as in A. -
[ ] Optional: in DevTools → Network (filter
ai-dev), the last response of each turn has anoperationsarray whose components'nodePathvalues all start with0(the content region) and notargetother thancontent.
Cleanup:
- [ ] Discard the AI-placed components via Review changes, or do not publish.
- [ ] Setup B only: restore the Tools list, e.g.
drush config:set --input-format=yaml -y canvas_dev_ai.settings tools '[]'(ordrush php:eval '\Drupal::configFactory()->getEditable("canvas_dev_ai.settings")->set("tools", [])->save();'), thendrush cr. - [ ] Delete any page variant created only for the optional setup step.
Follow-ups (not in this MR)
- The placement tools' region parameter and the multi-region placement tests, as noted in the issue.
- The orchestrator prompt still routes "add a header/footer" requests to the builder agents; those agents now build the body and explain that the page variant provides the chrome.
AI use disclosure
Per Drupal's policy on the use of AI when contributing: this MR was developed with AI assistance (Claude Code). The author reviewed every change, ran the automated tests and lints locally, applied the updates on a live site and verified both agents with the real provider.