Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Elastic AI Assistant] Adds support for arbitrary…
… tool registration (#172234) ## Summary Adds support for arbitrary tool registration on plugin start, allowing any plugin consuming the `elastic_assistant` plugin to register tools specific to their use case. This was achieved by introducing an `AppContextService`, with functions `registerTools` and `getRegisteredTools`. When registering within another plugin's start contract, call `registerTools`, e.g. ``` ts // Assistant Tool and Feature Registration plugins.elasticAssistant.registerTools(APP_UI_ID, getAssistantTools()); ``` and to get any tools for a given plugin, call `getRegisteredTools` with the plugin's name. E.g here within the assistant request handler: ```ts // Fetch any tools registered by the request's originating plugin const pluginName = getPluginNameFromRequest({ request, logger }); const assistantTools = (await context.elasticAssistant).getRegisteredTools(pluginName); ``` > [!NOTE] > Use the plugin name that corresponds to your application as defined in the `x-kbn-context` header of requests made from your application. This is the value used to fetch relevant tools, which may be different than your plugin's registered `APP_ID`. ### Test instructions Since no new tool functionality has been enabled here, you can just follow the test instructions from #173121, and ensure that enabling/disabling the KB or RAG on Alerts still functions as expected. You should see the registered tools as a debug logger, e.g. ``` [DEBUG][plugins.elasticAssistant] AppContextService:getRegisteredTools [DEBUG][plugins.elasticAssistant] pluginName: securitySolutionUI [DEBUG][plugins.elasticAssistant] tools: AlertCountsTool, ESQLKnowledgeBaseTool, OpenAndAcknowledgedAlertsTool [DEBUG][plugins.elasticAssistant] applicable tools: "alert-counts, ESQLKnowledgeBaseTool, open-alerts" ``` ### Checklist Delete any items that are not applicable to this PR. - [ ] ~Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~ - [ ] ~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials~ - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information