| 1545 | original_path = None |
| 1546 | |
| 1547 | def _create_agent(agent_dir_name: str): |
| 1548 | nonlocal original_path |
| 1549 | agent_dir = tmp_path / "agents" / agent_dir_name |
| 1550 | agent_dir.mkdir(parents=True, exist_ok=True) |
| 1551 | (tmp_path / "agents" / "__init__.py").write_text("", encoding="utf-8") |
| 1552 | (agent_dir / "__init__.py").write_text("", encoding="utf-8") |
| 1553 | |
| 1554 | agent_source = f"""\ |
| 1555 | from google.adk.agents.llm_agent import LlmAgent |
| 1556 | |
| 1557 | class MyAgent(LlmAgent): |
| 1558 | pass |
| 1559 | |
| 1560 | root_agent = MyAgent(name="{agent_dir_name}", model="gemini-2.5-flash") |
| 1561 | """ |
| 1562 | (agent_dir / "agent.py").write_text(agent_source, encoding="utf-8") |
| 1563 | |
| 1564 | monkeypatch.chdir(tmp_path) |
| 1565 | if original_path is None: |
| 1566 | original_path = str(tmp_path) |
| 1567 | sys.path.insert(0, original_path) |
| 1568 | |
| 1569 | module_name = f"agents.{agent_dir_name}.agent" |
| 1570 | module = importlib.import_module(module_name) |
| 1571 | created_modules.append(module_name) |
| 1572 | return module.root_agent |
| 1573 | |
| 1574 | yield _create_agent |
| 1575 | |