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 1002810031.

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

  • AiContextConsumerType plugins. AI Context ships agent. Other types belong in the consuming project.
  • Canonical IDs {type}:{instance} via AiContextConsumerId (fromParts, fromString, isValid, toString()). No __toString(). Type plugin IDs cannot contain :.
  • One store: ai_context.consumers. Instance flag is push_enabled (migrated from allow_context_injection). Agent loop_aware lives under settings.loop_aware.
  • Factory: fromConsumer(), loadConsumerConfig(), resolveConsumerConfig(), isPushAllowed(). fromAgent() / findAgentConfig() / factory isLoopAware() are gone.
  • Agent path stays on BuildSystemPromptEvent. Generic path is AiContextPreGenerateResponseSubscriber on PreGenerateResponseEvent. Agent type advertises no routing tags and always declines resolveConsumerId().
  • Combined push gate: instance push_enabled AND type isEnabled() AND isAvailable(). Missing type settings mean enabled. Pull ignores those gates.
  • Invocation result on the ai_context metadata key. Compare statuses to AiContextInvocationResult (PUSHED, NO_ITEMS, PUSH_DISABLED, TYPE_DISABLED, STALE, DECLINED, AMBIGUOUS).
  • Usage fields consumer_id / consumer_type; View repair in 10031. Composite index ai_context_usage_consumer is in the shared install helper.
  • Consumer listing, editor, and type settings. Debug / Explore and loop-aware are Agent-type only (instanceof AiContextConsumerTypeAgent). Old /settings/agents URLs are removed, not redirected.
  • Absent selection_mode inherits the site default (relevant). There is no written generic-consumer minimal default.
  • Runtime no longer dual-reads leftover ai_context.agents (overview, cleanup, budget). Importing leftover ai_context.agents after 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)

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 cr

For an already-installed site on this branch:

ddev drush updatedb --yes
ddev drush cache:rebuild

Then re-export configuration so ai_context.consumers replaces ai_context.agents.yml in sync. Run drush updatedb before drush config:import.

  1. Confirm updates 1002810031 ran. ai_context.agents is gone from active config. Existing agent overrides now have canonical IDs agent:{id} and push_enabled.
  2. Open /admin/config/ai/context/settings. Consumer Types is the tab to the left of Consumers.
  3. 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.
  4. On Consumers, an existing agent shows with agent:{id}. Open Configure context. push_enabled defaults on. Loop-aware and Debug / Explore appear only for the Agent type.
  5. With ai_agents_debugger enabled, Debug is visible for an agent consumer. With ai_agents_explorer enabled, Explore is visible. Uninstall explorer and confirm Explore disappears. A non-agent consumer (enable ai_context_test_consumer if needed) never shows those links.
  6. Bookmark /admin/config/ai/context/settings/agents 404s. There is no redirect.
  7. Run an agent that previously received context. Context still injects on BuildSystemPromptEvent. Turning push_enabled off for that agent suppresses push, including Always include and Global items. Pull tools still honor saved subscriptions.
  8. Disable the Agent consumer type. Row-less agents also stop receiving push. Re-enable it.
  9. Optional: enable ai_context_test_consumer, set a test type instance to push_enabled, and send a chat request tagged with that type's routing tag. Confirm generic-path injection and an ai_context invocation result on the event metadata (PUSHED or a skip status). Agent-tagged and ai_assistant_api-tagged requests must not double-inject.
  10. Import leftover ai_context.agents from config sync. Import fails with a validation error that names the remediation.

Post-merge

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

Edited by Kristen Pol

Merge request reports

Loading