Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
23c1a47
Gemini prompts
viduni94 Jun 11, 2025
3e159ba
Add new prompt with conditions
viduni94 Jun 16, 2025
8679aa6
Update prompt based on deployment
viduni94 Jun 16, 2025
f5aae43
Remove unnecessary new line
viduni94 Jun 16, 2025
6c6ea27
Alerts function
viduni94 Jun 16, 2025
9569a46
Elasticsearch function prompt tweaks
viduni94 Jun 16, 2025
07904a1
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jun 19, 2025
42d77c4
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jun 24, 2025
f81358f
Improve system prompt for generating ES|QL
SrdjanLL Jun 25, 2025
4015d54
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jun 25, 2025
38f247f
Merge branch 'main' into improve-prompts-for-gemini-models
SrdjanLL Jun 26, 2025
59b9f68
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jun 27, 2025
18f3c1e
Prompt tunning for APM scenarios
SrdjanLL Jun 27, 2025
d5c2906
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jun 30, 2025
ebe6a7f
Re-factor system prompt
viduni94 Jun 30, 2025
5dcbe60
Set "context" tool as non-internal in order to fix knowledge base ret…
SrdjanLL Jul 1, 2025
eac2764
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 2, 2025
5de47ff
Additional system prompt changes
SrdjanLL Jul 2, 2025
8b614a4
Make context tool internal again and use its function name from "comm…
SrdjanLL Jul 2, 2025
4b9ebd7
A few more refactors
viduni94 Jul 2, 2025
21e641d
Remove *query tools from the system prompt
SrdjanLL Jul 2, 2025
e8d73af
Improve KB retrieval
viduni94 Jul 2, 2025
55735ff
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 2, 2025
72d032f
Update tool name
viduni94 Jul 2, 2025
266979f
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 4, 2025
e7dd784
Add instructions to the NL-ES|QL system prompt specific to the query …
SrdjanLL Jul 4, 2025
02ca4a4
Move documentation tool instruction to the system prompt to fix instr…
viduni94 Jul 4, 2025
a2d9067
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 7, 2025
6000089
Update prompt for get_apm_downstream_dependancies to not enforce time…
viduni94 Jul 7, 2025
5eec8e1
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 8, 2025
a1db93c
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 8, 2025
66f77d1
Fix import
viduni94 Jul 8, 2025
9f8b85c
Fix import
viduni94 Jul 8, 2025
fa05b5f
Fix import
viduni94 Jul 8, 2025
41775e0
Fix import
viduni94 Jul 8, 2025
8dfe250
Fix import
viduni94 Jul 9, 2025
8a257af
System message updates for the NL-ESQL task
SrdjanLL Jul 9, 2025
ce7f83e
Append and emphasize available tools to the additional system instruc…
SrdjanLL Jul 9, 2025
83b918c
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 10, 2025
bcc053b
Fix import
viduni94 Jul 10, 2025
d828edf
Update tests
viduni94 Jul 10, 2025
fba0980
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 12, 2025
a6574e3
Fix import
viduni94 Jul 12, 2025
77abce8
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 14, 2025
050b37b
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 14, 2025
167bc1b
Dial down the eagerness for query execution in example scenarios
SrdjanLL Jul 11, 2025
be1138c
Refactor system prompt to reorder function usage guideliness for gett…
SrdjanLL Jul 16, 2025
18f91f1
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 16, 2025
f1f1b91
System prompt updates: remove hardcoded numbered list of core princip…
SrdjanLL Jul 17, 2025
065eba5
Fix index patern for trace duration ES|QL evaluation scenario as disc…
SrdjanLL Jul 17, 2025
4ed3281
Update system prompt with clearer query requirements. Update tool des…
SrdjanLL Jul 17, 2025
bcb9f3a
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 18, 2025
82eda46
Fix search prompt to inlcude tool instructions
viduni94 Jul 18, 2025
952ef2d
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 21, 2025
7dda9c7
Use tags in the system prompt instead of markdown section titles
viduni94 Jul 21, 2025
f4e7497
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 22, 2025
1f46084
Fix test
viduni94 Jul 22, 2025
2710076
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 22, 2025
cca3105
Improve documentation scenario criteria
viduni94 Jul 23, 2025
f996a7a
Change APM scenario back to success rate
viduni94 Jul 23, 2025
70dbd9e
Update formatting of the system prompt
viduni94 Jul 23, 2025
a3892d0
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 23, 2025
749f315
Tweak the system promot for better discoverability of the index name
viduni94 Jul 23, 2025
85d24e2
Update ES|QL instructions
viduni94 Jul 24, 2025
930ba2e
Improve instructions for time range handling and alerts
viduni94 Jul 24, 2025
4ebc616
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 24, 2025
179e8a1
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 25, 2025
d46b55a
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 28, 2025
a71c1d9
Improve instructions for the ES tool to disallow some actions
viduni94 Jul 28, 2025
b682dfb
Add snapshot tests
viduni94 Jul 28, 2025
2366166
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 30, 2025
0122059
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Jul 31, 2025
218351e
Fix i18n
viduni94 Jul 31, 2025
d008e38
Fix typo
viduni94 Jul 31, 2025
8437ff6
Update snapshots
viduni94 Jul 31, 2025
c918222
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 4, 2025
daaa0f1
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 6, 2025
a03ef08
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 6, 2025
5e2f90d
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 7, 2025
57a44b2
Small prompt tweak for time range handling
viduni94 Aug 8, 2025
61c0732
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 8, 2025
1db394b
Update prompt snapshots
viduni94 Aug 8, 2025
8edf472
Merge branch 'main' into improve-prompts-for-gemini-models
viduni94 Aug 11, 2025
13bc13f
Fix merge conflict
viduni94 Aug 11, 2025
51e38ff
Remove extra ES tool instruction from merging main
viduni94 Aug 11, 2025
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 @@ -5,8 +5,7 @@
* 2.0.
*/

import { Message } from '@kbn/observability-ai-assistant-plugin/common';
import { CONTEXT_FUNCTION_NAME } from '@kbn/observability-ai-assistant-plugin/server/functions/context/context';
import { CONTEXT_FUNCTION_NAME, Message } from '@kbn/observability-ai-assistant-plugin/common';
import { reverseToLastUserMessage } from './chat_body';

describe('<ChatBody>', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { ChatState, Message, MessageRole } from '@kbn/observability-ai-assistant-plugin/public';
import { createMockChatService } from './create_mock_chat_service';
import { KibanaContextProvider } from '@kbn/triggers-actions-ui-plugin/public/common/lib/kibana';
import { CONTEXT_FUNCTION_NAME } from '@kbn/observability-ai-assistant-plugin/server/functions/context/context';
import { CONTEXT_FUNCTION_NAME } from '@kbn/observability-ai-assistant-plugin/common';

const mockChatService = createMockChatService();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

// Context tools
export const CONTEXT_FUNCTION_NAME = 'context';
export const GET_DATA_ON_SCREEN_FUNCTION_NAME = 'get_data_on_screen';

// Alerts tools
export const GET_ALERTS_DATASET_INFO_FUNCTION_NAME = 'get_alerts_dataset_info';
export const ALERTS_FUNCTION_NAME = 'alerts';

// Query tools
export const QUERY_FUNCTION_NAME = 'query';
export const EXECUTE_QUERY_FUNCTION_NAME = 'execute_query';
export const VISUALIZE_QUERY_FUNCTION_NAME = 'visualize_query';

// Dataset tools
export const GET_DATASET_INFO_FUNCTION_NAME = 'get_dataset_info';
export const SELECT_RELEVANT_FIELDS_NAME = 'select_relevant_fields';

export const ELASTICSEARCH_FUNCTION_NAME = 'elasticsearch';

export const EXECUTE_CONNECTOR_FUNCTION_NAME = 'execute_connector';

export const KIBANA_FUNCTION_NAME = 'kibana';

export const SUMMARIZE_FUNCTION_NAME = 'summarize';

export const CHANGES_FUNCTION_NAME = 'changes';

export const RETRIEVE_ELASTIC_DOC_FUNCTION_NAME = 'retrieve_elastic_doc';

// APM tools
export const GET_APM_DATASET_INFO_FUNCTION_NAME = 'get_apm_dataset_info';
export const GET_APM_DOWNSTREAM_DEPENDENCIES_FUNCTION_NAME = 'get_apm_downstream_dependencies';
export const GET_APM_SERVICES_LIST_FUNCTION_NAME = 'get_apm_services_list';

// Deprecated tools
export const GET_APM_TIMESERIES_FUNCTION_NAME = 'get_apm_timeseries';
export const LENS_FUNCTION_NAME = 'lens';
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ export {
EIS_PRECONFIGURED_INFERENCE_IDS,
LEGACY_CUSTOM_INFERENCE_ID,
} from './preconfigured_inference_ids';

export {
GET_ALERTS_DATASET_INFO_FUNCTION_NAME,
ALERTS_FUNCTION_NAME,
QUERY_FUNCTION_NAME,
EXECUTE_QUERY_FUNCTION_NAME,
GET_DATA_ON_SCREEN_FUNCTION_NAME,
CONTEXT_FUNCTION_NAME,
ELASTICSEARCH_FUNCTION_NAME,
EXECUTE_CONNECTOR_FUNCTION_NAME,
GET_DATASET_INFO_FUNCTION_NAME,
SELECT_RELEVANT_FIELDS_NAME,
KIBANA_FUNCTION_NAME,
SUMMARIZE_FUNCTION_NAME,
VISUALIZE_QUERY_FUNCTION_NAME,
CHANGES_FUNCTION_NAME,
RETRIEVE_ELASTIC_DOC_FUNCTION_NAME,
GET_APM_DATASET_INFO_FUNCTION_NAME,
GET_APM_DOWNSTREAM_DEPENDENCIES_FUNCTION_NAME,
GET_APM_SERVICES_LIST_FUNCTION_NAME,
GET_APM_TIMESERIES_FUNCTION_NAME,
LENS_FUNCTION_NAME,
} from './function_names';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"taskManager",
"dataViews",
"inference",
"llmTasks",
"productDocBase"
],
"optionalPlugins": ["cloud", "serverless"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
*/

import { last } from 'lodash';
import { Message, MessageRole } from '../../../common';
import { CONTEXT_FUNCTION_NAME, Message, MessageRole } from '../../../common';
import { removeContextToolRequest } from './context';

const CONTEXT_FUNCTION_NAME = 'context';

describe('removeContextToolRequest', () => {
const baseMessages: Message[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import { encode } from 'gpt-tokenizer';
import { compact, last } from 'lodash';
import { Observable } from 'rxjs';
import { FunctionRegistrationParameters } from '..';
import { CONTEXT_FUNCTION_NAME } from '../../../common';
import { MessageAddEvent } from '../../../common/conversation_complete';
import { Message } from '../../../common/types';
import { createFunctionResponseMessage } from '../../../common/utils/create_function_response_message';
import { recallAndScore } from './utils/recall_and_score';

const MAX_TOKEN_COUNT_FOR_DATA_ON_SCREEN = 1000;

export const CONTEXT_FUNCTION_NAME = 'context';

export function registerContextFunction({
client,
functions,
Expand All @@ -39,8 +38,8 @@ export function registerContextFunction({
const screenDescription = compact(
screenContexts.map((context) => context.screenDescription)
).join('\n\n');
// any data that falls within the token limit, send it automatically

// any data that falls within the token limit, send it automatically
const dataWithinTokenLimit = compact(
screenContexts.flatMap((context) => context.data)
).filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@
*/

import type { FunctionRegistrationParameters } from '.';

export const ELASTICSEARCH_FUNCTION_NAME = 'elasticsearch';
import { ELASTICSEARCH_FUNCTION_NAME } from '..';

export function registerElasticsearchFunction({
functions,
resources,
}: FunctionRegistrationParameters) {
functions.registerInstruction(({ availableFunctionNames }) => {
if (availableFunctionNames.includes(ELASTICSEARCH_FUNCTION_NAME)) {
return `You can use the ${ELASTICSEARCH_FUNCTION_NAME} tool to call Elasticsearch APIs on behalf of the user.
You are only allowed to perform GET requests (Some examples for GET requests are: Retrieving cluster information, cluster license, cluster health, indices stats, index stats, etc.) and GET/POST requests for the \`/_search\` endpoint (for search operations).
If the user asks to perform destructive actions or actions that are not allowed (e.g. PUT, PATCH, DELETE requests or POST requests that are not to the \`/_search\` endpoint), **NEVER** attempt to call the ${ELASTICSEARCH_FUNCTION_NAME} tool.
Instead, inform the user that you do not have the capability to perform those actions.
If you attempt to call the ${ELASTICSEARCH_FUNCTION_NAME} tool with disallowed methods (PUT, DELETE, PATCH, POST requests that are not to the \`/_search\` endpoint), it will fail.
For POST \`/_search\` operations, if a request body is needed, make sure the request body is a valid object.`;
}
return '';
});

functions.registerFunction(
{
name: ELASTICSEARCH_FUNCTION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import { FunctionRegistrationParameters } from '.';

export const EXECUTE_CONNECTOR_FUNCTION_NAME = 'execute_connector';
import { EXECUTE_CONNECTOR_FUNCTION_NAME } from '..';

export function registerExecuteConnectorFunction({
functions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { compact } from 'lodash';
import dedent from 'dedent';
import { ObservabilityAIAssistantScreenContextRequest } from '../../common/types';
import { ChatFunctionClient } from '../service/chat_function_client';

export const GET_DATA_ON_SCREEN_FUNCTION_NAME = 'get_data_on_screen';
import { GET_DATA_ON_SCREEN_FUNCTION_NAME, CONTEXT_FUNCTION_NAME } from '../../common';

export function registerGetDataOnScreenFunction(
functions: ChatFunctionClient,
Expand Down Expand Up @@ -49,11 +48,19 @@ export function registerGetDataOnScreenFunction(
}
);

functions.registerInstruction(({ availableFunctionNames }) =>
availableFunctionNames.includes(GET_DATA_ON_SCREEN_FUNCTION_NAME)
? `The ${GET_DATA_ON_SCREEN_FUNCTION_NAME} function will retrieve specific content from the user's screen by specifying a data key. Use this tool to provide context-aware responses. Available data: ${dedent(
functions.registerInstruction(({ availableFunctionNames }) => {
if (availableFunctionNames.includes(GET_DATA_ON_SCREEN_FUNCTION_NAME)) {
return `You have access to data on the screen by calling the "${GET_DATA_ON_SCREEN_FUNCTION_NAME}" tool.
Use it to help the user understand what they are looking at.

This tool will retrieve specific content from the user's screen by specifying a data key. Use this tool to provide context-aware responses. Available data: ${dedent(
allData.map((data) => `${data.name}: ${data.description}`).join('\n')
)}`
: undefined
);
)}

A short summary of what they are looking at is available in the return of the "${CONTEXT_FUNCTION_NAME}" function.
Data that is compact enough automatically gets included in the response for the "${CONTEXT_FUNCTION_NAME}" function.`;
}

return undefined;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/
import type { DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { castArray, chunk, groupBy, uniq } from 'lodash';
import { lastValueFrom } from 'rxjs';
import { MessageRole, ShortIdTable, type Message } from '../../../common';
import {
MessageRole,
ShortIdTable,
type Message,
SELECT_RELEVANT_FIELDS_NAME,
} from '../../../common';
import { concatenateChatCompletionChunks } from '../../../common/utils/concatenate_chat_completion_chunks';
import { FunctionCallChatFunction } from '../../service/types';

export const SELECT_RELEVANT_FIELDS_NAME = 'select_relevant_fields';
export const GET_RELEVANT_FIELD_NAMES_SYSTEM_MESSAGE = `You are a helpful assistant for Elastic Observability.
Your task is to determine which fields are relevant to the conversation by selecting only the field IDs from the provided list.
The list in the user message consists of JSON objects that map a human-readable field "name" to its unique "id".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*/

import { IScopedClusterClient, Logger } from '@kbn/core/server';
import { Message } from '../../../common';
import { GET_DATASET_INFO_FUNCTION_NAME, Message } from '../../../common';
import { FunctionRegistrationParameters } from '..';
import { FunctionCallChatFunction, RespondFunctionResources } from '../../service/types';
import { getRelevantFieldNames } from './get_relevant_field_names';

export const GET_DATASET_INFO_FUNCTION_NAME = 'get_dataset_info';

export function registerGetDatasetInfoFunction({
resources,
functions,
Expand Down
Loading