diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.test.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.test.ts index 2456499b2d66f..199a6d8f1cbca 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.test.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.test.ts @@ -329,8 +329,8 @@ describe('Observability AI Assistant client', () => { { role: 'user', content: 'How many alerts do I have?' }, ]), functionCalling: 'native', - toolChoice: 'auto', - tools: {}, + toolChoice: undefined, + tools: undefined, }, ]); }); @@ -1373,7 +1373,7 @@ describe('Observability AI Assistant client', () => { expect(Object.keys(firstBody.tools ?? {}).length).toEqual(1); - expect(body.tools).toEqual({}); + expect(body.tools).toEqual(undefined); }); }); diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.ts index c03f7d6333825..8d1ee6138e54f 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/server/service/client/index.ts @@ -481,13 +481,24 @@ export class ObservabilityAIAssistantClient { tracer: LangTracer; } ): Observable => { - const tools = functions?.reduce((acc, fn) => { - acc[fn.name] = { - description: fn.description, - schema: fn.parameters, - }; - return acc; - }, {} as Record); + let tools: Record | undefined; + let toolChoice: ToolChoiceType | { function: string } | undefined; + + if (functions?.length) { + tools = functions.reduce((acc, fn) => { + acc[fn.name] = { + description: fn.description, + schema: fn.parameters, + }; + return acc; + }, {} as Record); + + toolChoice = functionCall + ? { + function: functionCall, + } + : ToolChoiceType.auto; + } const chatComplete$ = defer(() => this.dependencies.inferenceClient.chatComplete({ @@ -497,11 +508,7 @@ export class ObservabilityAIAssistantClient { messages.filter((message) => message.message.role !== MessageRole.System) ), functionCalling: simulateFunctionCalling ? 'simulated' : 'native', - toolChoice: functionCall - ? { - function: functionCall, - } - : ToolChoiceType.auto, + toolChoice, tools, }) ).pipe(