fix: double function response processing issue #2588
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.
Description
Fixes an issue in
base_llm_flow.py
where, in Bidi-streaming (live) mode, the multi-agent structure causes duplicated responses after tool calling.Problem
In Bidi-streaming (live) mode, when utilizing a multi-agent structure, the leaf-level sub-agent and its parent agent both process the same function call response, leading to duplicate replies. This duplication occurs because the parent agent's live connection remains open while initiating a new connection with the child agent.
Root Cause
The issue originated from the placement of agent transfer logic in the
_postprocess_live
method at lines 547-557. When atransfer_to_agent
function call was made:_postprocess_live
agent_to_run.run_live
was initiatedrun_live
method, as that code path was never reachedSolution
This PR addresses the issue by ensuring the parent agent's live connection is closed before initiating a new one with the child agent. Changes made:
Connection Management: Moved the agent transfer logic from
_postprocess_live
method to therun_live
method, specifically:_postprocess_live
run_live
Code Refactoring: The agent transfer now occurs in the proper sequence:
transfer_to_agent
function responseImproved Flow Control: This ensures that each agent processes function call responses without duplication, maintaining proper connection lifecycle management in multi-agent structures.
Testing
To verify this fix works correctly:
transfer_to_agent
function callExpected Behavior:
Backward Compatibility
This change is fully backward compatible: