Skip to content

Commit 131d39c

Browse files
GWealecopybara-github
authored andcommitted
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
1 parent 12db84f commit 131d39c

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

src/google/adk/cli/built_in_agents/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from __future__ import annotations
2222

2323
from . import agent # Import to make agent.root_agent available
24-
from .agent_builder_assistant import AgentBuilderAssistant
24+
from .adk_agent_builder_assistant import AgentBuilderAssistant
2525

2626
__all__ = [
2727
'AgentBuilderAssistant',

src/google/adk/cli/built_in_agents/agent_builder_assistant.py renamed to src/google/adk/cli/built_in_agents/adk_agent_builder_assistant.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,8 @@ def _load_embedded_schema_instruction_template() -> str:
416416

417417
with open(template_path, "r", encoding="utf-8") as f:
418418
return f.read()
419+
420+
421+
# Expose a module-level root_agent so the AgentLoader can find this built-in
422+
# assistant when requested as "__adk_agent_builder_assistant".
423+
root_agent = AgentBuilderAssistant.create_agent()

src/google/adk/cli/built_in_agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Agent Builder Assistant instance for ADK web testing."""
1616
from __future__ import annotations
1717

18-
from .agent_builder_assistant import AgentBuilderAssistant
18+
from .adk_agent_builder_assistant import AgentBuilderAssistant
1919

2020
# Create the agent instance using the factory
2121
# The root_agent variable is what ADK looks for when loading agents

src/google/adk/cli/built_in_agents/instruction_embedded.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Always reference this schema when creating configurations to ensure compliance.
7575
- **CRITICAL TIMING**: Ask for model selection IMMEDIATELY after determining LlmAgent is needed, BEFORE presenting any design
7676
- **MANDATORY CONFIRMATION**: Say "Please confirm what model you want to use" - do NOT assume or suggest defaults
7777
- **EXAMPLES**: "gemini-2.5-flash", "gemini-2.5-pro", etc.
78+
- **ALLOWED MODELS ONLY**: Only mention or propose "gemini-2.5-flash" or
79+
"gemini-2.5-pro". Treat any request for gemini-1.5-* or older models as
80+
unsupported and redirect to one of the 2.5 options.
7881
- **RATIONALE**: Only LlmAgent requires model specification; workflow agents do not
7982
- **DEFAULT MODEL**: If user says "use default" or "proceed with default model", use: {default_model}
8083
* This is the actual model name, NOT the literal string "default"

src/google/adk/cli/utils/agent_loader.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,30 @@ def _perform_load(self, agent_name: str) -> Union[BaseAgent, App]:
192192
agents_dir = os.path.abspath(SPECIAL_AGENTS_DIR)
193193
# Remove the double underscore prefix for the actual agent name
194194
actual_agent_name = agent_name[2:]
195+
# If this special agents directory is part of a package (has __init__.py
196+
# up the tree), build a fully-qualified module path so the built-in agent
197+
# can continue to use relative imports. Otherwise, fall back to importing
198+
# by module name relative to agents_dir.
199+
module_base_name = actual_agent_name
200+
package_parts: list[str] = []
201+
package_root: Optional[Path] = None
202+
current_dir = Path(agents_dir).resolve()
203+
while True:
204+
if not (current_dir / "__init__.py").is_file():
205+
package_root = current_dir
206+
break
207+
package_parts.append(current_dir.name)
208+
current_dir = current_dir.parent
209+
if package_parts:
210+
package_parts.reverse()
211+
module_base_name = ".".join(package_parts + [actual_agent_name])
212+
if str(package_root) not in sys.path:
213+
sys.path.insert(0, str(package_root))
195214
else:
196215
# Regular agent: use the configured agents directory
197216
agents_dir = self.agents_dir
198217
actual_agent_name = agent_name
218+
module_base_name = actual_agent_name
199219

200220
# Add agents_dir to sys.path
201221
if agents_dir not in sys.path:
@@ -204,20 +224,20 @@ def _perform_load(self, agent_name: str) -> Union[BaseAgent, App]:
204224
logger.debug("Loading .env for agent %s from %s", agent_name, agents_dir)
205225
envs.load_dotenv_for_agent(actual_agent_name, str(agents_dir))
206226

207-
if root_agent := self._load_from_module_or_package(actual_agent_name):
227+
if root_agent := self._load_from_module_or_package(module_base_name):
208228
self._record_origin_metadata(
209229
loaded=root_agent,
210-
expected_app_name=actual_agent_name,
211-
module_name=actual_agent_name,
230+
expected_app_name=agent_name,
231+
module_name=module_base_name,
212232
agents_dir=agents_dir,
213233
)
214234
return root_agent
215235

216-
if root_agent := self._load_from_submodule(actual_agent_name):
236+
if root_agent := self._load_from_submodule(module_base_name):
217237
self._record_origin_metadata(
218238
loaded=root_agent,
219-
expected_app_name=actual_agent_name,
220-
module_name=f"{actual_agent_name}.agent",
239+
expected_app_name=agent_name,
240+
module_name=f"{module_base_name}.agent",
221241
agents_dir=agents_dir,
222242
)
223243
return root_agent

0 commit comments

Comments
 (0)