fix(agent_transfer): add hasattr guard for peer agents without mode attribute#5910
Open
AliMuhammadAslam wants to merge 1 commit into
Open
Conversation
…ttribute _get_transfer_targets already guards sub-agent iteration with `not hasattr(sub_agent, 'mode')` to handle agents like LoopAgent that have no mode attribute. The peer-agent list comprehension on the next branch was missing the same guard, causing an uncaught AttributeError whenever a LoopAgent appeared as a sibling of an LlmAgent under a shared parent. Fixes google#5863
Collaborator
|
Response from ADK Triaging Agent Hello @AliMuhammadAslam, thank you for creating this PR! While we appreciate the regression tests included with your change, could you please add a testing plan section in your PR description to describe how you tested or intend to test this? Additionally, since this is a bug fix, providing some command-line logs or output demonstrating the fix would be extremely helpful for the reviewers. For more details, please refer to our contribution guidelines. This information will help reviewers review your PR more efficiently. Thanks! |
Author
|
Updated the PR description with a testing plan and before/after output as requested. The regression tests are in |
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.
Fixes #5863
_get_transfer_targetsalready uses ahasattrguard when building the sub-agent list:The peer-agent list comprehension a few lines later was missing the same guard:
LoopAgent(and any otherBaseAgentsubclass without amodeattribute) raisesAttributeError: 'LoopAgent' object has no attribute 'mode'here, breaking any setup where aLoopAgentappears as a sibling of anLlmAgentunder a shared parent.The fix applies the same
not hasattr(peer_agent, 'mode')guard to the peer list, matching the pattern already used for sub-agents.Testing plan
Regression test added:
tests/unittests/flows/llm_flows/test_get_transfer_targets.pytest_loop_agent_peer_does_not_raise_attribute_error— sets up a root agent with anLlmAgentand aLoopAgentas peer sub-agents, calls_get_transfer_targetson theLlmAgent, and asserts it returns theLoopAgentwithout raising.test_loop_agent_sub_agent_does_not_raise_attribute_error— same check for the sub-agent list path (already worked before; included for symmetry).Before the fix:
After the fix:
All existing tests in
tests/unittests/flows/llm_flows/continue to pass.