You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[9.2] [Bug][Inference chat model] Fix format for parallel tool call results. Consecutive tool results need to be merged into a single message (#241103) (#241389)
# Backport
This will backport the following commits from `main` to `9.2`:
- [[Bug][Inference chat model] Fix format for parallel tool call
results. Consecutive tool results need to be merged into a single
message (#241103)](#241103)
<!--- Backport version: 9.6.6 -->
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)
<!--BACKPORT [{"author":{"name":"Kenneth
Kreindler","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-30T22:29:13Z","message":"[Bug][Inference
chat model] Fix format for parallel tool call results. Consecutive tool
results need to be merged into a single message (#241103)\n\n##
Summary\n\nSummarize your PR. If it involves visual changes include a
screenshot or\ngif.\n\nFixes the following issue:\n\n<img width=\"847\"
height=\"395\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c38c89a9-5a81-4a5e-b371-f54fb027de6a\"\n/>\n\n```\nAn
error occurred sending your message.\n\nError calling connector: Status
code: 400. Message: API Error: Bad Request - Expected toolResult blocks
at messages.2.content for the following Ids:
tooluse_440cJcPjQhqjZSH5z5vbMg\n```\n\nFor Bedrock, the tool results
from parallel tool calls need to be merged\ninto a single message
containing all of the tool results in the content\narray. Without this,
the Bedrock API raises an
error.\n\n<details>\n\n<summary>Example</summary>\n\n###
Incorrect\n\n```\n[ \n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"Error:
index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n }\n ]\n },\n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"[].\"\n }\n }\n ]\n
}\n }\n ]\n }\n]\n```\n\n### Correct\n\n```\n {\n \"role\": \"user\",\n
\"content\": [\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"Error: index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n },\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"[].\"\n }\n }\n ]\n }\n }\n ]\n
}\n```\n\n</details>\n\n### How to test:\n- Create an Amazon Bedrock
connector with Sonnet 4.5\n- Open an AI assistant and ask a question
that produces parallel tool\ncalls. e.g.\n```\nCan you get me the count
of my alerts and tell me how many acknowledged alerts I have? Call both
tools in parallel. When making the parallel tool calls, also explain
what you are doing. Always call both tools.\n```\nCheck this a few times
and ensure there are no errors.\n\n### Checklist\n\nCheck the PR
satisfies following conditions. \n\nReviewers should verify this PR
satisfies this list as well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\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.\n\n### Identify risks\n\nDoes this
PR introduce any risks? For example, consider risks like hard\nto test
bugs, performance regression, potential of data loss.\n\nDescribe the
risk, its severity, and mitigation for each identified\nrisk. Invite
stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See
some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine
<[email protected]>\nCo-authored-by: Quynh Nguyen
<[email protected]>","sha":"c78f74a7f227019ad12e923513c912172092d902","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Security
Generative
AI","backport:version","v9.1.0","v8.19.0","v9.2.0","v9.3.0"],"title":"[Bug][Inference
chat model] Fix format for parallel tool call results. Consecutive tool
results need to be merged into a single
message","number":241103,"url":"https://github.com/elastic/kibana/pull/241103","mergeCommit":{"message":"[Bug][Inference
chat model] Fix format for parallel tool call results. Consecutive tool
results need to be merged into a single message (#241103)\n\n##
Summary\n\nSummarize your PR. If it involves visual changes include a
screenshot or\ngif.\n\nFixes the following issue:\n\n<img width=\"847\"
height=\"395\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c38c89a9-5a81-4a5e-b371-f54fb027de6a\"\n/>\n\n```\nAn
error occurred sending your message.\n\nError calling connector: Status
code: 400. Message: API Error: Bad Request - Expected toolResult blocks
at messages.2.content for the following Ids:
tooluse_440cJcPjQhqjZSH5z5vbMg\n```\n\nFor Bedrock, the tool results
from parallel tool calls need to be merged\ninto a single message
containing all of the tool results in the content\narray. Without this,
the Bedrock API raises an
error.\n\n<details>\n\n<summary>Example</summary>\n\n###
Incorrect\n\n```\n[ \n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"Error:
index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n }\n ]\n },\n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"[].\"\n }\n }\n ]\n
}\n }\n ]\n }\n]\n```\n\n### Correct\n\n```\n {\n \"role\": \"user\",\n
\"content\": [\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"Error: index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n },\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"[].\"\n }\n }\n ]\n }\n }\n ]\n
}\n```\n\n</details>\n\n### How to test:\n- Create an Amazon Bedrock
connector with Sonnet 4.5\n- Open an AI assistant and ask a question
that produces parallel tool\ncalls. e.g.\n```\nCan you get me the count
of my alerts and tell me how many acknowledged alerts I have? Call both
tools in parallel. When making the parallel tool calls, also explain
what you are doing. Always call both tools.\n```\nCheck this a few times
and ensure there are no errors.\n\n### Checklist\n\nCheck the PR
satisfies following conditions. \n\nReviewers should verify this PR
satisfies this list as well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\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.\n\n### Identify risks\n\nDoes this
PR introduce any risks? For example, consider risks like hard\nto test
bugs, performance regression, potential of data loss.\n\nDescribe the
risk, its severity, and mitigation for each identified\nrisk. Invite
stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See
some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine
<[email protected]>\nCo-authored-by: Quynh Nguyen
<[email protected]>","sha":"c78f74a7f227019ad12e923513c912172092d902"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.2"],"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":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/241103","number":241103,"mergeCommit":{"message":"[Bug][Inference
chat model] Fix format for parallel tool call results. Consecutive tool
results need to be merged into a single message (#241103)\n\n##
Summary\n\nSummarize your PR. If it involves visual changes include a
screenshot or\ngif.\n\nFixes the following issue:\n\n<img width=\"847\"
height=\"395\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c38c89a9-5a81-4a5e-b371-f54fb027de6a\"\n/>\n\n```\nAn
error occurred sending your message.\n\nError calling connector: Status
code: 400. Message: API Error: Bad Request - Expected toolResult blocks
at messages.2.content for the following Ids:
tooluse_440cJcPjQhqjZSH5z5vbMg\n```\n\nFor Bedrock, the tool results
from parallel tool calls need to be merged\ninto a single message
containing all of the tool results in the content\narray. Without this,
the Bedrock API raises an
error.\n\n<details>\n\n<summary>Example</summary>\n\n###
Incorrect\n\n```\n[ \n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"Error:
index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n }\n ]\n },\n {\n \"role\": \"user\",\n \"content\": [\n {\n
\"toolResult\": {\n \"toolUseId\": \"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n
\"content\": [\n {\n \"json\": {\n \"response\": \"[].\"\n }\n }\n ]\n
}\n }\n ]\n }\n]\n```\n\n### Correct\n\n```\n {\n \"role\": \"user\",\n
\"content\": [\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_YdiyO2LeSImJoPDq4UYfSA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"Error: index_not_found_exception\\n\\tRoot
causes:\\n\\t\\tindex_not_found_exception: no such index
[.alerts-security.alerts-12]\\n Please fix your mistakes.\"\n }\n }\n
]\n }\n },\n {\n \"toolResult\": {\n \"toolUseId\":
\"tooluse_VHLTnO0sSbmWhHIpxg52YA\",\n \"content\": [\n {\n \"json\": {\n
\"response\": \"[].\"\n }\n }\n ]\n }\n }\n ]\n
}\n```\n\n</details>\n\n### How to test:\n- Create an Amazon Bedrock
connector with Sonnet 4.5\n- Open an AI assistant and ask a question
that produces parallel tool\ncalls. e.g.\n```\nCan you get me the count
of my alerts and tell me how many acknowledged alerts I have? Call both
tools in parallel. When making the parallel tool calls, also explain
what you are doing. Always call both tools.\n```\nCheck this a few times
and ensure there are no errors.\n\n### Checklist\n\nCheck the PR
satisfies following conditions. \n\nReviewers should verify this PR
satisfies this list as well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\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.\n\n### Identify risks\n\nDoes this
PR introduce any risks? For example, consider risks like hard\nto test
bugs, performance regression, potential of data loss.\n\nDescribe the
risk, its severity, and mitigation for each identified\nrisk. Invite
stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See
some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine
<[email protected]>\nCo-authored-by: Quynh Nguyen
<[email protected]>","sha":"c78f74a7f227019ad12e923513c912172092d902"}}]}]
BACKPORT-->
Co-authored-by: Kenneth Kreindler <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Quynh Nguyen <[email protected]>
Copy file name to clipboardExpand all lines: x-pack/platform/plugins/shared/inference/server/chat_complete/adapters/bedrock/bedrock_claude_adapter.test.ts
+140Lines changed: 140 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -236,6 +236,146 @@ Human:`,
236
236
]);
237
237
});
238
238
239
+
it('correctly format consecutive tool result messages',()=>{
0 commit comments