Array to string conversion in Token::doReplace() when a dynamical token value is an array (applyTokens)
### Problem On every AI Agent run, a PHP warning is logged (and shown as a status message inside the Drupal Canvas AI editor): ``` Warning: Array to string conversion in Drupal\Core\Utility\Token->doReplace() (line 283 of core/lib/Drupal/Core/Utility/Token.php). ``` ### Backtrace (abridged) ``` Token.php(283): str_replace() Token.php(214): Drupal\Core\Utility\Token->doReplace() token_or/src/Token.php(27): ...->replacePlain() eca/.../TokenDecoratorTrait.php(444): ... ai_agents/src/PluginBase/AiAgentEntityWrapper.php(1323): ...->replacePlain() ai_agents/src/PluginBase/AiAgentEntityWrapper.php(983): ...->applyTokens() ...->getSystemPrompt() / ->determineSolvability() ``` ### Cause `AiAgentEntityWrapper::applyTokens()` merges the dynamical `$this->tokens` into the data passed to `Token::replacePlain()`: ```php $tokens = array_merge($tokens, $this->tokens); return $this->token->replacePlain($prompt, $tokens); ``` When a dynamical token value is an **array** (e.g. a token holding a list, set via `setTokenContexts()` or the `BuildSystemPromptEvent`), it reaches `str_replace()` in `Token::doReplace()` as a replacement value and triggers the "Array to string conversion" warning. Likely surfaced more since 1.1.x added agent/info-tool tokens. ### Steps to reproduce 1. Install AI + AI Agents + a provider; enable Drupal Canvas + Canvas AI. 2. Run any agent (e.g. type a prompt in the Canvas AI panel). 3. Observe the warning on every run (status message / dblog). ### Proposed fix In `applyTokens()`, coerce array token values to a string before `replacePlain()` (scalars only), so no array reaches `str_replace()`. MR attached. ### Environment ai_agents 1.3.x-dev, Drupal 11.3.
issue