Skip to content

Python: [Bug]: BedrockChatClient silently drops parallel tool results when results arrive as separate tool messages #9794

Closed

Description

Observed Behavior

BedrockChatClient silently drops valid tool results when an assistant turn contains multiple parallel tool calls and the corresponding results are represented as separate tool messages.

The issue occurs in _prepare_bedrock_messages() in:

python/packages/bedrock/agent_framework_bedrock/_chat_client.py

When an assistant turn contains two parallel tool calls (c1 and c2) and their results arrive as two separate tool messages, the first result is preserved but the second result is silently dropped.

In my reproduction, the generated Bedrock request contains:

  • toolUse IDs: ['c1', 'c2']
  • toolResult IDs: ['c1']

The toolResult for c2 is missing.

This happens because the pending tool-use IDs are cleared after processing the first tool message. The next tool message therefore has no pending ID to match against and its valid result is discarded.

This can leave the generated Bedrock Converse request with a toolUse for c2 without its corresponding toolResult.

Expected Behavior

All valid tool results for the parallel tool calls should be preserved.

When the conversation contains:

assistant:
toolUse: c1
toolUse: c2

tool:
toolResult: c1

tool:
toolResult: c2

the Bedrock adapter should generate a single following user message containing both results:

user:
toolResult: c1
toolResult: c2

The adapter should continue tracking unanswered tool-use IDs across consecutive tool messages and merge their results into the Bedrock user message.

Existing behavior for duplicate and unknown tool IDs should remain unchanged; those results should continue to be dropped.

Steps to Reproduce

  1. Create an assistant turn containing two parallel tool calls with IDs c1 and c2.
  2. Represent the tool results as two separate tool messages:
    • first message contains the result for c1
    • second message contains the result for c2
  3. Pass the conversation through BedrockChatClient / _prepare_bedrock_messages().
  4. Inspect the generated Bedrock Converse messages.
  5. Observe that the generated request contains toolUse IDs ['c1', 'c2'] but only toolResult ID ['c1'].
  6. The result for c2 has been silently discarded.

Minimal Reproduction

The issue can be reproduced with the Agent Framework repository and does not require a live Bedrock connection.

The minimal conversation is:

assistant:
toolUse: c1
toolUse: c2

tool:
toolResult: c1

tool:
toolResult: c2

Passing this conversation through the Bedrock message conversion produces:

toolUse IDs: ['c1', 'c2']
toolResult IDs: ['c1']

The toolResult for c2 is silently dropped.

I also reproduced this through the AG-UI conversion path, where AG-UI represents each tool result as a separate tool message.

The relevant implementation is:

python/packages/bedrock/agent_framework_bedrock/_chat_client.py

Specifically _prepare_bedrock_messages().

I have a local patch that fixes the behavior and two regression tests covering the parallel-result case and duplicate/unknown tool IDs.

Error Messages and Stack Traces

No Python exception is raised by the local message conversion itself.

The problem is that the generated Bedrock request is incomplete: it contains a `toolUse` for `c2` without a corresponding `toolResult`.

In the local reproduction:

toolUse IDs:    ['c1', 'c2']
toolResult IDs: ['c1']

I did not have access to a live Amazon Bedrock endpoint for this reproduction, so I have not included a claimed live Bedrock stack trace.

The expected failure is based on the Bedrock Converse tool-use contract requiring the corresponding `toolResult` for each `toolUse`.

Package Versions

Microsoft Agent Framework Core Version: 1.23.0

Python Version

Python 3.13.15

Operating System

Windows

Regression

Yes

Additional Context

The issue is particularly relevant to AG-UI because AG-UI can represent parallel tool results as separate tool messages.

I reproduced the complete local conversion path:

AG-UI messages
-> agui_messages_to_agent_framework()
-> Bedrock message conversion

For a parallel tool call with IDs c1 and c2, the converted Bedrock request contained:

toolUse IDs: ['c1', 'c2']
toolResult IDs: ['c1']

The second valid tool result was silently dropped.

The root cause appears to be that _prepare_bedrock_messages() clears the pending tool-use IDs after processing a tool message. Therefore, when the next tool message contains the result for another outstanding parallel call, there is no pending ID left to match it.

The proposed fix keeps unanswered tool-use IDs across consecutive tool messages and combines their results into the single Bedrock user message required for the tool-result turn.

I added two regression tests:

  1. Separate tool messages for parallel tool calls are merged correctly.
  2. Duplicate and unknown tool IDs continue to be dropped.

With the proposed fix, the full Bedrock test suite passes: 61 tests.

I have not yet run the project's full lint or type-check suite.

I searched existing Agent Framework issues for Bedrock toolResult, toolUse, parallel tool calls, toolUseId, and dropped tool results and did not find an existing issue covering this specific failure.

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 28, 2026
  2. Namraa310806 commented on Oct 28, 2026

    @Namraa310806
    ContributorAuthor

    working on it.

  3. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 28, 2026
  4. github-actions commented on Oct 28, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The defect is in python/packages/bedrock/agent_framework_bedrock/_chat_client.py::BedrockChatClient._prepare_bedrock_messages, especially line 557, where pending tool-use IDs are cleared after every tool message. It triggers when parallel calls receive results in consecutive tool messages. Minimal repro: pass one assistant message containing calls c1 and c2, followed by separate tool-result messages for each, and assert both results appear in the converted Bedrock user message.

    • Failing test: python/packages/bedrock/tests/test_bedrock_client.py::test_prepare_bedrock_messages_merges_parallel_results_from_separate_tool_messages
    • Files examined: python/packages/bedrock/agent_framework_bedrock/_chat_client.py, python/packages/bedrock/tests/test_bedrock_client.py, python/packages/bedrock/pyproject.toml, python/packages/bedrock/AGENTS.md, docs/specs/004-python-function-calling-loop.md
    • Tests run: test_prepare_bedrock_messages_merges_parallel_results_from_separate_tool_messages, test_prepare_bedrock_messages_sends_reasoning_back_with_tool_use, test_prepare_bedrock_messages_skips_unsupported_content_and_unmatched_tool_results
    • Reported version: 1.23.0
    • Current version: 1.0.0b261022
  5. added
    agentsUsage: [Issues, PRs], Target: Single agent
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 28, 2026
  6. kimnamu commented on Oct 29, 2026

    @kimnamu
    Contributor

    Thanks for the careful write-up and for opening #9796 right away.

    You mentioned you had no live Bedrock endpoint, so I sent the history from your repro, with a user turn in front, through BedrockChatClient.get_response in us-east-1. On main (fc3c3c0) the caller does get an error, because Converse rejects the request. With the _chat_client.py from #9796 (beb7d29) the same history goes through. Keeping both results but leaving them in two user messages fails the same way, so the merge step in #9796 matters as much as dropping the .clear() at _chat_client.py:557.

    Request Bedrock receives Claude Haiku 4.5 Nova Lite
    main: toolResult for c2 dropped ❌ ValidationException ❌ ValidationException
    both results, split across two user messages ❌ same error ❌ same error
    #9796: both results in one user message ✅ finish_reason=stop ✅ finish_reason=stop
    # main fc3c3c07
    tool messages ('c1', 'c2'): roles=['user', 'assistant', 'user'] toolUse=['c1', 'c2'] toolResult=['c1']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c2
    
    Script, raw output, unit tests

    Swap python/packages/bedrock/agent_framework_bedrock/_chat_client.py between runs; needs Bedrock access in us-east-1.

    Middle row: main with this local change, only to isolate the merge:

                     content_blocks = self._align_tool_results_with_pending(content_blocks, pending_tool_use_ids)
    -                pending_tool_use_ids.clear()
    +                for b in content_blocks:
    +                    if "toolResult" in b and b["toolResult"]["toolUseId"] in pending_tool_use_ids:
    +                        pending_tool_use_ids.remove(b["toolResult"]["toolUseId"])
    """#9794: parallel tool results in separate tool messages -> what Bedrock Converse actually does."""
    import asyncio
    import re
    import sys
    
    from agent_framework import Content, Message
    from agent_framework_bedrock import BedrockChatClient
    
    TOOL = {
        "toolSpec": {
            "name": "get_weather",
            "description": "Get the weather for a city.",
            "inputSchema": {"json": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}},
        }
    }
    
    
    def history(order: tuple[str, ...]) -> list[Message]:
        results = {"c1": "Seattle: 12C rain", "c2": "Paris: 18C sun"}
        return [
            Message(role="user", contents=[Content.from_text(text="Weather in Seattle and Paris?")]),
            Message(
                role="assistant",
                contents=[
                    Content.from_function_call(call_id="c1", name="get_weather", arguments={"city": "Seattle"}),
                    Content.from_function_call(call_id="c2", name="get_weather", arguments={"city": "Paris"}),
                ],
            ),
            *[Message(role="tool", contents=[Content.from_function_result(call_id=c, result=results[c])]) for c in order],
        ]
    
    
    async def main(models: list[str]) -> None:
        for order in (("c1", "c2"), ("c2", "c1")):
            msgs = history(order)
            client = BedrockChatClient(model=models[0], region="us-east-1")
            _, conv = client._prepare_bedrock_messages(msgs)
            roles = [m["role"] for m in conv]
            uses = [b["toolUse"]["toolUseId"] for m in conv for b in m["content"] if "toolUse" in b]
            res = [b["toolResult"]["toolUseId"] for m in conv for b in m["content"] if "toolResult" in b]
            print(f"tool messages {order}: roles={roles} toolUse={uses} toolResult={res}")
            for model in models:
                client = BedrockChatClient(model=model, region="us-east-1")
                try:
                    r = await client.get_response(messages=msgs, options={"tools": [TOOL], "max_tokens": 60})
                    print(f"  {model}: OK finish_reason={r.finish_reason} text={r.text[:160]!r}")
                except Exception as e:
                    print(f"  {model}: {type(e).__name__}: {re.sub(r'[0-9]{12}', '<acct>', str(e))[:200]}")
    
    
    asyncio.run(main(sys.argv[1:]))
    # main fc3c3c07
    tool messages ('c1', 'c2'): roles=['user', 'assistant', 'user'] toolUse=['c1', 'c2'] toolResult=['c1']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c2
      us.amazon.nova-lite-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c2
    tool messages ('c2', 'c1'): roles=['user', 'assistant', 'user'] toolUse=['c1', 'c2'] toolResult=['c2']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c1
      us.amazon.nova-lite-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c1
    
    # both results kept (pending IDs consumed per result, no merge)
    tool messages ('c1', 'c2'): roles=['user', 'assistant', 'user', 'user'] toolUse=['c1', 'c2'] toolResult=['c1', 'c2']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c2
      us.amazon.nova-lite-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c2
    tool messages ('c2', 'c1'): roles=['user', 'assistant', 'user', 'user'] toolUse=['c1', 'c2'] toolResult=['c2', 'c1']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c1
      us.amazon.nova-lite-v1:0: ValidationException: An error occurred (ValidationException) when calling the Converse operation: Expected toolResult blocks at messages.2.content for the following Ids: c1
    
    # #9796 beb7d291
    tool messages ('c1', 'c2'): roles=['user', 'assistant', 'user'] toolUse=['c1', 'c2'] toolResult=['c1', 'c2']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish_reason=stop text="Here's the weather for both cities:\n\n- **Seattle**: 12°C with rain\n- **Paris**: 18°C with sun\n\nParis is warmer and sunnier, while Seattle is cooler and rainy!"
      us.amazon.nova-lite-v1:0: OK finish_reason=stop text='<thinking>I have the weather information for Seattle and Paris from the tool results. I can now report this to the User.</thinking>\nThe weather in Seattle is cu'
    tool messages ('c2', 'c1'): roles=['user', 'assistant', 'user'] toolUse=['c1', 'c2'] toolResult=['c2', 'c1']
      us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish_reason=stop text="Here's the weather for both cities:\n\n- **Seattle**: 12°C with rain\n- **Paris**: 18°C with sun\n\nParis is warmer and sunnier, while Seattle is cooler and rainy at"
      us.amazon.nova-lite-v1:0: OK finish_reason=stop text="<thinking> I have the weather information for both cities. I can now provide the User with the weather details. </thinking>\nIt's 12°C with rain in Seattle and 1"
    
    # #9796's test file against main's _chat_client.py
    FAILED packages/bedrock/tests/test_bedrock_client.py::test_prepare_bedrock_messages_preserves_separate_parallel_tool_results
    FAILED packages/bedrock/tests/test_bedrock_client.py::test_prepare_bedrock_messages_handles_three_parallel_separate_results
    FAILED packages/bedrock/tests/test_bedrock_client.py::test_prepare_bedrock_messages_does_not_merge_unrelated_messages
    3 failed, 98 passed, 1 deselected, 2 warnings in 2.55s
    
    # #9796's source and tests: packages/bedrock/tests -m "not integration"
    101 passed, 1 deselected, 2 warnings in 2.63s
    

    Happy to leave it with you. Claude (via Claude Code) assisted with the checks and this write-up; the outputs above are from local runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions