Commit df70115
# Backport
This will backport the following commits from `main` to `8.x`:
- [[Obs Ai Assistant] Add system message
(#209773)](#209773)
<!--- Backport version: 9.4.3 -->
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)
<!--BACKPORT [{"author":{"name":"Arturo
Lidueña","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-17T10:12:56Z","message":"[Obs
Ai Assistant] Add system message (#209773)\n\nFix: System Message
Missing in Inference Plugin\r\nCloses #209548\r\n## Summary\r\n\r\nA
regression was introduced in
8.18\r\n([#199286](#199286)),
where the\r\nsystem message is no longer passed to the inference plugin
and,\r\nconsequently, the LLM.\r\n\r\nCurrently, only user messages are
being sent, which impacts conversation\r\nguidance and guardrails. The
system message is crucial for steering\r\nresponses and maintaining
contextual integrity.\r\n\r\nThe filtering of the system message happens
here:\r\n\r\nhttps://github.com/elastic/kibana/blob/771a080ffa99e501e72c9cb98c833795769483ae/x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/index.ts#L510-L512\r\n\r\nFix
Approach\r\n- Ensure the `system` message is included as a parameter
in\r\n`inferenceClient.chatComplete.`\r\n```typescript\r\nconst options
= {\r\n connectorId,\r\n system,\r\n messages:
convertMessagesForInference(messages),\r\n toolChoice,\r\n tools,\r\n
functionCalling: (simulateFunctionCalling ? 'simulated' : 'native') as
FunctionCallingMode,\r\n };\r\n if (stream) {\r\n return defer(() =>\r\n
this.dependencies.inferenceClient.chatComplete({\r\n ...options,\r\n
stream: true,\r\n })\r\n ).pipe(\r\n
convertInferenceEventsToStreamingEvents(),\r\n
instrumentAndCountTokens(name),\r\n failOnNonExistingFunctionCall({
functions }),\r\n tap((event) => {\r\n if (\r\n event.type ===
StreamingChatResponseEventType.ChatCompletionChunk &&\r\n
this.dependencies.logger.isLevelEnabled('trace')\r\n ) {\r\n
this.dependencies.logger.trace(`Received chunk:
${JSON.stringify(event.message)}`);\r\n }\r\n }),\r\n shareReplay()\r\n
) as TStream extends true\r\n ? Observable<ChatCompletionChunkEvent |
TokenCountEvent | ChatCompletionMessageEvent>\r\n : never;\r\n } else
{\r\n return this.dependencies.inferenceClient.chatComplete({\r\n
...options,\r\n stream: false,\r\n }) as TStream extends true ? never :
Promise<ChatCompleteResponse>;\r\n }\r\n }\r\n ```\r\n- Add an API test
to verify that the system message is correctly passed to the
LLM.","sha":"0ae28aa8bc73ce682166ffd5666828b1fdb7c017","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0"],"title":"[Obs
Ai Assistant] Add system
message","number":209773,"url":"https://github.com/elastic/kibana/pull/209773","mergeCommit":{"message":"[Obs
Ai Assistant] Add system message (#209773)\n\nFix: System Message
Missing in Inference Plugin\r\nCloses #209548\r\n## Summary\r\n\r\nA
regression was introduced in
8.18\r\n([#199286](#199286)),
where the\r\nsystem message is no longer passed to the inference plugin
and,\r\nconsequently, the LLM.\r\n\r\nCurrently, only user messages are
being sent, which impacts conversation\r\nguidance and guardrails. The
system message is crucial for steering\r\nresponses and maintaining
contextual integrity.\r\n\r\nThe filtering of the system message happens
here:\r\n\r\nhttps://github.com/elastic/kibana/blob/771a080ffa99e501e72c9cb98c833795769483ae/x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/index.ts#L510-L512\r\n\r\nFix
Approach\r\n- Ensure the `system` message is included as a parameter
in\r\n`inferenceClient.chatComplete.`\r\n```typescript\r\nconst options
= {\r\n connectorId,\r\n system,\r\n messages:
convertMessagesForInference(messages),\r\n toolChoice,\r\n tools,\r\n
functionCalling: (simulateFunctionCalling ? 'simulated' : 'native') as
FunctionCallingMode,\r\n };\r\n if (stream) {\r\n return defer(() =>\r\n
this.dependencies.inferenceClient.chatComplete({\r\n ...options,\r\n
stream: true,\r\n })\r\n ).pipe(\r\n
convertInferenceEventsToStreamingEvents(),\r\n
instrumentAndCountTokens(name),\r\n failOnNonExistingFunctionCall({
functions }),\r\n tap((event) => {\r\n if (\r\n event.type ===
StreamingChatResponseEventType.ChatCompletionChunk &&\r\n
this.dependencies.logger.isLevelEnabled('trace')\r\n ) {\r\n
this.dependencies.logger.trace(`Received chunk:
${JSON.stringify(event.message)}`);\r\n }\r\n }),\r\n shareReplay()\r\n
) as TStream extends true\r\n ? Observable<ChatCompletionChunkEvent |
TokenCountEvent | ChatCompletionMessageEvent>\r\n : never;\r\n } else
{\r\n return this.dependencies.inferenceClient.chatComplete({\r\n
...options,\r\n stream: false,\r\n }) as TStream extends true ? never :
Promise<ChatCompleteResponse>;\r\n }\r\n }\r\n ```\r\n- Add an API test
to verify that the system message is correctly passed to the
LLM.","sha":"0ae28aa8bc73ce682166ffd5666828b1fdb7c017"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/209773","number":209773,"mergeCommit":{"message":"[Obs
Ai Assistant] Add system message (#209773)\n\nFix: System Message
Missing in Inference Plugin\r\nCloses #209548\r\n## Summary\r\n\r\nA
regression was introduced in
8.18\r\n([#199286](#199286)),
where the\r\nsystem message is no longer passed to the inference plugin
and,\r\nconsequently, the LLM.\r\n\r\nCurrently, only user messages are
being sent, which impacts conversation\r\nguidance and guardrails. The
system message is crucial for steering\r\nresponses and maintaining
contextual integrity.\r\n\r\nThe filtering of the system message happens
here:\r\n\r\nhttps://github.com/elastic/kibana/blob/771a080ffa99e501e72c9cb98c833795769483ae/x-pack/platform/plugins/shared/observability_ai_assistant/server/service/client/index.ts#L510-L512\r\n\r\nFix
Approach\r\n- Ensure the `system` message is included as a parameter
in\r\n`inferenceClient.chatComplete.`\r\n```typescript\r\nconst options
= {\r\n connectorId,\r\n system,\r\n messages:
convertMessagesForInference(messages),\r\n toolChoice,\r\n tools,\r\n
functionCalling: (simulateFunctionCalling ? 'simulated' : 'native') as
FunctionCallingMode,\r\n };\r\n if (stream) {\r\n return defer(() =>\r\n
this.dependencies.inferenceClient.chatComplete({\r\n ...options,\r\n
stream: true,\r\n })\r\n ).pipe(\r\n
convertInferenceEventsToStreamingEvents(),\r\n
instrumentAndCountTokens(name),\r\n failOnNonExistingFunctionCall({
functions }),\r\n tap((event) => {\r\n if (\r\n event.type ===
StreamingChatResponseEventType.ChatCompletionChunk &&\r\n
this.dependencies.logger.isLevelEnabled('trace')\r\n ) {\r\n
this.dependencies.logger.trace(`Received chunk:
${JSON.stringify(event.message)}`);\r\n }\r\n }),\r\n shareReplay()\r\n
) as TStream extends true\r\n ? Observable<ChatCompletionChunkEvent |
TokenCountEvent | ChatCompletionMessageEvent>\r\n : never;\r\n } else
{\r\n return this.dependencies.inferenceClient.chatComplete({\r\n
...options,\r\n stream: false,\r\n }) as TStream extends true ? never :
Promise<ChatCompleteResponse>;\r\n }\r\n }\r\n ```\r\n- Add an API test
to verify that the system message is correctly passed to the
LLM.","sha":"0ae28aa8bc73ce682166ffd5666828b1fdb7c017"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Co-authored-by: Arturo Lidueña <[email protected]>
1 parent b002747 commit df70115
File tree
41 files changed
+282
-609
lines changed- x-pack
- platform
- plugins
- private/translations/translations
- solutions/observability/plugins/observability_ai_assistant_app
- scripts/evaluation
- server/rule_connector
- test
- api_integration/deployment_agnostic/apis/observability/ai_assistant
- chat
- complete
- conversations
- knowledge_base
- public_complete
- observability_ai_assistant_functional/tests/conversations
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
41 files changed
+282
-609
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
| |||
Lines changed: 7 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 119 | + | |
| 120 | + | |
129 | 121 | | |
130 | 122 | | |
131 | 123 | | |
| |||
157 | 149 | | |
158 | 150 | | |
159 | 151 | | |
160 | | - | |
| 152 | + | |
161 | 153 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | 154 | | |
170 | 155 | | |
171 | 156 | | |
| |||
183 | 168 | | |
184 | 169 | | |
185 | 170 | | |
| 171 | + | |
186 | 172 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 173 | | |
195 | 174 | | |
196 | 175 | | |
| |||
218 | 197 | | |
219 | 198 | | |
220 | 199 | | |
| 200 | + | |
221 | 201 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | 202 | | |
230 | 203 | | |
231 | 204 | | |
| |||
239 | 212 | | |
240 | 213 | | |
241 | 214 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | 215 | | |
250 | 216 | | |
251 | 217 | | |
| |||
255 | 221 | | |
256 | 222 | | |
257 | 223 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | 224 | | |
263 | 225 | | |
264 | 226 | | |
| |||
282 | 244 | | |
283 | 245 | | |
284 | 246 | | |
285 | | - | |
| 247 | + | |
286 | 248 | | |
287 | 249 | | |
288 | 250 | | |
289 | 251 | | |
290 | 252 | | |
291 | 253 | | |
292 | 254 | | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | 255 | | |
301 | 256 | | |
302 | 257 | | |
| |||
333 | 288 | | |
334 | 289 | | |
335 | 290 | | |
| 291 | + | |
336 | 292 | | |
337 | 293 | | |
338 | 294 | | |
| |||
Lines changed: 2 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 35 | | |
49 | 36 | | |
50 | 37 | | |
| |||
117 | 104 | | |
118 | 105 | | |
119 | 106 | | |
120 | | - | |
| 107 | + | |
| 108 | + | |
121 | 109 | | |
122 | 110 | | |
123 | 111 | | |
| |||
Lines changed: 1 addition & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 27 | + | |
35 | 28 | | |
36 | 29 | | |
37 | 30 | | |
| |||
Lines changed: 0 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 18 | | |
25 | 19 | | |
26 | 20 | | |
| |||
Lines changed: 1 addition & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 62 | | |
70 | 63 | | |
71 | 64 | | |
| |||
77 | 70 | | |
78 | 71 | | |
79 | 72 | | |
80 | | - | |
| 73 | + | |
81 | 74 | | |
82 | 75 | | |
83 | 76 | | |
| |||
113 | 106 | | |
114 | 107 | | |
115 | 108 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | 109 | | |
124 | 110 | | |
125 | 111 | | |
| |||
204 | 190 | | |
205 | 191 | | |
206 | 192 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | 193 | | |
215 | 194 | | |
216 | 195 | | |
| |||
282 | 261 | | |
283 | 262 | | |
284 | 263 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | 264 | | |
293 | 265 | | |
294 | 266 | | |
| |||
364 | 336 | | |
365 | 337 | | |
366 | 338 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 339 | | |
375 | 340 | | |
376 | 341 | | |
| |||
415 | 380 | | |
416 | 381 | | |
417 | 382 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | 383 | | |
426 | 384 | | |
427 | 385 | | |
| |||
491 | 449 | | |
492 | 450 | | |
493 | 451 | | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | 452 | | |
502 | 453 | | |
503 | 454 | | |
| |||
Lines changed: 3 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
| |||
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
103 | | - | |
| 99 | + | |
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
109 | 105 | | |
110 | 106 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 107 | + | |
| 108 | + | |
115 | 109 | | |
116 | 110 | | |
117 | 111 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9840 | 9840 | | |
9841 | 9841 | | |
9842 | 9842 | | |
9843 | | - | |
9844 | 9843 | | |
9845 | 9844 | | |
9846 | 9845 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9715 | 9715 | | |
9716 | 9716 | | |
9717 | 9717 | | |
9718 | | - | |
9719 | 9718 | | |
9720 | 9719 | | |
9721 | 9720 | | |
| |||
0 commit comments