fix(agent_transfer): add hasattr guard for peer agents without mode attribute#5910
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
|
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! |
|
Updated the PR description with a testing plan and before/after output as requested. The regression tests are in |
|
/adk-pr-analyze |
|
I have completed a thorough, read-only architectural and style analysis of PR #5910. The results have been compiled into a premium PR Analysis Report in your artifacts workspace: 🔑 Key Findings & Decisions
📋 Recommendation
|
|
/adk-pr-triage |
|
Hi @AliMuhammadAslam , Thank you for your contribution! We appreciate you taking the time to submit this pull request. |
- Add from __future__ import annotations to test_get_transfer_targets.py - Strip trailing whitespace from browser JS chunks and workflow YAML - Quote YAML name field to fix check-yaml error - Mock google.auth.default in gemini enterprise fixture to fix DefaultCredentialsError in unit tests
|
Hi @rohityan, I've addressed all the failing checks in the latest commit:
All checks should pass now. |
|
/adk-pr-analyze |
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.