Skip to content

Commit 343b80a

Browse files
[Obs AI Assistant] Update the simulate function calling setting to support "auto" (#209628)
Closes elastic/obs-ai-assistant-team#198 ## Summary The simulated function calling setting is currently a boolean. It needs to be updated to support the option `auto`. `export type FunctionCallingMode = 'native' | 'simulated' | 'auto';` If the setting is set to `false`, `auto` will be passed to the inference client. If the setting is `true`, `simulated` will be passed to it. Relates to #208144 ### Checklist - [x] 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/src/platform/packages/shared/kbn-i18n/README.md) - [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 - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 77ea8fe commit 343b80a

File tree

11 files changed

+38
-50
lines changed

11 files changed

+38
-50
lines changed

x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_body.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import {
2828
VisualizeESQLUserIntention,
2929
type ChatActionClickPayload,
3030
type Feedback,
31+
aiAssistantSimulatedFunctionCalling,
3132
} from '@kbn/observability-ai-assistant-plugin/public';
3233
import type { AuthenticatedUser } from '@kbn/security-plugin/common';
3334
import { findLastIndex } from 'lodash';
3435
import React, { useCallback, useEffect, useRef, useState } from 'react';
3536
import type { UseKnowledgeBaseResult } from '../hooks/use_knowledge_base';
3637
import { ASSISTANT_SETUP_TITLE, EMPTY_CONVERSATION_TITLE, UPGRADE_LICENSE_TITLE } from '../i18n';
3738
import { useAIAssistantChatService } from '../hooks/use_ai_assistant_chat_service';
38-
import { useSimulatedFunctionCalling } from '../hooks/use_simulated_function_calling';
3939
import { useGenAIConnectors } from '../hooks/use_genai_connectors';
4040
import { useConversation } from '../hooks/use_conversation';
4141
import { FlyoutPositionMode } from './chat_flyout';
@@ -47,6 +47,7 @@ import { WelcomeMessage } from './welcome_message';
4747
import { useLicense } from '../hooks/use_license';
4848
import { PromptEditor } from '../prompt_editor/prompt_editor';
4949
import { deserializeMessage } from '../utils/deserialize_message';
50+
import { useKibana } from '../hooks/use_kibana';
5051

5152
const fullHeightClassName = css`
5253
height: 100%;
@@ -138,7 +139,14 @@ export function ChatBody({
138139

139140
const chatService = useAIAssistantChatService();
140141

141-
const { simulatedFunctionCallingEnabled } = useSimulatedFunctionCalling();
142+
const {
143+
services: { uiSettings },
144+
} = useKibana();
145+
146+
const simulateFunctionCalling = uiSettings!.get<boolean>(
147+
aiAssistantSimulatedFunctionCalling,
148+
false
149+
);
142150

143151
const { conversation, messages, next, state, stop, saveTitle } = useConversation({
144152
initialConversationId,
@@ -409,7 +417,7 @@ export function ChatBody({
409417
</div>
410418
</EuiFlexItem>
411419

412-
{simulatedFunctionCallingEnabled ? (
420+
{simulateFunctionCalling ? (
413421
<EuiFlexItem grow={false}>
414422
<SimulatedFunctionCallingCallout />
415423
</EuiFlexItem>

x-pack/platform/packages/shared/kbn-ai-assistant/src/hooks/use_simulated_function_calling.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/chat_function_client/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('chatFunctionClient', () => {
5050
messages: [],
5151
signal: new AbortController().signal,
5252
connectorId: 'foo',
53-
useSimulatedFunctionCalling: false,
53+
simulateFunctionCalling: false,
5454
});
5555
}).rejects.toThrowError(`Function arguments are invalid`);
5656

@@ -112,7 +112,7 @@ describe('chatFunctionClient', () => {
112112
messages: [],
113113
signal: new AbortController().signal,
114114
connectorId: 'foo',
115-
useSimulatedFunctionCalling: false,
115+
simulateFunctionCalling: false,
116116
});
117117

118118
expect(result).toEqual({

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/chat_function_client/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ export class ChatFunctionClient {
167167
messages,
168168
signal,
169169
connectorId,
170-
useSimulatedFunctionCalling,
170+
simulateFunctionCalling,
171171
}: {
172172
chat: FunctionCallChatFunction;
173173
name: string;
174174
args: string | undefined;
175175
messages: Message[];
176176
signal: AbortSignal;
177177
connectorId: string;
178-
useSimulatedFunctionCalling: boolean;
178+
simulateFunctionCalling: boolean;
179179
}): Promise<FunctionResponse> {
180180
const fn = this.functionRegistry.get(name);
181181

@@ -194,7 +194,7 @@ export class ChatFunctionClient {
194194
screenContexts: this.screenContexts,
195195
chat,
196196
connectorId,
197-
useSimulatedFunctionCalling,
197+
simulateFunctionCalling,
198198
},
199199
signal
200200
);

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ describe('Observability AI Assistant client', () => {
313313
expect.objectContaining({
314314
connectorId: 'foo',
315315
stream: false,
316-
functionCalling: 'native',
316+
functionCalling: 'auto',
317317
toolChoice: expect.objectContaining({
318318
function: 'title_conversation',
319319
}),
@@ -349,7 +349,7 @@ describe('Observability AI Assistant client', () => {
349349
messages: expect.arrayContaining([
350350
{ role: 'user', content: 'How many alerts do I have?' },
351351
]),
352-
functionCalling: 'native',
352+
functionCalling: 'auto',
353353
toolChoice: undefined,
354354
tools: undefined,
355355
},
@@ -872,7 +872,7 @@ describe('Observability AI Assistant client', () => {
872872
},
873873
},
874874
],
875-
useSimulatedFunctionCalling: false,
875+
simulateFunctionCalling: false,
876876
});
877877
});
878878

@@ -919,7 +919,7 @@ describe('Observability AI Assistant client', () => {
919919
messages: expect.arrayContaining([
920920
{ role: 'user', content: 'How many alerts do I have?' },
921921
]),
922-
functionCalling: 'native',
922+
functionCalling: 'auto',
923923
toolChoice: 'auto',
924924
tools: expect.any(Object),
925925
},
@@ -1080,7 +1080,7 @@ describe('Observability AI Assistant client', () => {
10801080
messages: expect.arrayContaining([
10811081
{ role: 'user', content: 'How many alerts do I have?' },
10821082
]),
1083-
functionCalling: 'native',
1083+
functionCalling: 'auto',
10841084
toolChoice: 'auto',
10851085
tools: expect.any(Object),
10861086
},

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export class ObservabilityAIAssistantClient {
307307
disableFunctions,
308308
tracer: completeTracer,
309309
connectorId,
310-
useSimulatedFunctionCalling: simulateFunctionCalling === true,
310+
simulateFunctionCalling,
311311
})
312312
);
313313
}),
@@ -505,15 +505,17 @@ export class ObservabilityAIAssistantClient {
505505
}
506506
: ToolChoiceType.auto;
507507
}
508+
508509
const options = {
509510
connectorId,
510511
messages: convertMessagesForInference(
511512
messages.filter((message) => message.message.role !== MessageRole.System)
512513
),
513514
toolChoice,
514515
tools,
515-
functionCalling: (simulateFunctionCalling ? 'simulated' : 'native') as FunctionCallingMode,
516+
functionCalling: (simulateFunctionCalling ? 'simulated' : 'auto') as FunctionCallingMode,
516517
};
518+
517519
if (stream) {
518520
return defer(() =>
519521
this.dependencies.inferenceClient.chatComplete({

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/operators/continue_conversation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function executeFunctionAndCatchError({
5454
logger,
5555
tracer,
5656
connectorId,
57-
useSimulatedFunctionCalling,
57+
simulateFunctionCalling,
5858
}: {
5959
name: string;
6060
args: string | undefined;
@@ -65,7 +65,7 @@ function executeFunctionAndCatchError({
6565
logger: Logger;
6666
tracer: LangTracer;
6767
connectorId: string;
68-
useSimulatedFunctionCalling: boolean;
68+
simulateFunctionCalling: boolean;
6969
}): Observable<MessageOrChatEvent> {
7070
// hide token count events from functions to prevent them from
7171
// having to deal with it as well
@@ -86,7 +86,7 @@ function executeFunctionAndCatchError({
8686
signal,
8787
messages,
8888
connectorId,
89-
useSimulatedFunctionCalling,
89+
simulateFunctionCalling,
9090
})
9191
);
9292

@@ -184,7 +184,7 @@ export function continueConversation({
184184
disableFunctions,
185185
tracer,
186186
connectorId,
187-
useSimulatedFunctionCalling,
187+
simulateFunctionCalling,
188188
}: {
189189
messages: Message[];
190190
functionClient: ChatFunctionClient;
@@ -201,7 +201,7 @@ export function continueConversation({
201201
};
202202
tracer: LangTracer;
203203
connectorId: string;
204-
useSimulatedFunctionCalling: boolean;
204+
simulateFunctionCalling: boolean;
205205
}): Observable<MessageOrChatEvent> {
206206
let nextFunctionCallsLeft = functionCallsLeft;
207207

@@ -319,7 +319,7 @@ export function continueConversation({
319319
logger,
320320
tracer,
321321
connectorId,
322-
useSimulatedFunctionCalling,
322+
simulateFunctionCalling,
323323
});
324324
}
325325

@@ -348,7 +348,7 @@ export function continueConversation({
348348
disableFunctions,
349349
tracer,
350350
connectorId,
351-
useSimulatedFunctionCalling,
351+
simulateFunctionCalling,
352352
});
353353
})
354354
)

x-pack/platform/plugins/shared/observability_ai_assistant/server/service/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type RespondFunction<TArguments, TResponse extends FunctionResponse> = (
5656
screenContexts: ObservabilityAIAssistantScreenContextRequest[];
5757
chat: FunctionCallChatFunction;
5858
connectorId: string;
59-
useSimulatedFunctionCalling: boolean;
59+
simulateFunctionCalling: boolean;
6060
},
6161
signal: AbortSignal
6262
) => Promise<TResponse>;

x-pack/solutions/observability/plugins/observability_ai_assistant_app/server/functions/documentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ export async function registerDocumentationFunction({
6262
required: ['query'],
6363
} as const,
6464
},
65-
async ({ arguments: { query, product }, connectorId, useSimulatedFunctionCalling }) => {
65+
async ({ arguments: { query, product }, connectorId, simulateFunctionCalling }) => {
6666
const response = await llmTasks!.retrieveDocumentation({
6767
searchTerm: query,
6868
products: product ? [product] : undefined,
6969
max: 3,
7070
connectorId,
7171
request: resources.request,
72-
functionCalling: useSimulatedFunctionCalling ? 'simulated' : 'native',
72+
functionCalling: simulateFunctionCalling ? 'simulated' : 'auto',
7373
});
7474

7575
return {

x-pack/solutions/observability/plugins/observability_ai_assistant_app/server/functions/query/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function registerQueryFunction({
112112
function takes no input.`,
113113
visibility: FunctionVisibility.AssistantOnly,
114114
},
115-
async ({ messages, connectorId, useSimulatedFunctionCalling }, signal) => {
115+
async ({ messages, connectorId, simulateFunctionCalling }, signal) => {
116116
const esqlFunctions = functions
117117
.getFunctions()
118118
.filter(
@@ -137,7 +137,7 @@ export function registerQueryFunction({
137137
{ description: fn.description, schema: fn.parameters } as ToolDefinition,
138138
])
139139
),
140-
functionCalling: useSimulatedFunctionCalling ? 'simulated' : 'native',
140+
functionCalling: simulateFunctionCalling ? 'simulated' : 'auto',
141141
});
142142

143143
const chatMessageId = v4();

0 commit comments

Comments
 (0)