Skip to content

_separate_tool_calls corrupts conversation history when multiple MCP tool calls require approval #5293

@gyliu513

Description

@gyliu513

System Info

NA

Information

  • The official example scripts
  • My own modified scripts

🐛 Describe the bug

In StreamingResponseOrchestrator._separate_tool_calls(), when the model returns a single choice containing multiple MCP tool calls that all require approval (pending or denied), the method calls next_turn_messages.pop() once per tool call inside the inner loop. The first pop() correctly removes the assistant message appended, but every subsequent pop() deletes an unrelated message from the conversation history.

Error logs

NA

Expected behavior

Regardless of how many tool calls in a single choice require approval, only the one assistant message appended for that choice should be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions