def test_agent_internal_module_not_found_error(self):
    """Test error when an agent tries to import a non-existent module."""
    with tempfile.TemporaryDirectory() as temp_dir:
      temp_path = Path(temp_dir)
      agent_name = "importer_agent"

      # Create agent that imports a non-existent module
      agent_file = temp_path / f"{agent_name}.py"
      agent_file.write_text(dedent(f"""
                from google.adk.agents.base_agent import BaseAgent
                import non_existent_module  # This will fail

                class {agent_name.title()}Agent(BaseAgent):
                    def __init__(self):
                        super().__init__(name="{agent_name}")

                root_agent = {agent_name.title()}Agent()
            """))

      loader = AgentLoader(str(temp_path))
      with pytest.raises(ModuleNotFoundError) as exc_info:
        loader.load_agent(agent_name)

      assert f"Fail to load '{agent_name}' module." in str(exc_info.value)
      assert "No module named 'non_existent_module'" in str(exc_info.value)
Test error when an agent tries to import a non-existent module.
tests/unittests/cli/utils/test_agent_loader.py