kimaai_chatbot_allowed_tools

When it fires

In every chatbot request, streamed or not, and every search answer, while the request is prepared, right before kimaai_chatbot_tools_registry. The list starts with the tools ticked in the setting “Allowed custom functions” (Chatbot Settings, Pro) and, while the knowledge base is on, kb_vector_search. KimaAI’s own features add their tools at priority 10 when they are on: lead capture its contact form tool, and in Pro the handoff, the meeting booking, the customer tools and the WooCommerce, Contact Form 7 and Gravity Forms tools.

A request offers a tool only when its name is in this list and kimaai_chatbot_tools_registry has its definition; a name without a definition offers nothing. A non-array result counts as an empty list. The list is stored in the request payload as selectedTools.

Parameters

NameTypeDescription
tool_namesstring[]The names of the allowed tools, from the setting “Allowed custom functions”, with kb_vector_search while the knowledge base is on.

Returns

string[]: The names of the allowed tools.

Example

add_filter(
  'kimaai_chatbot_allowed_tools',
  function (array $names): array {
    $names[] = 'wp_search_posts';
    return array_values(array_unique($names));
  }
);

The chatbot may search the site’s posts by keyword on every request, without the tool being ticked in the setting. wp_search_posts is in the catalogue of kimaai_tools_registry, which the chatbot offers with KimaAI Pro.

More examples

Remove a tool, here the contact form of lead capture for visitors who are logged in:

add_filter(
  'kimaai_chatbot_allowed_tools',
  function (array $names): array {
    return is_user_logged_in() ? array_values(array_diff($names, ['offer_contact_form'])) : $names;
  },
  20
);

KimaAI adds its own tools at priority 10, so a callback that removes one runs later, at 20.

  • kimaai_chatbot_tools_registry: the definitions of the tools a request offers.
  • kimaai_tools_registry: the catalogue the setting lists.
  • kimaai_tool_call_allowed: blocks a single call instead of not offering the tool.

What are your feelings