Debugging
The AI Context module includes optional debug logging to help troubleshoot consumer routing, context selection, rendering, scope matching, and context item token issues.
Enabling debug logging
- Navigate to
/admin/config/ai/context/settings/general - Expand the Debugging section
- Check the Enable debug logging checkbox
- Save the configuration
Viewing debug logs
Debug information is written to the standard Drupal log:
- Go to Reports > Recent log messages (
/admin/reports/dblog) - Filter by type: ai_context
Or using Drush:
ddev exec drush watchdog:show --type=ai_context
What gets logged
Consumer routing (AiContextPreGenerateResponseSubscriber)
When a generic chat request matches at least one consumer type, one debug line is written with the invocation status, consumer ID (if any), selected item IDs, and request tags. Agent and assistant requests are excluded. Unrouted tags write nothing.
Statuses match AiContextInvocationResult: pushed, no_items,
push_disabled, type_disabled, stale, declined, ambiguous.
AiContextPreGenerateResponseSubscriber: Consumer routing; status=STATUS; consumer=ID; items=[IDS]; tags=[TAGS].
declined with an ai_automator tag and no ai_automator:id:{id}
tag means the automator instance could not be identified. AI 1.4.12
and later 1.4 releases, and AI 1.5.0 and later, send that ID. A
widget click skips the other automators on the field when the
clicked automator is allowed to push. push_disabled means the
consumer matched but automatic push is off (the Automator
default until you save an override).
Usage rows are written only for pushed. Use this log, not the Usage
tab, to see why a click produced no context.
For an automator, no_items or push_disabled does not always mean
that the provider got no context. AI Automators send all calls for one
field through one provider instance. When an earlier call pushed
context, providers that send the system role of that instance, for
example OpenAI-based providers, can still send the block of the
earlier call. This occurs on all supported AI versions: AI 1.4.12 and
later 1.4 releases, and AI 1.5.2 and later. AI Automators must fix it,
in project/ai#3586900.
See the known limit in
Consumer configuration.
The summary does not include task text or rendered context.
Context selection (AiContextSelector)
- Scope index prefilter counts: candidate IDs vs. published IDs for Minimal without subscriptions; for Minimal with active subscriptions, per-route candidate counts (subscription, global, entity-item, exact-match) instead, since that path queries the index directly and never loads the full published-ID catalog
- Number of published items loaded across chunks and always-include count
- Item count after priority-group merge
- One final selection summary with the consumer ID, selected item IDs, truncated item IDs, and token usage
- Warning when items are truncated due to token limits
- Warning when
TEXT_RENDEREDtext exceeds configuredmax_tokens - Relevant prefilter counts (base, situational, and subscription candidate IDs vs. published IDs)
- Warning when a selection scans more than 50 published items without a prefilter (once per consumer per request)
That last warning is expected for Broad, which always walks the full published catalog to fill leftover budget. Minimal and Relevant prefilter via the scope index and only fall back to a full scan when prefiltering is not possible — a scope plugin that cannot expand its subscribed values or enumerate its situational matches from indexed values. It is not a failure. It logs once per consumer per request, even if debug logging is off.
If the warning keeps appearing for a consumer on a large catalog, Minimal is the recommended mode: it skips the situational-match pass entirely, so it expands the fewest candidate IDs and loads the fewest entities. See Context selection for the trade-off.
The final debug summary uses this format:
AiContextSelector: Selection summary; consumer=CONSUMER; selected=[IDS]; truncated=[IDS]; tokens=USED/MAX.
It is emitted once per completed selection only when debug logging is enabled. The summary does not include task text, context content, provider responses, or IDs rejected by access checks.
See Selector pipeline events for when those overrides are allowed.
Scope scoring and hard context filtering run inside the selector via
AiContextScopeResolver but do not emit separate debug messages.
Context rendering (AiContextRenderer)
- Items skipped when the token budget is exhausted before or during rendering
Token estimation (AiContextTokenEstimator)
These warnings are logged also when debug logging is off. They never contain Context Item content.
- "Could not load the tokenizer vocabulary for model @model (@class: @message). AI Context uses an approximate token count until the vocabulary loads." The tokenizer could not download or read its vocabulary file. Logged once when a load fails. For the next 10 minutes, requests use the approximate count and do not try again. Vocabulary downloads use a socket timeout of 5 seconds. When the load raised a PHP warning, for example "fopen(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0", the message also has "PHP warning:" and the first warning. The PHP warnings themselves are not shown or logged.
- "Loading the tokenizer vocabulary for model @model raised a PHP warning:
@warning. AI Context uses the cl100k_base vocabulary for model @model for
the next @minutes minutes, then tries the vocabulary of the model again."
The vocabulary of the model (for example
o200k_baseforgpt-4omodels) could not be loaded, and the AI tokenizer loadedcl100k_baseinstead. For the next 10 minutes, counts and context rendering usecl100k_baseand do not try the download again.drush crends this at once. - "Loading the tokenizer vocabulary for model @model raised a PHP warning:
@warning. The vocabulary loaded." The load worked after a PHP warning,
but no new fallback is remembered: the model is
gpt-4, or a fallback is already remembered and itscl100k_baseload raised the warning. Logged once for each request. The vocabulary is then in memory, so later counts and context rendering in the request do not try the download again. - "The tokenizer for model @model could not encode a text (@class). AI Context uses an approximate token count for that text." The vocabulary loaded, but one text could not be encoded. Logged once for each request. This warning leaves out the exception message, because it can quote the text.
- "AI Context did not recalculate all stored token counts, because the
tokenizer vocabulary did not load. Cron recalculates them after the
vocabulary loads." A Drush recount (
config:set,config:import) or update10023stopped and queued a full recount for cron.
For the causes and the fixes, see When the tokenizer vocabulary cannot be loaded.
Subcontext resolution (AiContextSubcontextResolver)
Conditional selection fails closed: when a decision cannot be completed, conditional children are excluded while required children remain selected. The resolver writes one privacy-safe warning with the parent Context Item ID, affected child count, and one of these reason categories:
missing_provider: no provider/model is configured, or the configured provider plugin is unavailabledecision_cap_exhausted: the conditional parent limit for this context resolution call was reachedinvalid_response: the provider response is not a JSON list of scalar child IDs. Conditional subcontext asks the model for a fenced JSON code block wrapping a JSON array of child IDs (or an empty array if none), with no text before or after the fence. A bare array such as["123"]does not decode on AI core 1.5.x, so those replies are logged with this reason and every conditional child is dropped. A fenced non-array such as"none"is also this reason, notprovider_exception.unsupported_provider: the provider does not support chatprovider_exception: provider creation or execution failed
The warning uses this format:
AiContextSubcontextResolver: Conditional children excluded; parent=PARENT; affected=COUNT; reason=REASON.
Warnings never contain Context Item content, task text, provider-response content, or exception messages. Use the parent ID to inspect configuration, then verify the provider/model, conditional parent limit, and provider logs.
Context item tokens (AiContextItemTokenResolver)
When debug logging is on, CCC logs a message each time a
[ai_context:item:TOKEN_NAME] token gives an empty string. See Token
name.
A warning means that the text that uses the token has an error:
The token TOKEN is not defined. A token name starts with a lowercase letter and contains only lowercase letters, numbers and underscores.
The token name in the text is not a valid token name, for example
[ai_context:item:Brand_Voice].
The token TOKEN is not defined. No context item has the token name NAME.
No item has this token name. The name can have a spelling error, or an administrator changed or removed the token name, or deleted the item.
A debug message means that the token name exists, but the token gives no content for this request:
The token TOKEN gave an empty value. The context item with this token name is not published in this language, or the current user cannot view it.
Check the moderation state of the item and of its translations. Check that the user has View AI Context Items in CCC or Use Published AI Context in AI Features.
These messages do not contain item content. The check if a token name exists ignores access, because debug logging is for administrators.
Token results can be cached. A message is logged only when the token value
is built, not each time the cached text is used. To log the message again,
clear the cache, for example with drush cr.
Tool consumer_id inheritance (AiContextAgentToolSubscriber)
When a context tool opts in with
AiContextInheritsConsumerIdInterface and a non-empty
non-canonical consumer_id is replaced with
agent:{running agent}, one debug line is written with the
discarded value and the replacement. Omitted, empty, and
canonical values do not log. This line is always written at
debug. It is not gated by Enable debug logging. It does
not include task text or item content.
Performance considerations
Debug logging generates significant log entries and may affect performance. Only enable it when actively troubleshooting issues. Disable it when you finish debugging.
Test with the AI Agents Debugger and the Tools Explorer
Use the debugger to inspect the system prompt sent to the model. Use the Tools Explorer to run one CCC tool directly and inspect its output. These checks help distinguish selection and rendering problems from agent or model responses.
Modules and permissions
| Tool | Module | Path |
|---|---|---|
| AI Agents Debugger | ai_agents_debugger |
/admin/config/ai/agents/debug |
| Tools Explorer | ai_api_explorer |
/admin/config/ai/explorers/tools_explorer |
The AI module includes ai_api_explorer; enable it to use the Tools
Explorer. Configure a chat provider too: without an available chat
provider, the Tools Explorer page returns access denied, even though a
direct CCC tool call does not ask a model to choose a tool.
ai_agents_debugger is a separate project. For the beta release tested
here, a site with "minimum-stability": "stable" needs an explicit
stability flag:
composer require 'drupal/ai_agents_debugger:^1.0@beta'
Enable ai_agents_debugger after installing it. A site that already
allows development releases can use
composer require drupal/ai_agents_debugger.
Grant the account running these checks the appropriate permissions:
- Debug AI Agents (
debug ai agents) to open the debugger. - Permit access to using the AI API Explorer (
access ai prompt) to open the Tools Explorer. - Administer AI Context (
administer ai context) to configure consumers and general settings. - Use Published AI Context in AI Features (
access published ai context) or View AI Context Items in CCC (view ai context items) to receive published context. Administer AI Context also grants this access.
Without a runtime CCC permission, push adds no CCC block and the context
tools return an insufficient-permissions message. Editing an agent's
system prompt inside the debugger also needs Administer AI Agent
(administer ai_agent). When the agent edit form uses Modeler API,
configuring tools on that form requires Edit AI Agents
(modeler api edit ai_agents_agent). These administration and debugging
permissions are restricted; grant them only to trusted accounts.
The monitor labels below apply to AI Agents Debugger 1.0.0-beta2. CCC
requires AI ~1.4.12 || ^1.5.2 || ^2. Agent administration URLs can
vary by AI Agents version. Use the AI administration menu to find the
agent listing if a URL below is unavailable.
Read the system prompt in the debugger
- Go to
/admin/config/ai/context/settings/consumers. - Choose Debug agent in the operations of the agent. Alternatively,
open
/admin/config/ai/agents/debugand select the agent in Agent. - Enter the task in the Content field of the last row whose Role
is
user. The chat history rows carry no heading of their own, so look for the Role and Content pairs. CCC uses the latest user message as the selection task, rather than the agent's system prompt. Use a task relevant to the item you want to test. - Click Run Agent.
- Open AI Input in the monitor panel.
- Read its System Prompt section.
The monitor merges related steps into one entry. A run can show Agent Started, Loop Count, AI Input, AI Output, Agent Finished, and Final Answer. Each agent loop has its own AI Input entry and system prompt. Tool Used entries appear when tools run; they are not required for a run that only uses CCC push.
Find the CCC push block
CCC appends its push block to the system prompt between two dashed lines:
The following site-specific context applies to this task. Use it strictly when relevant; do not override user intent.
-----------------------------------------------
- id: 12
label: Brand voice
purpose: Tone rules for public copy
guidance:
Write in plain language. Avoid jargon.
- id: 34
label: Product naming
guidance:
Always write the product name in full.
-----------------------------------------------
The line above the first dashed line is the Context prefix from
/admin/config/ai/context/settings/general. The example shows the default
wording, used when that field is empty.
Every item starts with - id: followed by its Context Item ID.
Match the complete line, for example - id: 12, to confirm delivery;
a search for that text alone also matches - id: 120. label and
purpose follow when set. guidance: contains the rendered content,
indented by four spaces.
AI Agents can also add CCC tool output under Default information
tools. Load and Get Relevant output use - id: entries; List output
uses lines such as - [12] Brand voice. Look for the Context prefix
to distinguish the CCC push block from tool output added by AI Agents.
See Test the tool path instead of push.
The CCC push block is absent when no context is delivered, when the account lacks runtime CCC permission, or when Push context automatically is off. With Loop-aware context injection on, the block is also absent from the rebuilt system prompt after the first loop. Check What gets logged for selection and rendering evidence.
CCC does not replace Drupal tokens in item text. It inserts spaces to
prevent later token replacement: [site:name] appears as [site : name]
in the push block and tool output.
Test page and entity scopes
The debugger's route has no content entity. Use Advanced > Spoof Tokens to supply the page or entity for a scope test:
[entity_type]=node
[entity_id]=123
[path]=/node/123
Replace 123 with an entity your account can view. Follow
Test page and entity context
for the complete walkthrough and precedence rules.
CCC applies these hints during push. With push off, use the tool's
entity_type and entity_id parameters to test entity scopes. If push
has already applied the hints, a tool that the model calls later in the
same run can also see that request context.
On the first loop, AI Agents runs default information tools before CCC
applies the hints. On later loops in the same request, these tools can see
hints already applied by push. To test a specific entity with List or Get
Relevant, pass entity_type and entity_id in the tool's parameters.
Test the tool path instead of push
- Open the AI Agents administration listing and edit the agent. On
AI Agents 1.3.2 and later, the edit URL is
/admin/config/ai/tools-automation/agents/{agent_id}/edit/form. - Add a CCC tool in Tools, or in Advanced settings > Default information tools as described below.
- Go to
/admin/config/ai/context/settings/consumers. - Choose Configure context for the agent.
- Uncheck Push context automatically.
- Save the consumer settings.
- Set the consumers page's Automatic push filter to All or Off. It initially shows On, which hides the consumer after push is disabled.
- Choose Debug agent for the consumer and run the agent again.
The two tool settings work differently:
- Default information tools: AI Agents runs the tool before calling the model and adds its output to the system prompt, under "The following is information that is important as context:". The monitor shows Tool Used before AI Input. The prompt can still contain context from this tool when CCC push is off.
- Tools: the model decides whether to call the tool. A selected tool call appears in AI Output, followed by Tool Used with its output. Enabling a tool does not guarantee a call.
For a default information tool that lists the available context items, enter this YAML in Default information tools:
- tool: ai_context:list_ai_context_items
label: Available context items
parameters: {}
When using Get Relevant, supply its required task parameter. When
using Load, supply context_item_ids. Missing required parameters can
stop the run with an error.
List and Get Relevant inherit the running agent's consumer, including its scope subscriptions and inclusion overrides. Load does not inherit the consumer. To test entity scopes with push off, provide explicit entity parameters to List or Get Relevant.
Run one tool in the Tools Explorer
The Tools Explorer runs one function call with the parameters you enter. It does not run an agent or ask a model to choose the tool.
- Go to
/admin/config/ai/explorers/tools_explorer. - Select the tool.
- Fill in its parameters.
- Click Run Function.
| Tool | Plugin ID | Required parameters |
|---|---|---|
| List | ai_context:list_ai_context_items |
None |
| Load | ai_context:load_ai_context_items |
context_item_ids |
| Get Relevant | ai_context:get_relevant_ai_context_items |
task |
The explorer also lists Load AI Context Item By ID (deprecated),
the alias ai_context:load_ai_context_item_by_id. Use Load AI Context
Items for new tests.
| Optional parameter | List | Load | Get Relevant |
|---|---|---|---|
consumer_id, scope_subscriptions |
Yes | No | Yes |
entity_type, entity_id |
Yes | No | Yes |
always_include, never_include, selection_mode |
No | No | Yes |
max_tokens |
No | Yes | Yes |
include_subcontext |
No | Yes | No |
task |
No | Yes | Required |
Lists such as context_item_ids use text areas with one value per row.
selection_mode uses a select list, max_tokens uses a text field, and
Load's include_subcontext uses a checkbox. The explorer currently
omits unchecked checkbox values, so unchecking include_subcontext
does not override Load's default of including subcontext. Use a direct
API call to test an explicit FALSE value. That default applies only
where subcontext is enabled for the site: Load includes subcontext when
the site setting is on and the parameter is not FALSE, so with the
setting off the parameter changes nothing.
List applies scope filters. Without parameters, it returns only items
that match without a supplied entity or page, such as Global items.
Use entity_type and entity_id to test entity scopes. Its output is a
compact listing, for example - [12] Brand voice.
Load returns requested published items the account can view, without
entity parameters. It does not return unpublished items, even when the
account can view them elsewhere. Get Relevant uses its task to run
the selection pipeline; use it to check relevance and token budgets.
See Function calls for parameter details.
The explorer does not inherit an agent's consumer. List and Get
Relevant use site defaults unless you enter a consumer_id, such as
agent:<agent_id>.
Tips
- The debugger calls the configured AI provider. This can cost tokens and sends the conversation and full system prompt, including CCC context, to that provider. Use test content.
- Enter test text containing square brackets with Drush or the API. The Content field uses MDXEditor, which can escape brackets as Markdown. Drush and API writes avoid that editor transformation.
- Enable debug logging to inspect selected and truncated IDs, token usage, and prefilter counts. Scope filtering does not log each exclusion, so the log cannot explain every missing item. Check the rendered prompt or tool output to confirm which content arrived.