AiAgentEntityWrapper::$aiConfiguration is not initialized
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3584132. -->
Reported by: [joaopauloc.dev](https://www.drupal.org/user/3720064)
Related to !256
>>>
<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>Drupal\ai_agents\PluginBase\AiAgentEntityWrapper declares the property $aiConfiguration without an initial value:</p>
<pre>/**<br> * The AI configuration.<br> *<br> * @var array<br> */<br>protected $aiConfiguration;</pre><p>For agents that come from the temp store via fromArray() this is harmless, because fromArray() defaults the value to an empty array (line 1426: $this->aiConfiguration = $data['ai_configuration'] ?? [];).<br>
But for agents created directly via createInstance() — which is exactly what ai_assistant_api's AgentRunner::runAsAgent() does on every fresh turn — the property stays NULL until something explicitly calls setAiConfiguration().</p>
<p>When progress tracking is enabled on such a fresh agent (e.g. by calling setProgressThreadId() before determineSolvability()), the AgentRequestEvent is dispatched and AgentStatusSubscriber::onAgentRequestExecution() runs.<br>
That subscriber constructs an AiProviderRequest value object and passes $event->getAgent()->getAiConfiguration() directly into the array $config parameter of the constructor. Because the property is still NULL, PHP throws:</p>
<p>TypeError: Drupal\ai_agents\Service\AgentStatus\UpdateItems\AiProviderRequest::__construct():<br>
Argument #9 ($config) must be of type array, null given,<br>
called in .../src/EventSubscriber/AgentStatusSubscriber.php on line 178<br>
The site crashes with a 500 the moment the agent runs.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>1. Have an AI Assistant configured with an AI Agent (so runAsAgent() is the execution path).<br>
2. Make sure setProgressThreadId() is called on the agent before determineSolvability(). (See sibling issue in the ai queue: "AgentRunner::runAsAgent() does not propagate the thread id to the agent".)<br>
3. Trigger the assistant.<br>
Expected: Agent runs and dispatches AgentRequestEvent/AgentFinishedExecutionEvent normally. Actual: TypeError on AiProviderRequest::__construct(), full WSOD.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Two complementary one-line fixes:</p>
<p>1. Initialize the property to an empty array so a freshly-created agent always exposes a valid array from getAiConfiguration().<br>
2.. Defensively normalize at the call site in AgentStatusSubscriber so any future code path that mutates aiConfiguration to NULL does not crash status tracking.</p>
<p>Fix 1 — initialize the property<br>
src/PluginBase/AiAgentEntityWrapper.php line 67:</p>
<pre>/**<br> * The AI configuration.<br> *<br> * @var array<br> */<br>protected $aiConfiguration = [];</pre><p>Fix 2 — normalize at the call site<br>
src/EventSubscriber/AgentStatusSubscriber.php around line 187:</p>
<pre>if ($this->checkLogEventType($event, AiAgentStatusItemTypes::Request)) {<br> $this->statusStorage->storeStatusUpdateItem($event->getThreadId(), new AiProviderRequest(<br> time: $combined_ms,<br> agent_id: $event->getAgentId(),<br> agent_name: $event->getAgent()->getAiAgentEntity()->label(),<br> agent_runner_id: $event->getAgentRunnerId(),<br> loop_count: $event->getLoopCount(),<br> request_data: $event->getChatInput()->toArray(),<br> provider_name: $event->getAgent()->getAiProvider()->getPluginId(),<br> model_name: $event->getAgent()->getModelName(),<br> config: $event->getAgent()->getAiConfiguration() ?? [],<br> calling_agent_id: $event->getCallerId(),<br> ));<br>}</pre><h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>1. Add a unit/kernel test that creates an agent via createInstance(), enables progress tracking, dispatches AgentRequestEvent, and asserts no TypeError is thrown.</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>[x] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[x] 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>
> Related issue: [Issue #3582030](https://www.drupal.org/node/3582030)
issue