Skip to content

Services

The AI Context module registers the following services in ai_context.services.yml.

Core services

ai_context.selector

Class: Drupal\ai_context\Service\AiContextSelector

The high-level entry point for context selection. Coordinates scope matching, routing, rendering, and entity target resolution into a single select() call.

Key method:

public function select(
  string $task,
  string $agentId,
  array $alwaysInclude = [],
  ?int $maxOverride = NULL,
  ?array $entityContext = NULL,
): array

Returns an array with text (rendered context) and ids (selected item IDs).

ai_context.router

Class: Drupal\ai_context\Service\AiContextRouter

Ranks candidate context items by relevance to a given task. Supports two strategies:

  • Keyword -- matches keywords from the task against item labels, content, and tags
  • LLM -- uses an AI provider to rank items by relevance

The strategy is configured at /admin/ai/context/settings/general.

ai_context.renderer

Class: Drupal\ai_context\Service\AiContextRenderer

Renders selected context items into text for inclusion in agent prompts. Respects a configurable token budget and skips items that would exceed it.

ai_context.scope_matcher

Class: Drupal\ai_context\Service\AiContextScopeMatcher

Scores context items against an agent's scope subscriptions. Produces a relevance score for each item based on how many scope values match.

ai_context.entity_target_resolver

Class: Drupal\ai_context\Service\AiContextEntityTargetResolver

Resolves the current entity from the route or request context. Used to match context items that target specific entities.

ai_context.usage_tracker

Class: Drupal\ai_context\Service\AiContextUsageTracker

Records usage data when context items are selected. Tracks which items were used, by which agent, on which route, and which entities were involved.

Plugin managers

plugin.manager.ai_context_scope

Class: Drupal\ai_context\AiContextScopeManager

Plugin manager for scope plugins. Handles discovery, instantiation, and weight-based sorting of AiContextScope plugins.

Support services

ai_context.markdown_renderer

Class: Drupal\ai_context\Markdown\MarkdownRenderer

Converts markdown content to HTML for display.

logger.channel.ai_context

Standard Drupal logger channel for ai_context log messages.

Event subscribers (registered as services)

ai_context.system_prompt_subscriber

Class: Drupal\ai_context\EventSubscriber\SystemPromptSubscriber

Listens for BuildSystemPromptEvent and AgentStartedExecutionEvent. See Events.

ai_context.agent_tool_subscriber

Class: Drupal\ai_context\EventSubscriber\AiContextAgentToolSubscriber

Listens for AgentToolFinishedExecutionEvent. See Events.

Route subscribers

ai_context.route_subscriber

Class: Drupal\ai_context\Routing\AiContextRouteSubscriber

Alters routes for the module.

ai_context.scope_route_subscriber

Class: Drupal\ai_context\Routing\AiContextScopeRouteSubscriber

Dynamically generates routes for per-scope settings forms based on discovered scope plugins.

Access checks

ai_context.access_check.overview_page

Class: Drupal\ai_context\Access\AiContextOverviewAccessCheck

Controls access to the overview page based on the show_overview_page setting.

ai_context.access_check.usage_page

Class: Drupal\ai_context\Access\AiContextUsageAccessCheck

Controls access to the usage tracking page based on whether tracking is enabled.

Other services

ai_context.uninstall_validator

Class: Drupal\ai_context\AiContextUninstallValidator

Prevents uninstalling the module when context items exist.

Drupal\ai_context\Hook\DiffHooks

Class: Drupal\ai_context\Hook\DiffHooks

Autowired service for Diff module integration hooks.