Skip to content

Context Items

Context items are the core content entities in the AI Context module. Each item contains information that AI agents and other consumers can use when helping with tasks on your Drupal site.

Creating a context item

  1. Go to /admin/config/ai/context/items
  2. Click Add Context Item
  3. Fill in the fields described below
  4. Choose a state in Save as. New items default to Published, unless Publish by default is turned off under Settings → Context Items
  5. Save the item

Fields

Label, Description, Purpose, Content and Priority are required. Priority defaults to Medium. Context scope, Specific entities and Parent are optional. The optional Token name field is in the sidebar. See Token name.

Label

Required. The title of the context item, used to identify it in the admin listing and in injected context metadata.

Description

Required. A short summary of what the item covers. Helps editors understand the item without reading the full content.

Purpose

Required. Describes why this context item exists and when it should apply.

Purpose is included in injected context metadata (alongside the item ID and label). For conditional subcontext children, Purpose is also sent to the AI provider with each candidate child ID and is the main signal used to decide whether the child matches the current task.

Write task-specific inclusion criteria. See Writing Purpose for conditional children for examples and anti-patterns.

Content

Required. The main body of the context item, written in markdown using the MDXEditor. This is the text that gets included in consumer system prompts when the item is selected. Drupal tokens such as [site:name] are not replaced. They are sent with a space on both sides of the colon, for example [site : name]. See Authoring trust.

If an item tells the AI which tokens to use, for example the URL alias pattern blog/[node:title], the AI receives blog/[node : title]. When an agent then saves that pattern in a settings field, it can keep the spaces, and the token does not work. Add an instruction to the item such as "Remove the spaces around the colon when you write a token into a field." The agent is then more likely to save blog/[node:title].

The editor toolbar has a mode toggle with three views:

  • Rich text — the default WYSIWYG view.
  • Diff mode — compares the current text against the saved version.
  • Source mode — the raw markdown, for pasting or fixing formatting by hand.

Import content

When the optional ai_context_document_loader submodule is enabled, a Load Document button appears in the MDXEditor toolbar. Editors can import text, Markdown, PDF, or URL content directly into this field. See Content importers for installation, supported sources, and usage.

Imported content is copied, not linked to the source. It is untrusted until reviewed: it may be stale, wrong, or contain prompt-injection instructions. Sanitization limits unsafe markup in the editor but does not make the text safe for AI prompts. Review and revise imports before publication; prefer draft saves or disable Publish by default on importer-heavy sites. See Review imported content before publication.

Context scope

Scope values that categorize this item. See Scopes for details on the scope system.

When editing a subcontext item, the Same as parent checkbox controls whether the child uses the parent's scope or defines its own. See Subcontext hierarchies — Parent scope.

Priority

Required. High, Medium (the default) or Low. Priority controls ordering within each selection group. For subscription-scored items, priority breaks equal-score ties. Higher-priority items are considered first when global, internal candidate, or token limits apply within a group.

Specific entities

Associate this context item with specific content entities (nodes, media, etc.) using dynamic entity references. This is a hard filter: the item is left out when the consumer is working on different content, or when no request entity reaches CCC. On a matching entity it enters the exact-match group. Other items (Global, Always include, subscription matches) can still be selected alongside it.

The request entity must arrive via the route, agent token contexts, or explicit tool parameters. Chatbots and AI Assistants do not get this from the visitor's URL automatically. See Page and entity context.

Target references control applicability during selection, not Drupal view access to those entities. See Access boundaries.

Parent (subcontext)

Optional parent context item when subcontext hierarchy is enabled. Child items are included when their parent is selected for a consumer.

See Subcontext hierarchies for required vs conditional types, when to use subcontext, limits, and the site-wide toggle.

On the context items listing, a child row is indented under its parent and labelled Included in <parent> when it is required, or Conditionally included in <parent> when it is conditional. Where the parent is one the user cannot view, the label falls back to "Included in parent context" or "Conditionally included in parent context" without naming it. A parent row carries a badge with the number of children it has, whose tooltip reads "1 subcontext" or "N subcontexts".

Persistence rules (subcontext)

When subcontext hierarchy is enabled, relationships are validated on save:

  • A context item cannot be its own parent
  • Subcontext hierarchies are limited to one level
  • An item that already has children cannot become a subcontext itself
  • subcontext_type is required when a parent is selected
  • If a parent item is deleted, child items remain as standalone items with their parent and subcontext_type fields cleared

Token name

A token with the token name of an item puts the content of that item into other text. For example, you can put a brand voice item into the system prompt of an AI agent. Selection does not decide if the item is included. The site builder or developer who adds the token to the text decides it.

Set a token name

  1. Open the edit form of the item.
  2. In the sidebar, expand Token. This section is below Authoring information. It is open when the item has a token name.
  3. Enter a value in Token name, for example brand_voice.
  4. Save the item.

The value has these rules:

  • Use only lowercase letters, numbers and underscores. Start with a letter.
  • Use a maximum of 64 characters.
  • Each token name is unique. Two items cannot have the same token name.
  • To remove the token name, make the field empty and save the item.
  • To change or remove the token name, save the item as published. A draft of a published item cannot change the token name, because only the published revision stores it. The form shows an error in that case. When the item is not published now (for example a new or archived item), a draft can change it.

Only users with the Administer AI Context permission can set, change or remove a token name. Other users do not see the Token section. Field access applies this rule, so it applies also outside the item form.

The Token section shows only on the original language of the item, not on the translation forms. See Multilingual support.

Use the token

When an item has the token name brand_voice, use this token:

[ai_context:item:brand_voice]

The general pattern is [ai_context:item:TOKEN_NAME].

The token gives:

  • The content of the published translation in the current content language. If that translation does not exist or is not published, the token gives the published text in the original language. See Fallback behavior.
  • Only content that the current user can view. This is the same view check as for pushed context: the user needs View AI Context Items in CCC or Use Published AI Context in AI Features.
  • The content as it is. Drupal tokens in the content are neutralized, as on the other delivery paths. An item token in the content of an item is also neutralized, so it does not put a second item into the text. When the content ends with the start of a token, such as [current-user:, the token adds a space after the open bracket. Then the text after the token, for example a second item token, cannot complete it. See Authoring trust.
  • An empty string in all other cases, not the token text. For example, the token is empty when the item is not published, when the current user cannot view it, or when no item has the token name.

The token gives only the content field of the item, followed by the content of its required subcontext children, with a blank line between them. The token does not add the label or the purpose. It leaves out conditional children, because they need an AI decision for a task. Each child must be published in the chosen language, and the current user must be able to view it. As for the item itself, the scope rules do not apply to the children. When the subcontext feature is off, the token gives only the item. See Subcontext. The token budget of a consumer does not apply, and the token does not write a usage record.

The scope rules do not apply to the token. This includes the Roles hard filter and Specific entities. The administrator puts the token into the text on purpose, as with Always include. If the item must not reach a user, do not use the token in text that this user can get. See Access boundaries.

Where the token works

The token works in every module that replaces Drupal tokens in its text. It is not limited to AI prompts. Examples:

  • The system prompt of an AI agent. AI Agents replaces Drupal tokens in the agent system prompt. See Tokens in prompts.
  • Pathauto URL alias patterns.
  • Metatag values.
  • Webform email handlers.
  • ECA models.

AI core does not replace Drupal tokens in other prompts. In those prompts, the token stays as text.

AI Agents replaces tokens also in the output of default information tools. If a tool from another module returns text with an item token, AI Agents replaces it too. The token gives only content that the current user can view.

Warnings when the token stops working

Text that uses the token gets an empty value when the token name changes or the item is no longer available. CCC shows a warning in these cases:

  • You change the token name and save the item. The warning also shows the new token.
  • You remove the token name and save the item.
  • A change makes the token empty in a language. The rule is the same on all pages: the item form, the Content Moderation form, the delete confirmation and the revert confirmation. See When a change makes the token empty.
  • In the item form, you unpublish the item or one of its translations, for example with Archived. A new draft of a published item does not show the warning, because the token keeps the published content.
  • In the Content Moderation form on the Latest version tab, you apply a state that unpublishes the item or a translation, for example Archived. The item page shows that form only for an item that is not published, so no state there can unpublish the item.
  • You open the delete confirmation of an item or of a translation. This includes the delete page that the Translate tab links to. The warning uses the published content, also when the item has a pending draft.
  • You open the revert confirmation of a revision that is not published, for example an archived revision. A revert to a draft revision does not show the warning, because the published revision stays.
  • You set or change the Unpublish on date of an item that has a token name and save the item, and the unpublish at that date makes the token empty in a language. The warning shows the date. It also shows when you publish an item that already has a date, in the item form or in the Content Moderation form, and when you add a token name to a published item that already has a date. A Publish on date before the Unpublish on date counts as a publish, so the warning shows when you set the dates. When Scheduler publishes or unpublishes the item at a date, no other warning shows. No warning shows in these cases:
  • The translation is not published and has no Publish on date before the Unpublish on date, because the token does not give its text.
  • The original language is published and the date is on a translation, because the token falls back to the original language.

A limit: the date of a translation is checked only when you save that translation. If a translation has an Unpublish on date, and you unpublish the original language later, only the "not published now" warning shows. No warning shows for the date of the translation, although the token then becomes empty in that language at the date.

When a change makes the token empty

The token gives content in a language when the translation in that language is published, or when the original language is published. In the second case, the token falls back to the original language. A change makes the token empty when a language had content before the change and has no content after it. For example:

  • The published original language is unpublished or deleted. The token is then empty in all languages that do not have their own published translation.
  • The original language is not published, and a published translation is unpublished or deleted. This includes the last published translation of the item.

No warning shows in these cases:

  • You unpublish or delete a translation while the original language is published, because the token then gives the original-language content.
  • The item has no published translation, because the token is already empty.

For users with the Administer AI Context permission, the warning lists the configuration that contains the token, for example an AI agent or a Pathauto pattern. If no configuration contains the token, the warning says so. CCC searches the active configuration, including configuration translations. It does not search content, settings.php or code, so the token might still be in use when the list is empty.

Duplicates and revisions

  • A duplicate of an item starts without a token name, because token names are unique. See Duplicating items.
  • The token name is not revisionable and not translatable. One value applies to all revisions and all translations of the item. A revision revert does not change the token name. See Revisions.

Canonical view page

Opening a context item at /admin/config/ai/context/items/{id} (or viewing a revision) uses the full view mode and ai-context-item--full.html.twig instead of the default field list (ai-context-item.html.twig).

Main column

Rendered from the full view display field formatters:

  • Description
  • Purpose
  • Content
  • Content moderation control (when Content Moderation is enabled)

The page title is the entity label on the canonical route. Revision view uses the standard revision page title from the route.

A custom status badge shows the moderation state or published flag.

Built by AiContextItemViewBuilder (not field formatters):

  • Last updated date and author (plain text with avatar initial)
  • Subcontext type (when viewing a child item)
  • Scope plugin values. Global items show only Global: Enabled (matching the edit form). When at least one non-global scope is set, all enabled scope rows are shown (global first as Disabled, empty scopes as None in italics). When no non-global scopes are set, a SCOPE heading and italic message (No scope plugins are in use) are shown instead. Custom site section patterns list each path; entity type labels collapse when the type and bundle names match (e.g. Page: Page → Page). Each row includes a Phosphor icon via the shared .ai-icon pattern and SVGs bundled in this module.

Shown only when the item or its parent has subcontext children. Lists sibling child items with links and highlights the current item.

On revision view routes, the Nav panel lists subcontext siblings that existed when the viewed revision was saved (based on each child's parent reference at that point in time). Canonical view routes use the live child list.

Fields hidden on full view

These are omitted from the full view display because the template or AiContextItemViewBuilder handles them: label, parent, subcontext type, langcode, scope, tags, uid.

Sample items

Optional university samples are available if you want to try CCC before authoring your own items. They stay unpublished. Duplicate a sample, adapt it, and publish the copy — do not publish the originals unchanged.

  • Developers can apply the optional recipe listed on Configuration → AI → Context Control Center → Settings → Extensions.
  • Editors can copy or upload the same items from Sample context.

The copy is illustrative. Do not use it unchanged in production. Duplicate a sample, adapt it, and publish the copy.

Duplicating items

To duplicate an item, use Duplicate in the row operations of the context items listing. The item has no Duplicate tab. You can also go to /admin/config/ai/context/items/{id}/duplicate. You need permission to create items and to edit the original item.

The confirmation page shows "A new draft copy will be created." When you click Duplicate, the module saves the copy and opens the edit form of the copy. The copy has the field values and the translations of the original.

Duplicate always saves the copy as a draft. This applies to all users, also to users who may publish. It also applies when Publish by default is on. Duplicate saves the copy when you confirm, before you can change it. The copy is a draft, so you can change it before you publish it on its edit form.

  • You must be able to use the Create new draft transition. If you cannot, the form shows an error and does not save a copy.
  • Each translation of the copy is a draft.
  • You own the copy. The copy does not keep the publishing schedule or the revision log message of the original.
  • The copy has no token name, because token names are unique. See Token name.
  • A draft copy of a global item does not count toward the global item limit. The limit is checked when you publish the copy.

Managing items

The context items listing at /admin/config/ai/context/items shows all items the current user can view. Rows are grouped by status (published, then draft, then archived) and sorted alphabetically by label within each status. Other workflow states join the published or draft group based on whether the state is published. When subcontext is enabled, children stay immediately under their parent. The listing pages in groups of 100 top-level items so a child is not split onto the next page. The table caption is kept for screen readers and is not shown visually.

The toolbar above the table filters the listing in the browser; it does not reload the page or change the URL. Client-side search and filters hide rows on the current page; they do not change this order. It offers:

  • Search — matches the label, the purpose, every scope label on the row, and the status label. Case-insensitive. Each search word is matched separately, in any order. Put words in double quotes to match them as a phrase. Scope labels include any the Scopes column hides behind its +N pill, so a search can match a value that is not currently visible in that column. Typing archived or draft finds items in that state, and typing a use case or section name finds items scoped to it.
  • Status — defaults to Published, which remains available even when no listed row is published. Published includes every state that publishes its item, including custom workflow states, so a published state has no option of its own. The other options are the unpublished statuses on the listed rows, and they match those states exactly. Moderated items report their workflow state (for example Draft or Archived); items outside a workflow report Unpublished.
  • Token usage — filters by the tier shown on the Tokens badge: Low, Mid or High, using the same budget thresholds the badge uses. For a parent row showing a range, the tier is the high end, so the filter always agrees with the badge color. The badge counts the item's rendered block (its id, label and purpose header plus the indented guidance) against Max tokens for injection; when subcontext is enabled, a parent's figure already includes its subcontext items, which also have rows of their own.

Reset appears when a filter changes and restores Published, Token usage set to All, and an empty search. It returns keyboard focus to Search.

The three filters combine with AND logic. A matching child keeps its parent visible and a matching parent keeps its children visible, so the hierarchy stays readable. This also applies to Status: Published can show unpublished relatives of a published match, such as a draft or archived child. When nothing matches, the table shows a message and announces it. An empty Published view explains that no published items are on the current page and how to see other statuses by selecting All. Nonempty default loads do not announce a count.

The toolbar appears when browser filtering is ready. Without JavaScript, all items on the current page remain visible and the toolbar is hidden.

From the listing you can:

  • View, edit, or delete individual items
  • See the current moderation state (draft, published, archived)
  • See which subcontext children are conditional (type indicator on child rows)
  • When conditional subcontext AI is disabled, conditional child rows are visually de-emphasized in the listing with a link to re-enable the feature
  • Access revision history
  • Duplicate items