Skip to content

Conversation

@pgrayy
Copy link
Member

@pgrayy pgrayy commented Nov 7, 2025

Description

Set the handoff node to current only after the current node finishes. Currently, we make the switch in the middle of the current node execution. It is important to fix this for a few reasons:

  1. We emit the AfterNodeCallEvent with the current node id and state.current_node set to the handoff node. This is going to cause customer confusion.
  2. If the current node runs a tool that is interrupted in parallel (concurrently) to the hand off tool, the swarm state will be invalid. The swarm state needs a reference to the real current node so that users can properly respond to its interrupts and resume execution.

Related Issues

#204

Documentation PR

Implementation detail

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare: Relying on existing unit tests
  • I ran hatch test tests_integ/test_multiagent_swarm.py

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, or no new docs are needed
  • 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.

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/multiagent/swarm.py 66.66% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@pgrayy pgrayy marked this pull request as ready for review November 7, 2025 04:15
mkmeral
mkmeral previously approved these changes Nov 9, 2025
@pgrayy pgrayy requested a review from mkmeral November 10, 2025 16:06
Copy link
Member

@dbschmigelski dbschmigelski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test so we don't accidentally break the ordering in the future

@pgrayy pgrayy requested a review from JackYPCOnline November 17, 2025 15:14
@pgrayy
Copy link
Member Author

pgrayy commented Nov 17, 2025

Can you add a unit test so we don't accidentally break the ordering in the future

Done

@pgrayy pgrayy merged commit b4efc9d into strands-agents:main Nov 17, 2025
15 of 18 checks passed
@pgrayy pgrayy deleted the swarm-handoff-delayed branch November 18, 2025 13:58
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.

4 participants