From 131d39c3db1ae25e3911fa7f72afbe05e24a1c37 Mon Sep 17 00:00:00 2001 From: George Weale Date: Wed, 19 Nov 2025 16:00:16 -0800 Subject: [PATCH] fix: Change name for builder agent When this agent was built before the agent name was changed in the build script and accepted like that from the VB so changed to set into that form Co-authored-by: George Weale PiperOrigin-RevId: 834479335 --- .../adk/cli/built_in_agents/__init__.py | 2 +- ...tant.py => adk_agent_builder_assistant.py} | 5 +++ src/google/adk/cli/built_in_agents/agent.py | 2 +- .../instruction_embedded.template | 3 ++ src/google/adk/cli/utils/agent_loader.py | 32 +++++++++++++++---- 5 files changed, 36 insertions(+), 8 deletions(-) rename src/google/adk/cli/built_in_agents/{agent_builder_assistant.py => adk_agent_builder_assistant.py} (98%) diff --git a/src/google/adk/cli/built_in_agents/__init__.py b/src/google/adk/cli/built_in_agents/__init__.py index d88b442f..80b07a80 100644 --- a/src/google/adk/cli/built_in_agents/__init__.py +++ b/src/google/adk/cli/built_in_agents/__init__.py @@ -21,7 +21,7 @@ with ADK tools and web interfaces. from __future__ import annotations from . import agent # Import to make agent.root_agent available -from .agent_builder_assistant import AgentBuilderAssistant +from .adk_agent_builder_assistant import AgentBuilderAssistant __all__ = [ 'AgentBuilderAssistant', diff --git a/src/google/adk/cli/built_in_agents/agent_builder_assistant.py b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py similarity index 98% rename from src/google/adk/cli/built_in_agents/agent_builder_assistant.py rename to src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py index 3f28604e..810f838f 100644 --- a/src/google/adk/cli/built_in_agents/agent_builder_assistant.py +++ b/src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py @@ -416,3 +416,8 @@ class AgentBuilderAssistant: with open(template_path, "r", encoding="utf-8") as f: return f.read() + + +# Expose a module-level root_agent so the AgentLoader can find this built-in +# assistant when requested as "__adk_agent_builder_assistant". +root_agent = AgentBuilderAssistant.create_agent() diff --git a/src/google/adk/cli/built_in_agents/agent.py b/src/google/adk/cli/built_in_agents/agent.py index 71268996..51a6bbf7 100644 --- a/src/google/adk/cli/built_in_agents/agent.py +++ b/src/google/adk/cli/built_in_agents/agent.py @@ -15,7 +15,7 @@ """Agent Builder Assistant instance for ADK web testing.""" from __future__ import annotations -from .agent_builder_assistant import AgentBuilderAssistant +from .adk_agent_builder_assistant import AgentBuilderAssistant # Create the agent instance using the factory # The root_agent variable is what ADK looks for when loading agents diff --git a/src/google/adk/cli/built_in_agents/instruction_embedded.template b/src/google/adk/cli/built_in_agents/instruction_embedded.template index 27bbba76..4ba5760e 100644 --- a/src/google/adk/cli/built_in_agents/instruction_embedded.template +++ b/src/google/adk/cli/built_in_agents/instruction_embedded.template @@ -75,6 +75,9 @@ Always reference this schema when creating configurations to ensure compliance. - **CRITICAL TIMING**: Ask for model selection IMMEDIATELY after determining LlmAgent is needed, BEFORE presenting any design - **MANDATORY CONFIRMATION**: Say "Please confirm what model you want to use" - do NOT assume or suggest defaults - **EXAMPLES**: "gemini-2.5-flash", "gemini-2.5-pro", etc. +- **ALLOWED MODELS ONLY**: Only mention or propose "gemini-2.5-flash" or + "gemini-2.5-pro". Treat any request for gemini-1.5-* or older models as + unsupported and redirect to one of the 2.5 options. - **RATIONALE**: Only LlmAgent requires model specification; workflow agents do not - **DEFAULT MODEL**: If user says "use default" or "proceed with default model", use: {default_model} * This is the actual model name, NOT the literal string "default" diff --git a/src/google/adk/cli/utils/agent_loader.py b/src/google/adk/cli/utils/agent_loader.py index 3efd1df5..9f01705d 100644 --- a/src/google/adk/cli/utils/agent_loader.py +++ b/src/google/adk/cli/utils/agent_loader.py @@ -192,10 +192,30 @@ class AgentLoader(BaseAgentLoader): agents_dir = os.path.abspath(SPECIAL_AGENTS_DIR) # Remove the double underscore prefix for the actual agent name actual_agent_name = agent_name[2:] + # If this special agents directory is part of a package (has __init__.py + # up the tree), build a fully-qualified module path so the built-in agent + # can continue to use relative imports. Otherwise, fall back to importing + # by module name relative to agents_dir. + module_base_name = actual_agent_name + package_parts: list[str] = [] + package_root: Optional[Path] = None + current_dir = Path(agents_dir).resolve() + while True: + if not (current_dir / "__init__.py").is_file(): + package_root = current_dir + break + package_parts.append(current_dir.name) + current_dir = current_dir.parent + if package_parts: + package_parts.reverse() + module_base_name = ".".join(package_parts + [actual_agent_name]) + if str(package_root) not in sys.path: + sys.path.insert(0, str(package_root)) else: # Regular agent: use the configured agents directory agents_dir = self.agents_dir actual_agent_name = agent_name + module_base_name = actual_agent_name # Add agents_dir to sys.path if agents_dir not in sys.path: @@ -204,20 +224,20 @@ class AgentLoader(BaseAgentLoader): logger.debug("Loading .env for agent %s from %s", agent_name, agents_dir) envs.load_dotenv_for_agent(actual_agent_name, str(agents_dir)) - if root_agent := self._load_from_module_or_package(actual_agent_name): + if root_agent := self._load_from_module_or_package(module_base_name): self._record_origin_metadata( loaded=root_agent, - expected_app_name=actual_agent_name, - module_name=actual_agent_name, + expected_app_name=agent_name, + module_name=module_base_name, agents_dir=agents_dir, ) return root_agent - if root_agent := self._load_from_submodule(actual_agent_name): + if root_agent := self._load_from_submodule(module_base_name): self._record_origin_metadata( loaded=root_agent, - expected_app_name=actual_agent_name, - module_name=f"{actual_agent_name}.agent", + expected_app_name=agent_name, + module_name=f"{module_base_name}.agent", agents_dir=agents_dir, ) return root_agent