Skip to content
26 changes: 23 additions & 3 deletions src/google/adk/cli/utils/agent_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,33 @@ def _perform_load(self, agent_name: str) -> Union[BaseAgent, App]:
return root_agent

# If no root_agent was found by any pattern
# Check if user might be in the wrong directory
hint = ""
agents_path = Path(agents_dir)
if agents_path.joinpath("agent.py").is_file() or agents_path.joinpath(
"root_agent.yaml"
).is_file():
hint = (
"\n\nHINT: It looks like you might be running 'adk web' from inside an"
" agent directory. Try running 'adk web .' from the parent directory"
" that contains your agent folder, not from within the agent folder"
" itself."
)

raise ValueError(
f"No root_agent found for '{agent_name}'. Searched in"
f" '{actual_agent_name}.agent.root_agent',"
f" '{actual_agent_name}.root_agent' and"
f" '{actual_agent_name}/root_agent.yaml'. Ensure"
f" '{agents_dir}/{actual_agent_name}' is structured correctly, an .env"
" file can be loaded if present, and a root_agent is exposed."
f" '{actual_agent_name}/root_agent.yaml'."
f"\n\nExpected directory structure:"
f"\n <agents_dir>/"
f"\n {actual_agent_name}/"
f"\n agent.py (with root_agent) OR"
f"\n root_agent.yaml"
f"\n\nThen run: adk web <agents_dir>"
f"\n\nEnsure '{agents_dir}/{actual_agent_name}' is structured correctly,"
" an .env file can be loaded if present, and a root_agent is exposed."
f"{hint}"
)

def _ensure_app_name_matches(
Expand Down
Loading