Issue #3586346: Implement plugin-based generic context consumers and unified consumer configuration.
Description
Closes Implement plugin-based generic context consumer... (#3586346 - closed) • Unassigned • 1.0.0-beta5
Implements the architecture accepted in [Discuss] Move from agent-specific to generic c... (#3586319 - closed) • Unassigned • 1.0.0-beta4: everything that
receives context is a consumer, and agents are one consumer type.
Consumer types are Drupal attribute plugins. All configured consumers
use one ai_context.consumers store. Agent and non-agent requests
share the same request-building and selection pipeline.
This is a clean-slate beta change. Agent-specific factory methods and
configuration are removed rather than deprecated. Existing agent
configuration and usage data are migrated by updates 10028–10031.
As-built plan: ai_context-consumer-plugin-implementation-plan-v12.md
on the issue. Do not look up v11 draft names.
What this MR ships
AiContextConsumerTypeplugins. AI Context shipsagent. Other types belong in the consuming project.- Canonical IDs
{type}:{instance}viaAiContextConsumerId(fromParts,fromString,isValid,toString()). No__toString(). Type plugin IDs cannot contain:. - One store:
ai_context.consumers. Instance flag ispush_enabled(migrated fromallow_context_injection). Agentloop_awarelives undersettings.loop_aware. - Factory:
fromConsumer(),loadConsumerConfig(),resolveConsumerConfig(),isPushAllowed().fromAgent()/findAgentConfig()/ factoryisLoopAware()are gone. - Agent path stays on
BuildSystemPromptEvent. Generic path isAiContextPreGenerateResponseSubscriberonPreGenerateResponseEvent. Agent type advertises no routing tags and always declinesresolveConsumerId(). - Combined push gate: instance
push_enabledAND typeisEnabled()ANDisAvailable(). Missing type settings mean enabled. Pull ignores those gates. - Invocation result on the
ai_contextmetadata key. Compare statuses toAiContextInvocationResult(PUSHED,NO_ITEMS,PUSH_DISABLED,TYPE_DISABLED,STALE,DECLINED,AMBIGUOUS). - Usage fields
consumer_id/consumer_type; View repair in10031. Composite indexai_context_usage_consumeris in the shared install helper. - Consumer listing, editor, and type settings. Debug / Explore and
loop-aware are Agent-type only
(
instanceof AiContextConsumerTypeAgent). Old/settings/agentsURLs are removed, not redirected. - Absent
selection_modeinherits the site default (relevant). There is no written generic-consumerminimaldefault. - Runtime no longer dual-reads leftover
ai_context.agents(overview, cleanup, budget). Importing leftoverai_context.agentsafter migration is a validation error.
Breaking API / config (beta)
| Removed | Replacement |
|---|---|
fromAgent() |
fromConsumer('agent:' . $id) |
findAgentConfig() |
loadConsumerConfig() / resolveConsumerConfig() |
Config object ai_context.agents |
ai_context.consumers |
Config key allow_context_injection |
push_enabled |
isInjectionAllowed() |
isPushAllowed() |
Admin paths /settings/agents |
/settings/consumers and /settings/consumers/{consumer_id}/edit |
Usage field agent_id |
consumer_id plus consumer_type |
Views field ai_context_agent_link |
ai_context_consumer_link |
Also dropped: capabilities object, type getId() / getConfigName() /
defaultTypeSettings(), stored getType() / getSettings() /
generic isLoopAware(), Consumer ID __toString(), plugin weight,
agent-route redirects. All src/Form/* classes are @internal.
Follow-ups (not this MR)
- Create ai_ckeditor context consumer plugin issu... (#3586452 - closed) • Kristen Pol • 1.0.0-beta5 AI CKEditor consumer plugin (this queue until copied to CKEditor/AI)
- Refactor translation workflow to support Tool A... (ai_translate#3585523 - closed) • Unassigned Translate converting to agents; verified against this branch in Test CCC with AI Translate agent MR (#3586446 - closed) • Unassigned • 1.0.0-beta5
- Update Chicago demo with generic consumer patch... (#3586457) • Unassigned • 1.0.1 Chicago demo ConfigAction/recipe patch after merge
A Drupal.org change record is not required in beta. The upgrade
contract is in docs/developers/api-stability.md,
docs/developers/configuration.md, and docs/upgrade-policy.md.
Self-review threads on this MR have been resolved.
Testing instructions
Testing Setup:
mkdir my-drupal-site && cd my-drupal-site
ddev config --project-type=drupal11 --docroot=web
ddev start
ddev composer create-project drupal/cms
ddev composer drupal:recipe-unpack
ddev exec sed -i 's/"minimum-stability": "stable"/"minimum-stability": "dev"/' composer.json
ddev composer require drupal/ai_context:dev-1.0.x -W
ddev composer require drupal/ai_agents_debugger
ddev launch
go through installer in browser and choose the Byte site template
ddev drush en ai_context ai_agents_debugger canvas_ai -y
cd web/modules/contrib/ai_context
switch to the relevant MR branch (see GitLab fork instructions)
ddev drush crFor an already-installed site on this branch:
ddev drush updatedb --yes
ddev drush cache:rebuildThen re-export configuration so ai_context.consumers replaces
ai_context.agents.yml in sync. Run drush updatedb before
drush config:import.
- Confirm updates
10028–10031ran.ai_context.agentsis gone from active config. Existing agent overrides now have canonical IDsagent:{id}andpush_enabled. - Open
/admin/config/ai/context/settings. Consumer Types is the tab to the left of Consumers. - On Consumer Types, the Agent type is enabled by default. Edit it and confirm the kill-switch copy: disabling the type turns off push for every agent, including row-less agents; pull tools keep working.
- On Consumers, an existing agent shows with
agent:{id}. Open Configure context.push_enableddefaults on. Loop-aware and Debug / Explore appear only for the Agent type. - With
ai_agents_debuggerenabled, Debug is visible for an agent consumer. Withai_agents_explorerenabled, Explore is visible. Uninstall explorer and confirm Explore disappears. A non-agent consumer (enableai_context_test_consumerif needed) never shows those links. - Bookmark
/admin/config/ai/context/settings/agents404s. There is no redirect. - Run an agent that previously received context. Context still
injects on
BuildSystemPromptEvent. Turningpush_enabledoff for that agent suppresses push, including Always include and Global items. Pull tools still honor saved subscriptions. - Disable the Agent consumer type. Row-less agents also stop receiving push. Re-enable it.
- Optional: enable
ai_context_test_consumer, set a test type instance topush_enabled, and send a chat request tagged with that type's routing tag. Confirm generic-path injection and anai_contextinvocation result on the event metadata (PUSHEDor a skip status). Agent-tagged andai_assistant_api-tagged requests must not double-inject. - Import leftover
ai_context.agentsfrom config sync. Import fails with a validation error that names the remediation.
Post-merge
- Sites must run
drush updatedbimmediately after deploying the code, then re-export config. - Do not apply recipes or ConfigActions that still write
ai_context.agents. The Chicago demo patch is Update Chicago demo with generic consumer patch... (#3586457) • Unassigned • 1.0.1. - Old
/settings/agentsbookmarks 404 by design.
Checklist
- I have updated the MR title to use format:
Issue #3586346: Implement plugin-based generic context consumers and unified consumer configuration. - I have updated the MR description to include:
Closes #3586346+s - I have performed a self-review of my own code
- I have added or updated tests, or explained in the description why this change is not covered by tests
- I have updated documentation for any new or changed functionality
- I have written testing instructions and verified them locally
- I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
- This MR contains no breaking API or hook changes, or they are explicitly documented in the description
AI Compliance
Note
Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.
-
AI Assisted Code
Mainly written by a human; AI used for autocomplete or partial generation under full human supervision. -
AI Generated Code
Mainly generated by AI, reviewed and approved by a human before this MR was created. -
Vibe Coded
Generated by AI and only functionally reviewed before this MR was created.
READY FOR REVIEW AND TESTING!!!
MULTIPLE REVIEWERS/TESTERS ARE WELCOME TO REVIEW/TEST AT THE SAME TIME
MULTIPLE ASSIGNEES ARE ALLOWED ON ISSUES SO ASSIGN EVEN IF YOU SEE OTHERS ASSIGNED
NOTE TO REVIEWERS: THIS IS A MONSTER MR
- YOU ARE NOT EXPECTED TO MANUALLY REVIEW THE CODE CHANGES (I HAVE DONE THAT EXCEPT FOR TESTS)
- IT WOULD BE HELPFUL IF YOU MANUALLY REVIEWED THE NEW API METHODS BUT THAT'S NOT STRICTLY REQUIRED
- HAVE YOUR AGENT(S) REVIEW THE CODE AND TEST IT (I HAVE USED GROK AND OPUS 5, SO USING DIFFERENT MODELS IS HELPFUL)
- MANUAL TESTING IS THE MOST IMPORTANT THING TO DO, ESPECIALLY LOOKING AT THE UI BEFORE AND AFTER THE CHANGES