Skip to content

fix: preserve tool_results request order in ConcurrentToolExecutor#2199

Open
luyao618 wants to merge 1 commit intostrands-agents:mainfrom
luyao618:fix/concurrent-tool-result-ordering
Open

fix: preserve tool_results request order in ConcurrentToolExecutor#2199
luyao618 wants to merge 1 commit intostrands-agents:mainfrom
luyao618:fix/concurrent-tool-result-ordering

Conversation

@luyao618
Copy link
Copy Markdown

Problem

ConcurrentToolExecutor collects tool results in task completion order rather than the original request order. When a fast tool finishes before a slow tool, the tool_results list does not match the tool_uses ordering.

Reported in #2112.

Solution

After all concurrent tasks complete, sort tool_results by the original tool_uses index using a toolUseId → index mapping built before execution. The sort happens in the finally block of _execute() so it applies regardless of how tasks complete.

Testing

Added test_concurrent_executor_preserves_request_order that verifies tool_results order matches the original tool_uses order when tools complete at different speeds.

Closes #2112

The ConcurrentToolExecutor collects tool results in task completion order
rather than the original request order. When a fast tool finishes before
a slow tool, the results list does not match the tool_uses ordering.

Sort tool_results by the original tool_uses index after all tasks
complete using the toolUseId mapping.

Closes strands-agents#2112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ConcurrentToolExecutor collects tool_results in completion order, breaking prompt-cache stability

1 participant