microsoft / microsoft/semantic-kernel

.Net: Bug: ChatHistory is broken when LLM calls multiple tools in one message

Open
#13,647 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

Description

Describe the bug
Using Bedrock connector (Claude Sonnet 4.5). After passing the first prompt - getting a chat history with two tools invocations and two results - all in separate messages.

The history built by the agent is not usable in subsequent requests, getting

Expected toolResult blocks at messages.4.content for the following Ids: tooluse_sMmlRWbbCGd0lnhiLjvk8H, but found: tooluse_G64hibpFmRqXEcAYwOfP5s

If I merge two first requests to one item and two following responses to another item - it fixes the issue.

Shouldn't SK automatically merge the history as needed or this is supposed to be a client side action when using bedrock ?

History content:

        {
            "authorName": "Audit agent",
            "role":
            {
                "label": "assistant"
            },
            "items":
            [
                {
                    "$type": "FunctionCallContent",
                    "id": "tooluse_G64hibpFmRqXEcAYwOfP5s",
                    "functionName": "Feeds_GetFeeds"
                }
            ],
            "metadata":
            {
                "usage": null
            }
        },
        {
            "authorName": "Audit agent",
            "role":
            {
                "label": "assistant"
            },
            "items":
            [
                {
                    "$type": "FunctionCallContent",
                    "id": "tooluse_sMmlRWbbCGd0lnhiLjvk8H",
                    "functionName": "DistributionList_GetTeamsDistributionList",
                    "arguments":
                    {
                        "distributionListName": "developers"
                    }
                }
            ],
            "metadata":
            {
                "usage": null
            }
        },
        {
            "authorName": "Audit agent",
            "role":
            {
                "label": "tool"
            },
            "items":
            [
                {
                    "$type": "FunctionResultContent",
                    "callId": "tooluse_G64hibpFmRqXEcAYwOfP5s",
                    "result": "Dataset DataReference: memory://8df2be02a23c4ebfb77e1170dea6c4b4. Dataset size: 78 items."
                }
            ],
            "metadata":
            {
                "usage": null
            }
        },
        {
            "authorName": "Audit agent",
            "role":
            {
                "label": "tool"
            },
            "items":
            [
                {
                    "$type": "FunctionResultContent",
                    "callId": "tooluse_sMmlRWbbCGd0lnhiLjvk8H",
                    "result": "19:791df3464b4f4c3fac8429041e8e2540@thread.v2"
                }
            ],
            "metadata":
            {
                "usage": null
            }
        }

To Reproduce
LLM invokes two tools, I suppose in parallel.

Expected behavior
ChatHistory is properly formatted by SK and can be used as is in follow up requests.

Platform
.NET 10, SK 1.73, Bedrock 4.0.16.2 (Claude Sonnet 4.5)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two-parallel-tool-call case with .NET 10, Semantic Kernel 1.73, Bedrock 4.0.16.2, and Claude Sonnet 4.5, then inspect ChatHistory handling in the Bedrock connector. Done means the resulting history can be passed unchanged to a follow-up request and Bedrock accepts the matching tool-result IDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, csharp
Domain
ai, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.