# FlowDrop AI Context

Provides FlowDrop node processors that inject
[AI Context Items](https://www.drupal.org/project/ai_context) into workflows as
formatted, AI-ready text blocks. Includes two processors covering static
single-item injection and dynamic multi-item selection.

For a full description of the module, visit the
[project page](https://www.drupal.org/project/flowdrop_ai_context).

Submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/flowdrop_ai_context).


## Table of contents

- Requirements
- Installation
- Configuration
- Node Processors
- Services
- Architecture
- Maintainers


## Requirements

This module requires the following modules:

- [FlowDrop](https://www.drupal.org/project/flowdrop) (^1.0)
- [Context Control Center (CCC)](https://www.drupal.org/project/ai_context) (^1.0)

Drupal 11 and PHP 8.3 or higher are required.


## Installation

Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).


## Configuration

AI Context Items are managed through the AI Context module at
`/admin/config/ai/ai-context`. Node types are registered automatically and
appear in the FlowDrop palette under the `data` category at
`/admin/flowdrop/config/node-types`.


## Node Processors

Each processor is a `FlowDropNodeProcessor` plugin that integrates with the
Drupal AI Context module. Both produce `rendered_text` in the same structured
block format that `BuildSystemPromptEvent` uses natively — connect
`rendered_text` to `additional_context` on an AI Agent Executor node.

| Processor | Plugin ID | Description |
|-----------|-----------|-------------|
| AI Context Injector | `ai_context_injector` | Pin one specific AI Context Item at design time |
| AI Context Selector | `ai_context_dynamic_selector` | Auto-select relevant AI Context Items at runtime from a task |

The injector renders a single configured item via `AiContextRenderer`. The
dynamic selector uses `AiContextSelector` to pick relevant items based on the
incoming task, optionally scoped to an AI agent's context subscriptions. The
selector automatically resolves and interleaves subcontext children.


## Services

### AiContextRenderer (`ai_context.renderer`)

Provided by the AI Context module. Produces the structured block format used by
the `BuildSystemPromptEvent` subscriber, including `id`, `label`, `purpose`,
and `guidance` fields.

### AiContextSelector (`ai_context.selector`)

Provided by the AI Context module. Selects relevant context items for a task,
resolving subcontext hierarchy and respecting token budgets.

### AiContextRequestFactory (`ai_context.request_factory`)

Provided by the AI Context module. Builds `AiContextRequest` objects from node
parameters, merging an agent's `ai_context.agents` configuration (scope
subscriptions, always/never includes) when an `agent_id` is supplied.


## Architecture

- **Rendered output**: Both processors emit the same structured block format
  used internally by AI Context, ensuring downstream agents receive context in
  a predictable, model-friendly shape.
- **Subcontext handling**: The injector renders only the configured item;
  children are not auto-included. The dynamic selector resolves subcontext —
  when a parent item is selected, its children are interleaved immediately
  after the parent in `rendered_text`.
- **Agent-aware selection**: When `agent_id` is provided to the dynamic
  selector, the agent's context configuration is merged with the node
  parameters, applying the same rules the agent uses for automatic injection
  without re-executing the agent. When empty, selection mode falls back to
  `match_all` so all published candidates are considered.
- **Field component**: The Svelte widget `FormFieldContextSelector` is
  registered on `flowdrop:editor:init` against `format === 'ai_context_item_selector'`.


## Maintainers

- David Galeano - [gxleano](https://www.drupal.org/u/gxleano)
