Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Elastic AI Assistant] Adds support for arbitrary tool registration #172234

Merged
merged 24 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9aeed7c
Support registration of arbitrary tools on plugin start
spong Nov 30, 2023
f7b50dc
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Nov 30, 2023
5df33d5
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 30, 2023
f2f2e51
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Nov 30, 2023
38a3941
Update mocks
spong Nov 30, 2023
5096191
Merge branch 'main' into tool-registry
spong Nov 30, 2023
36be9e6
Merge branch 'main' into tool-registry
spong Dec 1, 2023
c713281
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 6, 2023
c10e546
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 7, 2023
52d57cf
Move new RAG on alerts tools to Security Solution plugin
spong Dec 8, 2023
bef4775
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 8, 2023
68e1ceb
Adds tool metadata and separates params validation from tool creation
spong Dec 13, 2023
9c79925
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 13, 2023
d4e52f5
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Dec 13, 2023
8565784
Adds jest config for new security solution assistant server tests
spong Dec 13, 2023
92211a2
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 13, 2023
cf5eea4
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 13, 2023
0f47898
Renames to match new tool names from merge w/ main
spong Dec 13, 2023
7ab2e42
Additional missed renames
spong Dec 13, 2023
2f65edb
Extracts plugin name from request and adds tests
spong Dec 14, 2023
19b7532
Merge branch 'main' of github.com:elastic/kibana into tool-registry
spong Dec 14, 2023
dcf4c82
Updating tool names
spong Dec 14, 2023
70186ab
Last comments from review
spong Dec 14, 2023
91d868b
Reverts alert counts query updates for acknowledged rules
spong Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createMockClients = () => {
clusterClient: core.elasticsearch.client,
elasticAssistant: {
actions: actionsClientMock.create(),
getRegisteredTools: jest.fn(),
logger: loggingSystemMock.createLogger(),
},
savedObjectsClient: core.savedObjects.client,
Expand Down Expand Up @@ -72,6 +73,7 @@ const createElasticAssistantRequestContextMock = (
): jest.Mocked<ElasticAssistantApiRequestHandlerContext> => {
return {
actions: clients.elasticAssistant.actions as unknown as ActionsPluginStart,
getRegisteredTools: jest.fn(),
logger: clients.elasticAssistant.logger,
};
};
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/elastic_assistant/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export async function plugin(initializerContext: PluginInitializerContext) {
}

export type {
ElasticAssistantPluginSetup as EcsDataQualityDashboardPluginSetup,
ElasticAssistantPluginStart as EcsDataQualityDashboardPluginStart,
ElasticAssistantPluginSetup,
ElasticAssistantPluginStart,
ElasticAssistantPluginSetupDependencies,
ElasticAssistantPluginStartDependencies,
AssistantTool,
AssistantToolParams,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { KNOWLEDGE_BASE_INDEX_PATTERN } from '../../../routes/knowledge_base/con
import type { AgentExecutorParams, AgentExecutorResponse } from '../executors/types';
import { withAssistantSpan } from '../tracers/with_assistant_span';
import { APMTracer } from '../tracers/apm_tracer';
import { getApplicableTools } from '../tools';
import { AssistantToolParams } from '../../../types';

export const DEFAULT_AGENT_EXECUTOR_ID = 'Elastic AI Assistant Agent Executor';

Expand All @@ -31,6 +31,7 @@ export const callAgentExecutor = async ({
allow,
allowReplacement,
assistantLangChain,
assistantTools = [],
connectorId,
elserId,
esClient,
Expand Down Expand Up @@ -71,7 +72,8 @@ export const callAgentExecutor = async ({
// Create a chain that uses the ELSER backed ElasticsearchStore, override k=10 for esql query generation for now
const chain = RetrievalQAChain.fromLLM(llm, esStore.asRetriever(10));

const tools: Tool[] = getApplicableTools({
// Fetch any applicable tools that the source plugin may have registered
const assistantToolParams: AssistantToolParams = {
allow,
allowReplacement,
alertsIndexPattern,
Expand All @@ -83,7 +85,8 @@ export const callAgentExecutor = async ({
replacements,
request,
size,
});
};
const tools: Tool[] = assistantTools.flatMap((tool) => tool.getTool(assistantToolParams) ?? []);

logger.debug(`applicable tools: ${JSON.stringify(tools.map((t) => t.name).join(', '), null, 2)}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { Logger } from '@kbn/logging';
import { KibanaRequest } from '@kbn/core-http-server';
import type { LangChainTracer } from 'langchain/callbacks';
import { RequestBody, ResponseBody } from '../types';
import type { AssistantTool } from '../../../types';

export interface AgentExecutorParams {
alertsIndexPattern?: string;
actions: ActionsPluginStart;
allow?: string[];
allowReplacement?: string[];
assistantLangChain: boolean;
assistantTools?: AssistantTool[];
connectorId: string;
esClient: ElasticsearchClient;
kbResource: string | undefined;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading