-
Notifications
You must be signed in to change notification settings - Fork 605
Description
Checks
- I have updated to the lastest minor and patch version of Strands
- I have checked the documentation and this is not expected behavior
- I have searched ./issues and there are no duplicates of my issue
Strands Version
Latest
Python Version
Latest
Operating System
Mac
Installation Method
pip
Steps to Reproduce
Occurs on any invocation of Swarm. For an example of invoking swarm, see the integ tests here.
Expected Behavior
When a swarm is interrupted, the execution_time is reset on the resume invocation (src). It should instead be a sum across an interrupt/resume cycle. For an example of how this should look, you can check out the execution_time calculation in graph (src, test).
Actual Behavior
When a swarm is interrupted, the execution_time is reset on the resume invocation (src). It should instead be a sum across an interrupt/resume cycle. For an example of how this should look, you can check out the execution_time calculation in graph (src, test).
Additional Context
No response
Possible Solution
No response
Related Issues
No response
Implementation Requirements
Root Cause
In src/strands/multiagent/swarm.py line 409:
self.state.execution_time = round((time.time() - self.state.start_time) * 1000)This uses = assignment which resets execution_time on each invocation, rather than accumulating it across interrupt/resume cycles.
Reference Implementation
The correct behavior is demonstrated in src/strands/multiagent/graph.py line 589:
self.state.execution_time += round((time.time() - start_time) * 1000)This uses += to accumulate execution time across all invocations, which is the expected behavior.
Technical Approach
-
Code Fix - Change line 409 in
swarm.pyfrom=to+=:self.state.execution_time += round((time.time() - self.state.start_time) * 1000)
-
Unit Test - Add a test similar to
test_graph_interrupt_on_before_node_call_event(found attests/strands/multiagent/test_graph.pyline 2096) that verifies:- First invocation records
first_execution_time - After resume,
multiagent_result.execution_time >= first_execution_time
- First invocation records
Files to Modify
| File | Change |
|---|---|
src/strands/multiagent/swarm.py |
Line 409: change = to += |
tests/strands/multiagent/test_swarm.py |
Add test for execution_time accumulation across interrupt/resume |
Acceptance Criteria
-
execution_timeinSwarmResultaccumulates across interrupt/resume cycles (not reset) - New unit test verifies
execution_timeafter resume is >=execution_timefrom first invocation - All existing swarm tests pass
- Code follows existing patterns in
graph.py