Skip to content

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

@ealeykin

Description

@ealeykin

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions