Pass DeepChat context to the service that runs assistant as agent
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3571982. -->
Reported by: [a.dmitriiev](https://www.drupal.org/user/3235287)
Related to !1167
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Short Description: </strong>[One-line issue summary for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When using DeepChat bot with every request to API endpoint the context is passed. By default it is the current_route only, but it could be more things. In case of assistant processor this context is processed and used, but if assistant is using an agent, this context is just lost.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Please provide information like AI modules enabled, which AI provider, browser, etc.<br>
1. Install ai_chatbot (ai_assistant_api a dependency and will be installed automatically) module<br>
2. Install ai_agents module.<br>
3. Create an assistant (corresponding agent will be created automatically).<br>
4. Place a DeepChat block using the above created assistant.<br>
5. When using the chatbot observe that `/api/deepchat` endpoint payload has context property.<br>
6. Ask chatbot what is the current route, it will not answer, as this is not passed to the agent.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Include in AI Assistant API <code>runAsAgent</code> method the context from deepchat as optional parameter.<br>
Fire an event inside that method and pass the parameter to it.<br>
Other modules when reacting on the event can do something with that parameter, for example convert it into agent tokens or something else.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Adjust the code so that the context from Deepchat is passed to corresponding agent.</p>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[ ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
issue