Skip to content

fix(batch): read invocations from tool input and fix concurrency error#439

Open
dosvk wants to merge 1 commit intostrands-agents:mainfrom
dosvk:fix/batch-tool-broken
Open

fix(batch): read invocations from tool input and fix concurrency error#439
dosvk wants to merge 1 commit intostrands-agents:mainfrom
dosvk:fix/batch-tool-broken

Conversation

@dosvk
Copy link
Copy Markdown

@dosvk dosvk commented Apr 2, 2026

Fix two bugs preventing the batch tool from executing sub-tools:

  1. Read invocations from tool['input']['invocations'] instead of kwargs,
    which only contains framework state (agent, model, etc.) and never
    the tool input parameters.

  2. Pass record_direct_tool_call=False when calling sub-tools to avoid
    ConcurrencyException from the agent invocation lock that is already
    held by the batch tool execution.

Update tests to pass invocations via tool['input'] to match the real
SDK calling convention.

Closes #413

Description

Fix two bugs in the batch tool that prevented any sub-tool execution.

Bug 1 (line 97): kwargs.get("invocations", []) always returned empty because
module-based tools receive their inputs in the tool dict, not kwargs. Fixed
to tool.get("input", {}).get("invocations", []).

Bug 2 (line 112): tool_fn(**arguments) raised ConcurrencyException because
the agent invocation lock was already held. Fixed by passing
record_direct_tool_call=False to skip the lock and message recording.

Related Issues

Closes #413

Documentation PR

N/A

Type of Change

Bug fix

Testing

  • Fixed existing tests to pass invocations via tool["input"] (matching real SDK calling convention)
  • Added test for missing input key (graceful fallback)
  • Added assertion verifying sub-tools called with record_direct_tool_call=False
  • Verified manually with real agent: batch now executes all sub-tools successfully
  • 6 tests passing, 0 failures

Evidence

Before fix (batch returns 0 results, agent falls back to individual calls):

=== Testing batch tool ===
Asking agent to get current time in multiple timezones using batch...

I'll use the batch tool to get the current time in both UTC and US/Pacific simultaneously.
Tool #1: batch
It seems there was an issue with the batch execution. Let me try getting both times individually:
Tool #2: current_time

Tool #3: current_time
Here are the current times:

- **UTC**: 2026-04-02T16:22:03.529741+00:00 (4:22:03 PM)
- **US/Pacific**: 2026-04-02T09:22:04.658259-07:00 (9:22:04 AM)

The Pacific time is 7 hours behind UTC, which is expected during Pacific Daylight Time (PDT) when daylight saving time is in effect.
=== Result ===
Here are the current times:

- **UTC**: 2026-04-02T16:22:03.529741+00:00 (4:22:03 PM)
- **US/Pacific**: 2026-04-02T09:22:04.658259-07:00 (9:22:04 AM)

The Pacific time is 7 hours behind UTC, which is expected during Pacific Daylight Time (PDT) when daylight saving time is in effect.

After fix (batch executes all sub-tools in one call):

=== Testing batch tool ===
Asking agent to get current time in multiple timezones using batch...

I'll use the batch tool to get the current time in both UTC and US/Pacific timezones simultaneously.
Tool #1: batch
Here are the current times in both timezones:

**UTC**: 2026-04-02T16:28:14.740848+00:00  
**US/Pacific**: 2026-04-02T09:28:14.742302-07:00

The Pacific time is 7 hours behind UTC, showing the current daylight saving time offset.
=== Result ===
Here are the current times in both timezones:

**UTC**: 2026-04-02T16:28:14.740848+00:00  
**US/Pacific**: 2026-04-02T09:28:14.742302-07:00

The Pacific time is 7 hours behind UTC, showing the current daylight saving time offset.
  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Fix two bugs preventing the batch tool from executing sub-tools:

1. Read invocations from tool['input']['invocations'] instead of
   kwargs, which only contains framework state (agent, model, etc.)
   and never the tool input parameters.

2. Pass record_direct_tool_call=False when calling sub-tools to avoid
   ConcurrencyException from the agent invocation lock that is already
   held by the batch tool execution.

Update tests to pass invocations via tool['input'] to match the real
SDK calling convention.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] batch tool is completely broken - two issues prevent any sub-tool execution

1 participant