Error: Call to a member function newInstance() with ActionPluginDeriver

Created on 20 May 2025, about 1 month ago

Problem/Motivation

Regarding #3525531 ๐Ÿ› Add AI Agent is not working Active , it is possible to get the following error...

Error: Call to a member function newInstance() on null in Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType() (line 183 of ai/src/Plugin/AiFunctionCall/Derivative/ActionPluginDeriver.php).

Steps to reproduce

1. Install latest version of Drupal AI Agents module - 1.1.0-beta2
2. Go to AI Agents Settings โ†’ page
3. Click on + Add AI Agent โ†’ button

Proposed resolution

Add a fallback for the context definitions so that we don't run into that PHP error.

๐Ÿ› Bug report
Status

Active

Version

1.1

Component

AI Core module

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada RobLoach Earth

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @RobLoach
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada RobLoach Earth

    MR over at https://git.drupalcode.org/project/ai/-/merge_requests/624

    May not be the best solution around it though. Perhaps we have it return the same `$type` instead of an empty string?

  • Pipeline finished with Success
    about 1 month ago
    Total: 388s
    #501964
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany marcus_johansson

    I have tried to replicate this with Drupal10.3 and Drupal 10.4 without success - any other modules that might be installed that installs some extra action plugins? I tried ECA.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany marcus_johansson

    Adding the module list here, for anyone also trying to repliace it - all 1.1.x and Drupal 10.4:

    • Drupal AI
    • AI Search
    • Key
    • Search API
    • Open AI Provider
    • Milvus VDB Provider
    • AI Assistant API
    • AI Agents
    • AI Chatbot
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Ishani Patel

    Hello,
    I've also tried with D10.4 and 1.1.x of AI and sub modules, but no luck.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    Testing in a clean installation with Drupal 10.4.7 and 1.1.x AI stack and everything works fine.

    Seems like some module from the other installation is interfering on this.

    Closing the issue.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States j-barnes

    We are currently experiencing the same issue on 10.4.7 with ai / ai_agent on latest dev release. It looks like it's caused by the node_unpublish_by_keyword_action and returned no attributes. Adding the above seems to have cured our problem.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada RobLoach Earth

    Confirmed it's something with the action module. Try this...

    drush pm:install action
    drush cr
    

    Visit /admin/structure/ai-agent/add

    You get the white screen:

    The website encountered an unexpected error. Try again later.

    Error: Call to a member function newInstance() on null in Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType() (line 183 of modules/contrib/ai/src/Plugin/AiFunctionCall/Derivative/ActionPluginDeriver.php).

  • ๐Ÿ‡ฒ๐Ÿ‡ฆMorocco lakhal

    I got the same error when I updated to the last versions of AI modules and applied the database update:

    Error : Call to a member function newInstance() on null dans Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType() (C:\xampp\htdocs\onedd\modules\contrib\ai\src\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver.php ligne 183)
    #0 C:\xampp\htdocs\onedd\modules\contrib\ai\src\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver.php(162): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType('sequence')
    #1 C:\xampp\htdocs\onedd\modules\contrib\ai\src\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver.php(78): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->getContextDefinitions(Object(Drupal\action\Plugin\Action\UnpublishByKeywordComment))
    #2 C:\xampp\htdocs\onedd\core\lib\Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator.php(101): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->getDerivativeDefinitions(Array)
    #3 C:\xampp\htdocs\onedd\core\lib\Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives(Array)
    #4 C:\xampp\htdocs\onedd\core\lib\Drupal\Core\Plugin\DefaultPluginManager.php(337): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()
    #5 C:\xampp\htdocs\onedd\modules\contrib\ai\src\Service\FunctionCalling\FunctionCallPluginManager.php(33): Drupal\Core\Plugin\DefaultPluginManager->findDefinitions()
    #6 C:\xampp\htdocs\onedd\core\lib\Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait.php(22): Drupal\ai\Service\FunctionCalling\FunctionCallPluginManager->getDefinitions()
    #7 C:\xampp\htdocs\onedd\modules\contrib\ai_agents\ai_agents.install(142): Drupal\Core\Plugin\DefaultPluginManager->getDefinition('ai_agent:get_co...', false)
    #8 C:\xampp\htdocs\onedd\core\includes\update.inc(178): ai_agents_update_10305(Array)
    #9 C:\xampp\htdocs\onedd\core\includes\batch.inc(297): update_do_one('ai_agents', 10305, Array, Array)
    #10 C:\xampp\htdocs\onedd\core\includes\batch.inc(139): _batch_process()
    #11 C:\xampp\htdocs\onedd\core\includes\batch.inc(95): _batch_do()
    #12 C:\xampp\htdocs\onedd\core\modules\system\src\Controller\DbUpdateController.php(195): _batch_page(Object(Symfony\Component\HttpFoundation\Request))
    #13 [internal function]: Drupal\system\Controller\DbUpdateController->handle('start', Object(Symfony\Component\HttpFoundation\Request))
    #14 C:\xampp\htdocs\onedd\core\lib\Drupal\Core\Update\UpdateKernel.php(115): call_user_func_array(Array, Array)
    #15 C:\xampp\htdocs\onedd\core\lib\Drupal\Core\Update\UpdateKernel.php(76): Drupal\Core\Update\UpdateKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request))
    #16 C:\xampp\htdocs\onedd\update.php(27): Drupal\Core\Update\UpdateKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #17 {main} 
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States keiserjb

    Thanks for the tip about the action module. If I turn that off the error goes away. But the patch works for me too.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia norbert-goco Subotica

    The ActionPluginDeriver class is responsible for collecting Action Plugins from contributed modules.
    If you debug the getContextDefinitions() function, you can see which configuration contains a mapping whose type cannot be resolved.

    In my case, it was the configuration of the domain_access module:

    Configuration for the add domain(s) to users action (action.configuration.domain_access_add_editor_action)

    This configuration contains a sequence within a mapping, meaning it can hold multiple values.

    Therefore, in such mappings, the inner type of the sequence should be considered.

    Iโ€™m attaching a patch that fixes this issue in my case โ€” it might help others as well. If not, then further investigation is needed to identify additional cases that should be handled.

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland merilainen

    I get this error after installing Drupal AI 1.1.0 and simply going to Chat explorer /admin/config/ai/explorers/chat_generator

    Error: Call to a member function newInstance() on null in Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType() (line 183 of /var/www/html/web/modules/contrib/ai/src/Plugin/AiFunctionCall/Derivative/ActionPluginDeriver.php).

    Here is the backtrace I get in Drupal logs:

    #0 /var/www/html/web/modules/contrib/ai/src/Plugin/AiFunctionCall/Derivative/ActionPluginDeriver.php(162): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->resolveRootDataType()
    #1 /var/www/html/web/modules/contrib/ai/src/Plugin/AiFunctionCall/Derivative/ActionPluginDeriver.php(78): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->getContextDefinitions()
    #2 /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(101): Drupal\ai\Plugin\AiFunctionCall\Derivative\ActionPluginDeriver->getDerivativeDefinitions()
    #3 /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives()
    #4 /var/www/html/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(337): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()
    #5 /var/www/html/web/modules/contrib/ai/src/Service/FunctionCalling/FunctionCallPluginManager.php(33): Drupal\Core\Plugin\DefaultPluginManager->findDefinitions()
    #6 /var/www/html/web/modules/contrib/ai/modules/ai_api_explorer/src/Plugin/AiApiExplorer/ChatGenerator.php(188): Drupal\ai\Service\FunctionCalling\FunctionCallPluginManager->getDefinitions()
    #7 /var/www/html/web/modules/contrib/ai/modules/ai_api_explorer/src/Form/AiApiExplorerForm.php(60): Drupal\ai_api_explorer\Plugin\AiApiExplorer\ChatGenerator->buildForm()
    #8 [internal function]: Drupal\ai_api_explorer\Form\AiApiExplorerForm->buildForm()
    #9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
    #10 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->retrieveForm()
    #11 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
    #12 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
    #13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #14 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
    #16 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #22 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\Core\StackMiddleware\ContentLength->handle()
    #23 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #26 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #28 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #29 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
    #30 {main}
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Just to make sure that we do not have this error on 1.2.x of AI and 1.2.x of AI agents, tried replicating with Drupal core 11.x, all pages are working fine without any error, etc.

    Seems to be specific to Drupal core 10 and Drupal AI 1.1.0, as mentioned in the Steps to reproduce.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany marcus_johansson

    I think this should be solved in 1.2.x with the inclusion of ๐Ÿ“Œ Create Context upcaster for complex data types Active .

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Got the same error on the pageadmin/config/ai/explorers/tools_explorer.

    Will something like the following work:

        if (!empty($attributes)) {
          return $attributes[0]->newInstance()->id;
        }
        return $type;
    
Production build 0.71.5 2024