Fix handoff closure bug and add multiple handoffs test#1310
Merged
tconley1428 merged 1 commit intomainfrom Jan 29, 2026
Merged
Conversation
Fixed a Python closure bug in _convert_agent where handoff functions were incorrectly captured by reference instead of by value. This caused all handoff calls to route to the last agent processed in the loop instead of the intended agent. - Fix: Use default parameter to capture handoff function by value - Add: Test case validating correct handoff routing with multiple agents - Test: Verifies transfer_to_planner correctly routes to Planner agent 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4 tasks
mfateev
reviewed
Jan 29, 2026
THardy98
approved these changes
Jan 29, 2026
Contributor
THardy98
left a comment
There was a problem hiding this comment.
LGTM - as a sanity check, could we add an assertion after the planner response to check that the subsequent handoff to the writer is also correct
Contributor
Author
|
It actually doesn't bother handing off to the writer because the planner doesn't have the writer as a subagent and the planner doesn't know what to plan. Sufficient to test the issue though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_convert_agentwhere handoff functions were incorrectly captured by reference instead of by valueProblem
The
_convert_agentfunction had a closure bug where theasync def on_invokefunction was defined inside a loop and captured theoriginal_invokevariable by reference. This caused all handoff calls to route to the last agent processed in the loop instead of the intended agent.For example, when calling
transfer_to_planner, it would incorrectly route to the writer agent instead of the planner agent.Solution
invoke_func=original_invoke) to capture the handoff function by value instead of by referenceTest
Added
test_multiple_handoffs_workflowthat:transfer_to_plannercorrectly routes to the Planner agent🤖 Generated with Claude Code