Context-aware prompt generation (Drupal content, internal links, styles)
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3554041. -->
Reported by: [devator](https://www.drupal.org/user/3841723)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The AI module provides a strong foundation for integrating AI into Drupal (text generation, automations, assistants, etc.).<br>
However, current AI-generated text within Drupal lacks awareness of the site’s internal context.<br>
Generated outputs do not take into account node metadata, internal linking structures, editorial styles, or SEO information.<br>
As a result, the produced content often lacks relevance, coherence, and optimization in relation to the site’s actual data and structure. </p>
<p>Adding a unified <strong>Drupal context</strong> layer would enable more coherent, SEO-friendly, and site-aware AI text generation.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Not applicable – this is a feature request. </p>
<p>Observed with modules such as:<br>
- ai_automators<br>
- ai_agents<br>
- seo_ai </p>
<p>Regardless of the provider (OpenAI, Mistral, Anthropic, etc.), current prompts are isolated from Drupal’s site context.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Introduce a standardized <strong>Drupal Context Service</strong> to make Drupal-specific information available to all AI operations. </p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>- Define and implement a Drupal Context Service within ai_core or ai_utils.<br>
- Add documentation and examples showing how to alter prompts with contextual data.<br>
- Provide optional MCP integration for exposing Drupal context to external tools.<br>
- Extend ai_agents with contextual agents (InternalLinkAgent, SeoAgent).<br>
- Update developer guide and include integration examples for ai_automators and seo_ai.<br>
- Create automated tests verifying prompt enrichment and performance impact.</p>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<p><strong>User interface:</strong><br>
No visual or UX changes expected; the functionality operates at the service and hook level. </p>
<p><strong>API changes:</strong><br>
- New service for site context data (ai.drupal_context).<br>
- Optional plugin for MCP resource exposure. </p>
<p><strong>Data model:</strong><br>
- Optional new index for internal link relationships (if implemented). </p>
<p><strong>Performance considerations:</strong><br>
- Context data can be cached using cache.ai to prevent redundant computations. </p>
<p><strong>Expected outcome:</strong><br>
A consistent, context-aware text generation layer across the AI module ecosystem, improving coherence, SEO quality, and relevance of AI outputs.</p>
issue