[8.x] [Obs AI Assistant] Pass function responses when copying conversation (#195635) (#196558)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Obs AI Assistant] Pass function responses when copying conversation
(#195635)](https://github.com/elastic/kibana/pull/195635)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"viduni.wickramarachchi@elastic.co"},"sourceCommit":{"committedDate":"2024-10-16T14:42:09Z","message":"[Obs
AI Assistant] Pass function responses when copying conversation
(#195635)\n\nCloses
https://github.com/elastic/kibana/issues/181216\r\n\r\n##
Summary\r\n\r\n### Problem\r\nFunction call arguments and responses are
serialized separately.\r\nTherefore, when a conversation is copied,
arguments and responses\r\n(`content` and `data`) appear as strings
instead of JSON objects. This\r\nmakes it harder to debug.\r\n\r\n###
Solution\r\nDeserialize the arguments and responses and include it in
the copied\r\nconversation object.\r\n\r\nExample of original copied
conversation:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability....\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.881Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"Give me examples of questions I can ask here.\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.965Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:27.063Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:35.140Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"Sure, here are some examples of questions you can
ask:\\n\\n1. \\\"What is the average response time for my
services?\\\"\\n2. \\\"Show me the error rate for my services.\\\"\\n3.
\\\"Are there any anomalies in my system?\\\"\\n4. \\\"What are the top
5 services by transaction volume?\\\"\\n5. \\\"Show me the logs for a
specific service.\\\"\\n6. \\\"Are there any alerts in my
system?\\\"\\n7. \\\"What is the CPU usage of my hosts?\\\"\\n8.
\\\"Show me the network traffic in my system.\\\"\\n9. \\\"What is the
disk usage of my hosts?\\\"\\n10. \\\"Show me the memory usage of my
containers.\\\"\\n\\nPlease note that the actual questions you can ask
depend on the data you have in your system.\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:41.651Z\",\r\n \"message\": {
\"role\": \"user\", \"content\": \"What are the top 5 services by
transaction volume\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.784Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:43.370Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {\r\n
\"name\": \"get_dataset_info\",\r\n \"arguments\": \"{\\n \\\"index\\\":
\\\"traces-apm*,apm-*,traces-*.otel-*\\\"\\n}\",\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\":
\"{\\\"indices\\\":[],\\\"fields\\\":[]}\" }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": \"{}\", \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"keywords\\\":[\\\"STATS\\\",\\\"SORT\\\",\\\"LIMIT\\\",\\\"COUNT\\\"],\\\"requestedDocumentation\\\":{\\\"STATS\\\":\\\"#
STATS ... BY\\\\n\\\\nThe `STATS ... BY` command groups rows based on a
common value and calculates one or more aggregated values over these
grouped rows.\\\\n\\\\n## Syntax\\\\n\\\\n```esql\\\\nSTATS [column1 =]
expression1[, ..., [columnN =] expressionN] [BY grouping_expression1[,
..., grouping_expressionN]]\\\\n```\\\\n\\\\n###
Parameters\\\\n\\\\n#### columnX\\\\n\\\\nThe name for the aggregated
value in the output. If not provided....\"}}\",\r\n \"name\":
\"query\",\r\n \"content\": \"{}\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": \"{\\\"query\\\":\\\"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\\\"}\",\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\":
\"{\\\"message\\\":\\\"The query failed to
execute\\\",\\\"error\\\":{\\\"name\\\":\\\"ResponseError\\\",\\\"message\\\":\\\"verification_exception\\\\n\\\\tRoot
causes:\\\\n\\\\t\\\\tverification_exception: Found 1 problem\\\\nline
1:1: Unknown index [traces-apm*,apm-*,traces-*.otel-*]\\\"}}\"\r\n }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>\r\n<br/>\r\nCopied conversation after
deserializing:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability. Your goal is to help the Elastic Observability users to
quickly assess what is happening in their observed systems...\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.881Z\",\r\n
\"message\": { \"role\": \"user\", \"content\": \"Give me examples of
questions I can ask here.\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.965Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:27.063Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": { \"scores\": [], \"suggestions\": [] },\r\n
\"name\": \"context\",\r\n \"content\": {\r\n \"screen_description\":
\"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:35.140Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"\", \"arguments\":
\"\", \"trigger\": \"assistant\" },\r\n \"content\": \"Sure, here are
some examples of questions...\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.651Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"What are the top 5 services by transaction volume\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.723Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.784Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\": { \"scores\": [],
\"suggestions\": [] },\r\n \"name\": \"context\",\r\n \"content\": {\r\n
\"screen_description\": \"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.370Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"get_dataset_info\",\r\n \"arguments\": { \"index\":
\"traces-apm*,apm-*,traces-*.otel-*\" },\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\": {
\"indices\": [], \"fields\": [] } }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": {}, \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": {\r\n \"keywords\": [\"STATS\", \"SORT\",
\"LIMIT\", \"COUNT\"],\r\n \"requestedDocumentation\": {\r\n \"STATS\":
\"# STATS ... BY\\n\\nThe `STATS ... BY`...\",\r\n \"SORT\": \"#
SORT\\n\\nThe SORT command...\",\r\n \"LIMIT\": \"# LIMIT\\n\\nThe LIMIT
command...\",\r\n \"COUNT\": \"# COUNT\\n\\n....\",\r\n \"SYNTAX\": \"#
ES|QL Syntax Guide....\",\r\n \"OVERVIEW\": \"## ES|QL Overview\\n\\n###
ES|QL....\",\r\n \"OPERATORS\": \"# ES|QL Operators\\n\\nThis
document....\"\r\n }\r\n },\r\n \"name\": \"query\",\r\n \"content\":
{}\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": {\r\n \"query\": \"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\"\r\n },\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\": {\r\n
\"message\": \"The query failed to execute\",\r\n \"error\": {\r\n
\"name\": \"ResponseError\",\r\n \"message\":
\"verification_exception\\n\\tRoot
causes:\\n\\t\\tverification_exception: Found 1 problem\\nline 1:1:
Unknown index [traces-apm*,apm-*,traces-*.otel-*]\"\r\n }\r\n }\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>","sha":"e34876aa6809a5ea79a836ce61e94192a4769d59","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:prev-minor","Team:Obs
AI Assistant","ci:project-deploy-observability"],"title":"[Obs AI
Assistant] Pass function responses when copying
conversation","number":195635,"url":"https://github.com/elastic/kibana/pull/195635","mergeCommit":{"message":"[Obs
AI Assistant] Pass function responses when copying conversation
(#195635)\n\nCloses
https://github.com/elastic/kibana/issues/181216\r\n\r\n##
Summary\r\n\r\n### Problem\r\nFunction call arguments and responses are
serialized separately.\r\nTherefore, when a conversation is copied,
arguments and responses\r\n(`content` and `data`) appear as strings
instead of JSON objects. This\r\nmakes it harder to debug.\r\n\r\n###
Solution\r\nDeserialize the arguments and responses and include it in
the copied\r\nconversation object.\r\n\r\nExample of original copied
conversation:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability....\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.881Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"Give me examples of questions I can ask here.\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.965Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:27.063Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:35.140Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"Sure, here are some examples of questions you can
ask:\\n\\n1. \\\"What is the average response time for my
services?\\\"\\n2. \\\"Show me the error rate for my services.\\\"\\n3.
\\\"Are there any anomalies in my system?\\\"\\n4. \\\"What are the top
5 services by transaction volume?\\\"\\n5. \\\"Show me the logs for a
specific service.\\\"\\n6. \\\"Are there any alerts in my
system?\\\"\\n7. \\\"What is the CPU usage of my hosts?\\\"\\n8.
\\\"Show me the network traffic in my system.\\\"\\n9. \\\"What is the
disk usage of my hosts?\\\"\\n10. \\\"Show me the memory usage of my
containers.\\\"\\n\\nPlease note that the actual questions you can ask
depend on the data you have in your system.\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:41.651Z\",\r\n \"message\": {
\"role\": \"user\", \"content\": \"What are the top 5 services by
transaction volume\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.784Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:43.370Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {\r\n
\"name\": \"get_dataset_info\",\r\n \"arguments\": \"{\\n \\\"index\\\":
\\\"traces-apm*,apm-*,traces-*.otel-*\\\"\\n}\",\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\":
\"{\\\"indices\\\":[],\\\"fields\\\":[]}\" }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": \"{}\", \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"keywords\\\":[\\\"STATS\\\",\\\"SORT\\\",\\\"LIMIT\\\",\\\"COUNT\\\"],\\\"requestedDocumentation\\\":{\\\"STATS\\\":\\\"#
STATS ... BY\\\\n\\\\nThe `STATS ... BY` command groups rows based on a
common value and calculates one or more aggregated values over these
grouped rows.\\\\n\\\\n## Syntax\\\\n\\\\n```esql\\\\nSTATS [column1 =]
expression1[, ..., [columnN =] expressionN] [BY grouping_expression1[,
..., grouping_expressionN]]\\\\n```\\\\n\\\\n###
Parameters\\\\n\\\\n#### columnX\\\\n\\\\nThe name for the aggregated
value in the output. If not provided....\"}}\",\r\n \"name\":
\"query\",\r\n \"content\": \"{}\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": \"{\\\"query\\\":\\\"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\\\"}\",\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\":
\"{\\\"message\\\":\\\"The query failed to
execute\\\",\\\"error\\\":{\\\"name\\\":\\\"ResponseError\\\",\\\"message\\\":\\\"verification_exception\\\\n\\\\tRoot
causes:\\\\n\\\\t\\\\tverification_exception: Found 1 problem\\\\nline
1:1: Unknown index [traces-apm*,apm-*,traces-*.otel-*]\\\"}}\"\r\n }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>\r\n<br/>\r\nCopied conversation after
deserializing:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability. Your goal is to help the Elastic Observability users to
quickly assess what is happening in their observed systems...\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.881Z\",\r\n
\"message\": { \"role\": \"user\", \"content\": \"Give me examples of
questions I can ask here.\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.965Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:27.063Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": { \"scores\": [], \"suggestions\": [] },\r\n
\"name\": \"context\",\r\n \"content\": {\r\n \"screen_description\":
\"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:35.140Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"\", \"arguments\":
\"\", \"trigger\": \"assistant\" },\r\n \"content\": \"Sure, here are
some examples of questions...\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.651Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"What are the top 5 services by transaction volume\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.723Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.784Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\": { \"scores\": [],
\"suggestions\": [] },\r\n \"name\": \"context\",\r\n \"content\": {\r\n
\"screen_description\": \"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.370Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"get_dataset_info\",\r\n \"arguments\": { \"index\":
\"traces-apm*,apm-*,traces-*.otel-*\" },\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\": {
\"indices\": [], \"fields\": [] } }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": {}, \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": {\r\n \"keywords\": [\"STATS\", \"SORT\",
\"LIMIT\", \"COUNT\"],\r\n \"requestedDocumentation\": {\r\n \"STATS\":
\"# STATS ... BY\\n\\nThe `STATS ... BY`...\",\r\n \"SORT\": \"#
SORT\\n\\nThe SORT command...\",\r\n \"LIMIT\": \"# LIMIT\\n\\nThe LIMIT
command...\",\r\n \"COUNT\": \"# COUNT\\n\\n....\",\r\n \"SYNTAX\": \"#
ES|QL Syntax Guide....\",\r\n \"OVERVIEW\": \"## ES|QL Overview\\n\\n###
ES|QL....\",\r\n \"OPERATORS\": \"# ES|QL Operators\\n\\nThis
document....\"\r\n }\r\n },\r\n \"name\": \"query\",\r\n \"content\":
{}\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": {\r\n \"query\": \"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\"\r\n },\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\": {\r\n
\"message\": \"The query failed to execute\",\r\n \"error\": {\r\n
\"name\": \"ResponseError\",\r\n \"message\":
\"verification_exception\\n\\tRoot
causes:\\n\\t\\tverification_exception: Found 1 problem\\nline 1:1:
Unknown index [traces-apm*,apm-*,traces-*.otel-*]\"\r\n }\r\n }\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>","sha":"e34876aa6809a5ea79a836ce61e94192a4769d59"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195635","number":195635,"mergeCommit":{"message":"[Obs
AI Assistant] Pass function responses when copying conversation
(#195635)\n\nCloses
https://github.com/elastic/kibana/issues/181216\r\n\r\n##
Summary\r\n\r\n### Problem\r\nFunction call arguments and responses are
serialized separately.\r\nTherefore, when a conversation is copied,
arguments and responses\r\n(`content` and `data`) appear as strings
instead of JSON objects. This\r\nmakes it harder to debug.\r\n\r\n###
Solution\r\nDeserialize the arguments and responses and include it in
the copied\r\nconversation object.\r\n\r\nExample of original copied
conversation:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability....\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.881Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"Give me examples of questions I can ask here.\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.965Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:27.063Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:35.140Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"Sure, here are some examples of questions you can
ask:\\n\\n1. \\\"What is the average response time for my
services?\\\"\\n2. \\\"Show me the error rate for my services.\\\"\\n3.
\\\"Are there any anomalies in my system?\\\"\\n4. \\\"What are the top
5 services by transaction volume?\\\"\\n5. \\\"Show me the logs for a
specific service.\\\"\\n6. \\\"Are there any alerts in my
system?\\\"\\n7. \\\"What is the CPU usage of my hosts?\\\"\\n8.
\\\"Show me the network traffic in my system.\\\"\\n9. \\\"What is the
disk usage of my hosts?\\\"\\n10. \\\"Show me the memory usage of my
containers.\\\"\\n\\nPlease note that the actual questions you can ask
depend on the data you have in your system.\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:41.651Z\",\r\n \"message\": {
\"role\": \"user\", \"content\": \"What are the top 5 services by
transaction volume\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.784Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"scores\\\":[],\\\"suggestions\\\":[]}\",\r\n \"name\":
\"context\",\r\n \"content\": \"{\\\"screen_description\\\":\\\"The user
is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\\\n\\\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\\\\\"universal_profiling\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"uptime\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"heartbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_metrics\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"metrics-*,metricbeat-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"alert\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"apm\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":{\\\\\\\"transaction\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"span\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*\\\\\\\",\\\\\\\"error\\\\\\\":\\\\\\\"logs-apm*,apm-*,logs-*.otel-*\\\\\\\",\\\\\\\"metric\\\\\\\":\\\\\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"onboarding\\\\\\\":\\\\\\\"apm-*\\\\\\\",\\\\\\\"sourcemap\\\\\\\":\\\\\\\"apm-*\\\\\\\"},\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"ux\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"},\\\\\\\"infra_logs\\\\\\\":{\\\\\\\"hasData\\\\\\\":false,\\\\\\\"indices\\\\\\\":\\\\\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\\\\\",\\\\\\\"status\\\\\\\":\\\\\\\"success\\\\\\\"}}\\\",\\\"learnings\\\":[]}\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:43.370Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {\r\n
\"name\": \"get_dataset_info\",\r\n \"arguments\": \"{\\n \\\"index\\\":
\\\"traces-apm*,apm-*,traces-*.otel-*\\\"\\n}\",\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\":
\"{\\\"indices\\\":[],\\\"fields\\\":[]}\" }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": \"{}\", \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\":
\"{\\\"keywords\\\":[\\\"STATS\\\",\\\"SORT\\\",\\\"LIMIT\\\",\\\"COUNT\\\"],\\\"requestedDocumentation\\\":{\\\"STATS\\\":\\\"#
STATS ... BY\\\\n\\\\nThe `STATS ... BY` command groups rows based on a
common value and calculates one or more aggregated values over these
grouped rows.\\\\n\\\\n## Syntax\\\\n\\\\n```esql\\\\nSTATS [column1 =]
expression1[, ..., [columnN =] expressionN] [BY grouping_expression1[,
..., grouping_expressionN]]\\\\n```\\\\n\\\\n###
Parameters\\\\n\\\\n#### columnX\\\\n\\\\nThe name for the aggregated
value in the output. If not provided....\"}}\",\r\n \"name\":
\"query\",\r\n \"content\": \"{}\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n
\"role\": \"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": \"{\\\"query\\\":\\\"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\\\"}\",\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\":
\"{\\\"message\\\":\\\"The query failed to
execute\\\",\\\"error\\\":{\\\"name\\\":\\\"ResponseError\\\",\\\"message\\\":\\\"verification_exception\\\\n\\\\tRoot
causes:\\\\n\\\\t\\\\tverification_exception: Found 1 problem\\\\nline
1:1: Unknown index [traces-apm*,apm-*,traces-*.otel-*]\\\"}}\"\r\n }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>\r\n<br/>\r\nCopied conversation after
deserializing:\r\n<details>\r\n <summary>Click to expand
JSON</summary>\r\n\r\n```json\r\n{\r\n \"title\": \"\",\r\n
\"messages\": [\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.723Z\",\r\n \"message\": {\r\n \"role\":
\"system\",\r\n \"content\": \"You are a helpful assistant for Elastic
Observability. Your goal is to help the Elastic Observability users to
quickly assess what is happening in their observed systems...\"\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:26.881Z\",\r\n
\"message\": { \"role\": \"user\", \"content\": \"Give me examples of
questions I can ask here.\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:26.965Z\",\r\n \"message\": { \"role\":
\"assistant\", \"function_call\": { \"name\": \"context\", \"trigger\":
\"assistant\" }, \"content\": \"\" }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:27.063Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": { \"scores\": [], \"suggestions\": [] },\r\n
\"name\": \"context\",\r\n \"content\": {\r\n \"screen_description\":
\"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:35.140Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"\", \"arguments\":
\"\", \"trigger\": \"assistant\" },\r\n \"content\": \"Sure, here are
some examples of questions...\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:41.651Z\",\r\n \"message\": { \"role\": \"user\",
\"content\": \"What are the top 5 services by transaction volume\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.723Z\",\r\n
\"message\": { \"role\": \"assistant\", \"function_call\": { \"name\":
\"context\", \"trigger\": \"assistant\" }, \"content\": \"\" }\r\n
},\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:41.784Z\",\r\n
\"message\": {\r\n \"role\": \"user\",\r\n \"data\": { \"scores\": [],
\"suggestions\": [] },\r\n \"name\": \"context\",\r\n \"content\": {\r\n
\"screen_description\": \"The user is looking at
http://localhost:5601/kyq/app/observability/overview?rangeFrom=now-15m&rangeTo=now.
The current time range is 2024-10-09T13:40:00.288Z -
2024-10-09T13:55:00.288Z.\\n\\nThe user is viewing the Overview page
which shows a summary of the following apps:
{\\\"universal_profiling\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"uptime\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"heartbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_metrics\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"metrics-*,metricbeat-*\\\",\\\"status\\\":\\\"success\\\"},\\\"alert\\\":{\\\"hasData\\\":false,\\\"status\\\":\\\"success\\\"},\\\"apm\\\":{\\\"hasData\\\":false,\\\"indices\\\":{\\\"transaction\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"span\\\":\\\"traces-apm*,apm-*,traces-*.otel-*\\\",\\\"error\\\":\\\"logs-apm*,apm-*,logs-*.otel-*\\\",\\\"metric\\\":\\\"metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"onboarding\\\":\\\"apm-*\\\",\\\"sourcemap\\\":\\\"apm-*\\\"},\\\"status\\\":\\\"success\\\"},\\\"ux\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-*.otel-*,metrics-apm*,apm-*,metrics-*.otel-*\\\",\\\"status\\\":\\\"success\\\"},\\\"infra_logs\\\":{\\\"hasData\\\":false,\\\"indices\\\":\\\"logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*\\\",\\\"status\\\":\\\"success\\\"}}\",\r\n
\"learnings\": []\r\n }\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.370Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"get_dataset_info\",\r\n \"arguments\": { \"index\":
\"traces-apm*,apm-*,traces-*.otel-*\" },\r\n \"trigger\":
\"assistant\"\r\n },\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n
\"@timestamp\": \"2024-10-09T13:58:43.379Z\",\r\n \"message\": {
\"role\": \"user\", \"name\": \"get_dataset_info\", \"content\": {
\"indices\": [], \"fields\": [] } }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:43.998Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": { \"name\": \"query\",
\"arguments\": {}, \"trigger\": \"assistant\" },\r\n \"content\":
\"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:47.572Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"data\": {\r\n \"keywords\": [\"STATS\", \"SORT\",
\"LIMIT\", \"COUNT\"],\r\n \"requestedDocumentation\": {\r\n \"STATS\":
\"# STATS ... BY\\n\\nThe `STATS ... BY`...\",\r\n \"SORT\": \"#
SORT\\n\\nThe SORT command...\",\r\n \"LIMIT\": \"# LIMIT\\n\\nThe LIMIT
command...\",\r\n \"COUNT\": \"# COUNT\\n\\n....\",\r\n \"SYNTAX\": \"#
ES|QL Syntax Guide....\",\r\n \"OVERVIEW\": \"## ES|QL Overview\\n\\n###
ES|QL....\",\r\n \"OPERATORS\": \"# ES|QL Operators\\n\\nThis
document....\"\r\n }\r\n },\r\n \"name\": \"query\",\r\n \"content\":
{}\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.481Z\",\r\n \"message\": {\r\n \"role\":
\"assistant\",\r\n \"function_call\": {\r\n \"name\":
\"execute_query\",\r\n \"arguments\": {\r\n \"query\": \"FROM
traces-apm*,apm-*,traces-*.otel-* | STATS COUNT(*) BY service.name |
SORT COUNT(*) DESC | LIMIT 5\"\r\n },\r\n \"trigger\": \"assistant\"\r\n
},\r\n \"content\": \"\"\r\n }\r\n },\r\n {\r\n \"@timestamp\":
\"2024-10-09T13:58:51.619Z\",\r\n \"message\": {\r\n \"role\":
\"user\",\r\n \"name\": \"execute_query\",\r\n \"content\": {\r\n
\"message\": \"The query failed to execute\",\r\n \"error\": {\r\n
\"name\": \"ResponseError\",\r\n \"message\":
\"verification_exception\\n\\tRoot
causes:\\n\\t\\tverification_exception: Found 1 problem\\nline 1:1:
Unknown index [traces-apm*,apm-*,traces-*.otel-*]\"\r\n }\r\n }\r\n
}\r\n },\r\n {\r\n \"@timestamp\": \"2024-10-09T13:58:56.600Z\",\r\n
\"message\": {\r\n \"role\": \"assistant\",\r\n \"function_call\": {
\"name\": \"\", \"arguments\": \"\", \"trigger\": \"assistant\" },\r\n
\"content\": \"I'm sorry, but it seems like there are no indices
matching the pattern \\\"traces-apm*,apm-*,traces-*.otel-*\\\" in your
system. Therefore, I'm unable to retrieve the top 5 services by
transaction volume. Please ensure that your APM data is being ingested
correctly into Elasticsearch.\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n</details>","sha":"e34876aa6809a5ea79a836ce61e94192a4769d59"}}]}]
BACKPORT-->

Co-authored-by: Viduni Wickramarachchi <viduni.wickramarachchi@elastic.co>
This commit is contained in:
Kibana Machine 2024-10-17 03:29:34 +11:00 committed by GitHub
parent 7059fcab53
commit 24d9229d0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 157 additions and 1 deletions

View file

@ -45,6 +45,7 @@ import { SimulatedFunctionCallingCallout } from './simulated_function_calling_ca
import { WelcomeMessage } from './welcome_message';
import { useLicense } from '../hooks/use_license';
import { PromptEditor } from '../prompt_editor/prompt_editor';
import { deserializeMessage } from '../utils/deserialize_message';
const fullHeightClassName = css`
height: 100%;
@ -226,9 +227,11 @@ export function ChatBody({
});
const handleCopyConversation = () => {
const deserializedMessages = (conversation.value?.messages ?? messages).map(deserializeMessage);
const content = JSON.stringify({
title: initialTitle,
messages: conversation.value?.messages ?? messages,
messages: deserializedMessages,
});
navigator.clipboard?.writeText(content || '');

View file

@ -0,0 +1,118 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { cloneDeep } from 'lodash';
import { Message, MessageRole } from '@kbn/observability-ai-assistant-plugin/common';
import { deserializeMessage } from './deserialize_message';
import { safeJsonParse } from './safe_json_parse';
jest.mock('lodash', () => ({
cloneDeep: jest.fn(),
}));
jest.mock('./safe_json_parse', () => ({
safeJsonParse: jest.fn((value) => {
try {
return JSON.parse(value);
} catch {
return value;
}
}),
}));
describe('deserializeMessage', () => {
const baseMessage: Message = {
'@timestamp': '2024-10-15T00:00:00Z',
message: {
role: MessageRole.User,
content: 'This is a message',
},
};
beforeEach(() => {
(cloneDeep as jest.Mock).mockImplementation((obj) => JSON.parse(JSON.stringify(obj)));
});
it('should clone the original message', () => {
const message = { ...baseMessage };
deserializeMessage(message);
expect(cloneDeep).toHaveBeenCalledWith(message);
});
it('should deserialize function_call.arguments if it is a string', () => {
const messageWithFunctionCall: Message = {
...baseMessage,
message: {
...baseMessage.message,
function_call: {
name: 'testFunction',
arguments: '{"key": "value"}',
trigger: MessageRole.Assistant,
},
},
};
const result = deserializeMessage(messageWithFunctionCall);
expect(safeJsonParse).toHaveBeenCalledWith('{"key": "value"}');
expect(result.message.function_call!.arguments).toEqual({ key: 'value' });
});
it('should deserialize message.content if it is a string', () => {
const messageWithContent: Message = {
...baseMessage,
message: {
...baseMessage.message,
name: 'testMessage',
content: '{"key": "value"}',
},
};
const result = deserializeMessage(messageWithContent);
expect(safeJsonParse).toHaveBeenCalledWith('{"key": "value"}');
expect(result.message.content).toEqual({ key: 'value' });
});
it('should deserialize message.data if it is a string', () => {
const messageWithData: Message = {
...baseMessage,
message: {
...baseMessage.message,
name: 'testMessage',
data: '{"key": "value"}',
},
};
const result = deserializeMessage(messageWithData);
expect(safeJsonParse).toHaveBeenCalledWith('{"key": "value"}');
expect(result.message.data).toEqual({ key: 'value' });
});
it('should return the copied message as is if no deserialization is needed', () => {
const messageWithoutSerialization: Message = {
...baseMessage,
message: {
...baseMessage.message,
function_call: {
name: 'testFunction',
arguments: '',
trigger: MessageRole.Assistant,
},
content: '',
},
};
const result = deserializeMessage(messageWithoutSerialization);
expect(result.message.function_call!.name).toEqual('testFunction');
expect(result.message.function_call!.arguments).toEqual('');
expect(result.message.content).toEqual('');
});
});

View file

@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { cloneDeep } from 'lodash';
import type { Message } from '@kbn/observability-ai-assistant-plugin/common';
import { safeJsonParse } from './safe_json_parse';
export const deserializeMessage = (message: Message): Message => {
const copiedMessage = cloneDeep(message);
if (
copiedMessage.message.function_call?.arguments &&
typeof copiedMessage.message.function_call?.arguments === 'string'
) {
copiedMessage.message.function_call.arguments = safeJsonParse(
copiedMessage.message.function_call.arguments ?? '{}'
);
}
if (copiedMessage.message.name) {
if (copiedMessage.message.content && typeof copiedMessage.message.content === 'string') {
copiedMessage.message.content = safeJsonParse(copiedMessage.message.content);
}
if (copiedMessage.message.data && typeof copiedMessage.message.data === 'string') {
copiedMessage.message.data = safeJsonParse(copiedMessage.message.data);
}
}
return copiedMessage;
};