Function Calls
The AI Context module provides three AI function call plugins grouped under
Context Tools (context_tools), registered via the
Drupal\ai_context\Plugin\AiFunctionGroup\ContextTools plugin. This group
label appears in AI module tool pickers alongside other function groups.
Plugins in this group:
ai_context:list_ai_context_itemsai_context:load_ai_context_item_by_idai_context:get_relevant_ai_context_items
Agents can invoke them as tools for context discovery, loading, and relevance-based selection.
All three plugins require the current user to have at least one of:
access published ai contextview ai context itemsadminister ai context
Tool workflow
For agent-driven discovery, the typical flow is:
- List available items with
ai_context:list_ai_context_items - Load chosen items with
ai_context:load_ai_context_item_by_id
Alternatively, Get relevant (ai_context:get_relevant_ai_context_items)
runs the full selection pipeline in one step (scope scoring, subcontext
resolution, and rendering).
GetRelevantAiContextItems
Plugin ID: ai_context:get_relevant_ai_context_items
Function name: ai_context_get_relevant_ai_context_items
Class: Drupal\ai_context\Plugin\AiFunctionCall\GetRelevantAiContextItems
Selects and returns relevant context for a task using the same pipeline as
automatic system-prompt injection. Delegates to
AiContextSelectorInterface::select() via ai_context.request_factory.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task |
string |
Yes | Current task or user prompt to select context for |
scope_subscriptions |
map |
No | Scope plugin IDs mapped to subscribed value lists (e.g. {"language":["en"],"tag":["5"]}) |
always_include |
list |
No | Context item IDs to always include |
never_include |
list |
No | Context item IDs to never include |
agent_id |
string |
No | Agent ID whose saved context configuration is merged into the request |
selection_mode |
string |
No | minimal or match_all. Controls behavior when scope_subscriptions is empty. Defaults to minimal when omitted. Agent-backed calls inherit the agent's saved selection mode unless explicitly overridden |
entity_type |
string |
No | Entity type for target matching (e.g. node) |
entity_id |
integer |
No | Entity ID for target matching (used with entity_type) |
max_items |
integer |
No | Override for maximum number of items to return (1–20) |
max_tokens |
integer |
No | Override for max tokens in rendered text |
Behavior
Builds an AiContextRequest from the parameters and returns the rendered
context text. If no items match, the output is
"No relevant context items found."
When agent_id is provided, the agent's saved scope subscriptions,
always/never include lists, and limits are merged with explicit parameters
(same-named keys from explicit input override agent values).
Example output
## Brand Guidelines
Use our primary brand color (#1a73e8) for all headings...
## Product Categories
Our catalog is organized into three main categories...
ListAiContextItems
Plugin ID: ai_context:list_ai_context_items
Function name: ai_context_list_ai_context_items
Class: Drupal\ai_context\Plugin\AiFunctionCall\ListAiContextItems
Lists published, accessible context items with ID, label, and purpose.
Intended as a lightweight discovery tool so agents can choose what to load
via LoadAiContextItemById. Does not return full item content.
Results are capped at 200 items (sorted by ID ascending).
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
scope_subscriptions |
map |
No | Filter by scope subscriptions |
agent_id |
string |
No | Merge an agent's saved context configuration into filters |
entity_type |
string |
No | Entity type for target matching |
entity_id |
integer |
No | Entity ID for target matching |
Behavior
Loads published items the current user can view, then applies optional
filters via AiContextScopeResolver (hard context filters, scope
subscriptions, entity targets, and agent never/always include lists).
Example output
Available context items (3):
- [5] Brand Guidelines — Tone, voice, and visual identity rules
- [12] Product Categories — Catalog organization overview
- [3] Compliance Notes — Medical device regulatory context
LoadAiContextItemById
Plugin ID: ai_context:load_ai_context_item_by_id
Function name: ai_context_load_ai_context_item_by_id
Class: Drupal\ai_context\Plugin\AiFunctionCall\LoadAiContextItemById
Loads one or more context items by ID and returns fully rendered content. Use after listing items. Requested IDs appear in tool arguments for observability.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
context_item_ids |
list |
Yes | One or more numeric context item IDs |
task |
string |
No | Task description for conditional subcontext resolution |
max_tokens |
integer |
No | Max tokens override for rendered text |
include_subcontext |
boolean |
No | Include child items of loaded parents (default: true) |
Behavior
Loads published, accessible items by ID, translates them to the current
content language, optionally resolves subcontext children via
AiContextSubcontextResolver, and renders via AiContextRenderer within
the token limit.
If subcontext is disabled in module settings, child items are not included
regardless of include_subcontext. See Subcontext.
Example output
## Brand Guidelines
Use our primary brand color (#1a73e8) for all headings...