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 <gweale@google.com>
PiperOrigin-RevId: 834479335
This commit is contained in:
George Weale
2025-11-19 16:00:51 -08:00
committed by Copybara-Service
parent 12db84f5cd
commit 131d39c3db
5 changed files with 36 additions and 8 deletions
@@ -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',
@@ -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()
+1 -1
View File
@@ -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
@@ -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"
+26 -6
View File
@@ -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