def test_loading_order_preference(self):
    """Test that module/package is preferred over agent.py in a sub-package."""
    with tempfile.TemporaryDirectory() as temp_dir:
      temp_path = Path(temp_dir)
      agent_name = "order_test_agent"

      # Create structure 1: agents_dir/agent_name.py (expected to be loaded)
      agent_module_file = temp_path / f"{agent_name}.py"
      agent_module_file.write_text(dedent(f"""
                from google.adk.agents.base_agent import BaseAgent
                class ModuleAgent(BaseAgent):
                    def __init__(self):
                        super().__init__(name="{agent_name}_module_version")
                root_agent = ModuleAgent()
            """))

      # Create structure 2: agents_dir/agent_name/agent.py (should be ignored)
      agent_package_dir = temp_path / agent_name
      agent_package_dir.mkdir()
      agent_submodule_file = agent_package_dir / "agent.py"
      agent_submodule_file.write_text(dedent(f"""
                from google.adk.agents.base_agent import BaseAgent
                class SubmoduleAgent(BaseAgent):
                    def __init__(self):
                        super().__init__(name="{agent_name}_submodule_version")
                root_agent = SubmoduleAgent()
            """))

      loader = AgentLoader(str(temp_path))
      agent = loader.load_agent(agent_name)

      # Assert that the module version was loaded due to the new loading order
      assert agent.name == f"{agent_name}_module_version"
Test that module/package is preferred over agent.py in a sub-package.
tests/unittests/cli/utils/test_agent_loader.py