Skip to content

[Obs AI Assistant] Inject user prompt before tool call when query actions are clicked#227462

Merged
viduni94 merged 6 commits intoelastic:mainfrom
viduni94:query-actions-bug
Jul 11, 2025
Merged

[Obs AI Assistant] Inject user prompt before tool call when query actions are clicked#227462
viduni94 merged 6 commits intoelastic:mainfrom
viduni94:query-actions-bug

Conversation

@viduni94
Copy link
Contributor

@viduni94 viduni94 commented Jul 10, 2025

Closes https://github.com/elastic/obs-ai-assistant-team/issues/309

Summary

This PR improves the Display Results and visualize this query actions by injecting a user prompt first and then the tool call to maintain correct message ordering. This fixes the empty message that was observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be handled separately to avoid breaking the conversation flow.

Testing instructions:

  1. Generate some logs
  2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude 3.5, Claude 3.7, GPT-4, etc)
  3. Ask the assistant to generate a query
  4. Click on Display results -- the results should be shown and the user should be able to continue the conversation
  5. Click on Visualize this query -- the visualization should be shown and the user should be able to continue the conversation

Traces with each model:

image
Screen.Recording.2025-07-10.at.1.17.47.PM.mov
image image image image image

Checklist

  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

@viduni94 viduni94 changed the title Inject user prompt before tool call when visualize query is clicked [Obs AI Assistant] Inject user prompt before tool call when visualize query is clicked Jul 10, 2025
@viduni94 viduni94 self-assigned this Jul 10, 2025
@viduni94
Copy link
Contributor Author

Also tested auto visualization:

Screen.Recording.2025-07-10.at.12.22.21.PM.mov

@viduni94 viduni94 force-pushed the query-actions-bug branch from 6a40d44 to de1dd09 Compare July 10, 2025 16:51
@viduni94 viduni94 changed the title [Obs AI Assistant] Inject user prompt before tool call when visualize query is clicked [Obs AI Assistant] Inject user prompt before tool call when query actions are clicked Jul 10, 2025
@viduni94 viduni94 marked this pull request as ready for review July 10, 2025 17:20
@viduni94 viduni94 requested review from a team as code owners July 10, 2025 17:20
@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Jul 10, 2025
@github-actions
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@viduni94 viduni94 added Team:Obs AI Assistant Observability AI Assistant backport:version Backport to applied version labels v9.1.0 v8.19.0 v9.2.0 v8.18.4 v9.0.4 and removed ci:project-deploy-observability Create an Observability project labels Jul 10, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@github-actions
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 10, 2025

💚 Build Succeeded

  • Buildkite Build
  • Commit: 7136d4a
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-227462-7136d4a8ffd5

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observabilityAIAssistantApp 176.4KB 176.7KB +307.0B
searchAssistant 102.9KB 103.2KB +307.0B
total +614.0B

History

cc @viduni94

@neptunian
Copy link
Contributor

Tested on Elastic Managed LLM, Bedrock 3.5 v2, Bedrock 3.7, Azture gpt4o. Confirmed no longer seeing the behavior with 2 events and no response when clicking Display Results in Claude models.

@viduni94
Copy link
Contributor Author

Tested on Elastic Managed LLM, Bedrock 3.5 v2, Bedrock 3.7, Azture gpt4o. Confirmed no longer seeing the behavior with 2 events and no response when clicking Display Results in Claude models.

Thanks a lot for testing @neptunian

@eleonoramicozzi
Copy link
Contributor

I tested this with Azure GPT4o, Gemini 2.5, Claude 3.5, Claude 3.7 and Elastic Managed LLM and it worked in all cases :)

@viduni94
Copy link
Contributor Author

viduni94 commented Jul 11, 2025

I tested this with Azure GPT4o, Gemini 2.5, Claude 3.5, Claude 3.7 and Elastic Managed LLM and it worked in all cases :)

Thanks a lot for testing @eleonoramicozzi

@viduni94
Copy link
Contributor Author

Final testing:

  • Contextual insights response generation and continuing the conversation
  • Starter prompts
  • Display results when a query is generated
  • Visualize this query when a query is generated
  • Continue the conversation after both actions above
  • Automatic execution after a query is generated
  • Automatic visualization after a query is generated
  • Continue the conversation after both scenarios above

@viduni94 viduni94 merged commit 021b308 into elastic:main Jul 11, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.18, 8.19, 9.0, 9.1

https://github.com/elastic/kibana/actions/runs/16219962728

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 11, 2025
…ions are clicked (elastic#227462)

Closes elastic/obs-ai-team#309

## Summary

This PR improves the `Display Results` and `visualize this query`
actions by injecting a user prompt first and then the tool call to
maintain correct message ordering. This fixes the empty message that was
observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be
handled separately to avoid breaking the conversation flow.

## Testing instructions:
1. Generate some logs
2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude
3.5, Claude 3.7, GPT-4, etc)
3. Ask the assistant to generate a query
4. Click on `Display results` -- the results should be shown and the
user should be able to continue the conversation
5. Click on `Visualize this query` -- the visualization should be shown
and the user should be able to continue the conversation

## Traces with each model:

- EIS (Visualize this query) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D
<img width="715" height="868" alt="image"
src="https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da"
/>

- EIS (Display results) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D

https://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669

- Bedrock+Claude 3.7 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D
<img width="709" height="889" alt="image"
src="https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227"
/>

- Bedrock+Claude 3.5 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D
<img width="714" height="942" alt="image"
src="https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139"
/>

- AzureOpenAI+GPT 4.1 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D
<img width="715" height="877" alt="image"
src="https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d"
/>

- Gemini 2.0 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D
<img width="709" height="880" alt="image"
src="https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b"
/>

- Gemini 2.5 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D
<img width="708" height="872" alt="image"
src="https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061"
/>

### Checklist

- [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

(cherry picked from commit 021b308)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 11, 2025
…ions are clicked (elastic#227462)

Closes elastic/obs-ai-team#309

## Summary

This PR improves the `Display Results` and `visualize this query`
actions by injecting a user prompt first and then the tool call to
maintain correct message ordering. This fixes the empty message that was
observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be
handled separately to avoid breaking the conversation flow.

## Testing instructions:
1. Generate some logs
2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude
3.5, Claude 3.7, GPT-4, etc)
3. Ask the assistant to generate a query
4. Click on `Display results` -- the results should be shown and the
user should be able to continue the conversation
5. Click on `Visualize this query` -- the visualization should be shown
and the user should be able to continue the conversation

## Traces with each model:

- EIS (Visualize this query) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D
<img width="715" height="868" alt="image"
src="https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da"
/>

- EIS (Display results) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D

https://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669

- Bedrock+Claude 3.7 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D
<img width="709" height="889" alt="image"
src="https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227"
/>

- Bedrock+Claude 3.5 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D
<img width="714" height="942" alt="image"
src="https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139"
/>

- AzureOpenAI+GPT 4.1 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D
<img width="715" height="877" alt="image"
src="https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d"
/>

- Gemini 2.0 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D
<img width="709" height="880" alt="image"
src="https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b"
/>

- Gemini 2.5 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D
<img width="708" height="872" alt="image"
src="https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061"
/>

### Checklist

- [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

(cherry picked from commit 021b308)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 11, 2025
…ions are clicked (elastic#227462)

Closes elastic/obs-ai-team#309

## Summary

This PR improves the `Display Results` and `visualize this query`
actions by injecting a user prompt first and then the tool call to
maintain correct message ordering. This fixes the empty message that was
observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be
handled separately to avoid breaking the conversation flow.

## Testing instructions:
1. Generate some logs
2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude
3.5, Claude 3.7, GPT-4, etc)
3. Ask the assistant to generate a query
4. Click on `Display results` -- the results should be shown and the
user should be able to continue the conversation
5. Click on `Visualize this query` -- the visualization should be shown
and the user should be able to continue the conversation

## Traces with each model:

- EIS (Visualize this query) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D
<img width="715" height="868" alt="image"
src="https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da"
/>

- EIS (Display results) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D

https://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669

- Bedrock+Claude 3.7 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D
<img width="709" height="889" alt="image"
src="https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227"
/>

- Bedrock+Claude 3.5 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D
<img width="714" height="942" alt="image"
src="https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139"
/>

- AzureOpenAI+GPT 4.1 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D
<img width="715" height="877" alt="image"
src="https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d"
/>

- Gemini 2.0 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D
<img width="709" height="880" alt="image"
src="https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b"
/>

- Gemini 2.5 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D
<img width="708" height="872" alt="image"
src="https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061"
/>

### Checklist

- [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

(cherry picked from commit 021b308)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.18 Backport failed because of merge conflicts
8.19
9.0
9.1

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 227462

Questions ?

Please refer to the Backport tool documentation

@viduni94
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.18

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

viduni94 added a commit to viduni94/kibana that referenced this pull request Jul 11, 2025
…ions are clicked (elastic#227462)

Closes elastic/obs-ai-team#309

## Summary

This PR improves the `Display Results` and `visualize this query`
actions by injecting a user prompt first and then the tool call to
maintain correct message ordering. This fixes the empty message that was
observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be
handled separately to avoid breaking the conversation flow.

## Testing instructions:
1. Generate some logs
2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude
3.5, Claude 3.7, GPT-4, etc)
3. Ask the assistant to generate a query
4. Click on `Display results` -- the results should be shown and the
user should be able to continue the conversation
5. Click on `Visualize this query` -- the visualization should be shown
and the user should be able to continue the conversation

## Traces with each model:

- EIS (Visualize this query) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D
<img width="715" height="868" alt="image"
src="https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da"
/>

- EIS (Display results) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D

https://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669

- Bedrock+Claude 3.7 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D
<img width="709" height="889" alt="image"
src="https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227"
/>

- Bedrock+Claude 3.5 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D
<img width="714" height="942" alt="image"
src="https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139"
/>

- AzureOpenAI+GPT 4.1 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D
<img width="715" height="877" alt="image"
src="https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d"
/>

- Gemini 2.0 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D
<img width="709" height="880" alt="image"
src="https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b"
/>

- Gemini 2.5 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D
<img width="708" height="872" alt="image"
src="https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061"
/>

### Checklist

- [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

(cherry picked from commit 021b308)

# Conflicts:
#	x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_body.tsx
kibanamachine added a commit that referenced this pull request Jul 11, 2025
…ery actions are clicked (#227462) (#227641)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Obs AI Assistant] Inject user prompt before tool call when query
actions are clicked
(#227462)](#227462)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"viduni.wickramarachchi@elastic.co"},"sourceCommit":{"committedDate":"2025-07-11T12:25:04Z","message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v9.2.0","v8.18.4","v9.0.4"],"title":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked","number":227462,"url":"https://github.com/elastic/kibana/pull/227462","mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227462","number":227462,"mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},{"branch":"8.18","label":"v8.18.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
kibanamachine added a commit that referenced this pull request Jul 11, 2025
…ry actions are clicked (#227462) (#227643)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[Obs AI Assistant] Inject user prompt before tool call when query
actions are clicked
(#227462)](#227462)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"viduni.wickramarachchi@elastic.co"},"sourceCommit":{"committedDate":"2025-07-11T12:25:04Z","message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v9.2.0","v8.18.4","v9.0.4"],"title":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked","number":227462,"url":"https://github.com/elastic/kibana/pull/227462","mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227462","number":227462,"mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},{"branch":"8.18","label":"v8.18.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
kibanamachine added a commit that referenced this pull request Jul 11, 2025
…ry actions are clicked (#227462) (#227642)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Obs AI Assistant] Inject user prompt before tool call when query
actions are clicked
(#227462)](#227462)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"viduni.wickramarachchi@elastic.co"},"sourceCommit":{"committedDate":"2025-07-11T12:25:04Z","message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v9.2.0","v8.18.4","v9.0.4"],"title":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked","number":227462,"url":"https://github.com/elastic/kibana/pull/227462","mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227462","number":227462,"mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},{"branch":"8.18","label":"v8.18.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
viduni94 added a commit that referenced this pull request Jul 11, 2025
…ery actions are clicked (#227462) (#227649)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Obs AI Assistant] Inject user prompt before tool call when query
actions are clicked
(#227462)](#227462)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"viduni.wickramarachchi@elastic.co"},"sourceCommit":{"committedDate":"2025-07-11T12:25:04Z","message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v9.2.0","v8.18.4","v9.0.4"],"title":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked","number":227462,"url":"https://github.com/elastic/kibana/pull/227462","mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},"sourceBranch":"main","suggestedTargetBranches":["8.18"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/227643","number":227643,"state":"OPEN"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/227641","number":227641,"state":"OPEN"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227462","number":227462,"mergeCommit":{"message":"[Obs
AI Assistant] Inject user prompt before tool call when query actions are
clicked (#227462)\n\nCloses
https://github.com/elastic/obs-ai-assistant-team/issues/309\n\n##
Summary\n\nThis PR improves the `Display Results` and `visualize this
query`\nactions by injecting a user prompt first and then the tool call
to\nmaintain correct message ordering. This fixes the empty message that
was\nobserved when visualize this query was clicked.\n\nHowever, in any
case, if an empty message is received this should be\nhandled separately
to avoid breaking the conversation flow.\n\n## Testing instructions:\n1.
Generate some logs\n2. Pick the LLM (Needs to be tested with Elastic
Managed LLM, Claude\n3.5, Claude 3.7, GPT-4, etc)\n3. Ask the assistant
to generate a query\n4. Click on `Display results` -- the results should
be shown and the\nuser should be able to continue the conversation\n5.
Click on `Visualize this query` -- the visualization should be
shown\nand the user should be able to continue the conversation\n\n##
Traces with each model:\n\n- EIS (Visualize this query)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D\n<img
width=\"715\" height=\"868\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da\"\n/>\n\n-
EIS (Display results)
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D\n\n\nhttps://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669\n\n-
Bedrock+Claude 3.7
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D\n<img
width=\"709\" height=\"889\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227\"\n/>\n\n\n-
Bedrock+Claude 3.5
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D\n<img
width=\"714\" height=\"942\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139\"\n/>\n\n\n-
AzureOpenAI+GPT 4.1
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D\n<img
width=\"715\" height=\"877\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d\"\n/>\n\n\n-
Gemini 2.0 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D\n<img
width=\"709\" height=\"880\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b\"\n/>\n\n-
Gemini 2.5 Flash
-\nhttps://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D\n<img
width=\"708\" height=\"872\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061\"\n/>\n\n\n###
Checklist\n\n- [x] The PR description includes the appropriate Release
Notes section,\nand the correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*`
labels.","sha":"021b30816e86ddb2e1fa2a8c911ff85ab07e1d43"}},{"branch":"8.18","label":"v8.18.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/227642","number":227642,"state":"OPEN"}]}]
BACKPORT-->

---------

Co-authored-by: Brad White <Ikuni17@users.noreply.github.com>
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
…ions are clicked (elastic#227462)

Closes elastic/obs-ai-team#309

## Summary

This PR improves the `Display Results` and `visualize this query`
actions by injecting a user prompt first and then the tool call to
maintain correct message ordering. This fixes the empty message that was
observed when visualize this query was clicked.

However, in any case, if an empty message is received this should be
handled separately to avoid breaking the conversation flow.

## Testing instructions:
1. Generate some logs
2. Pick the LLM (Needs to be tested with Elastic Managed LLM, Claude
3.5, Claude 3.7, GPT-4, etc)
3. Ask the assistant to generate a query
4. Click on `Display results` -- the results should be shown and the
user should be able to continue the conversation
5. Click on `Visualize this query` -- the visualization should be shown
and the user should be able to continue the conversation

## Traces with each model:

- EIS (Visualize this query) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/b1dcb77fb39ad7efbf82d9c4a1feb0e0?selectedSpanNodeId=U3BhbjoyOTk3ODQ%3D
<img width="715" height="868" alt="image"
src="https://github.com/user-attachments/assets/75fd8efe-82df-4f7f-ad4f-f915e09d49da"
/>

- EIS (Display results) -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/e7d8c42774491e6e2bcf328c34203c14?selectedSpanNodeId=U3BhbjozMDAxOTg%3D


https://github.com/user-attachments/assets/6aa520db-2b40-4317-ace0-7be206ebb669

- Bedrock+Claude 3.7 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/f1bc4f490fcc990db9dbddf0782cff7e?selectedSpanNodeId=U3BhbjoyOTk4MDA%3D
<img width="709" height="889" alt="image"
src="https://github.com/user-attachments/assets/86f77ff9-1783-42d3-8b31-8680fd7da227"
/>


- Bedrock+Claude 3.5 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/457a7cc939ce3b18ae3a9e2b066c3a7f?selectedSpanNodeId=U3BhbjoyOTk4MTY%3D
<img width="714" height="942" alt="image"
src="https://github.com/user-attachments/assets/fe96b72e-24d0-4a85-9b42-a9862bdf4139"
/>


- AzureOpenAI+GPT 4.1 -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/de9fc09a6f0162b7b2d6f52fbb188469?selectedSpanNodeId=U3BhbjoyOTk4MzI%3D
<img width="715" height="877" alt="image"
src="https://github.com/user-attachments/assets/cca5326e-9350-426f-9f2e-a407d26e193d"
/>


- Gemini 2.0 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/982da6b0ff4bae04f45af0271aa4cd84?selectedSpanNodeId=U3BhbjoyOTk4NTI%3D
<img width="709" height="880" alt="image"
src="https://github.com/user-attachments/assets/d29b99c7-e3f6-4318-a19b-0a92e7aa690b"
/>

- Gemini 2.5 Flash -
https://35-187-109-62.sslip.io/projects/UHJvamVjdDo5/traces/9f7115cc79bb2e929dbeb93670555e81?selectedSpanNodeId=U3BhbjoyOTk4NjU%3D
<img width="708" height="872" alt="image"
src="https://github.com/user-attachments/assets/4c6e48fd-ccaf-413c-b01d-21c0fc8df061"
/>


### Checklist

- [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants