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
- Go to
/admin/config/ai/context/items - Click Add Context Item
- Fill in the fields described below
- Choose a state in Save as. New items default to Published, unless Publish by default is turned off under Settings → Context Items
- Save the item
Fields
Label, Description, Purpose, Content and Priority are required. Priority defaults to Medium. Context scope, Specific entities and Parent are optional.
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_typeis required when a parent is selected- If a parent item is deleted, child items remain as standalone items with
their
parentandsubcontext_typefields cleared
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.
Sidebar Details panel
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-iconpattern and SVGs bundled in this module.
Sidebar Nav panel
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.
- 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
+Npill, so a search can match a value that is not currently visible in that column. Typingarchivedordraftfinds 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,labelandpurposeheader 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