Skip to content

Commit d73a5c6

Browse files
committed
fix(cli): improve error message when adk web is run in wrong directory
Enhances the AgentLoader error message to help users who run 'adk web' from incorrect directories. This issue affected multiple teams during internal workshops when getting started with ADK. Changes: - Adds visual directory structure diagram to error message - Includes explicit 'adk web <agents_dir>' usage example - Detects when user is inside an agent directory and provides targeted hint to run 'adk web .' from parent directory Fixes #3195
1 parent 2424d6a commit d73a5c6

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,32 @@ def _perform_load(self, agent_name: str) -> Union[BaseAgent, App]:
224224
return root_agent
225225

226226
# If no root_agent was found by any pattern
227+
# Check if user might be in the wrong directory
228+
hint = ""
229+
if os.path.isfile(os.path.join(agents_dir, "agent.py")) or os.path.isfile(
230+
os.path.join(agents_dir, "root_agent.yaml")
231+
):
232+
hint = (
233+
"\n\nHINT: It looks like you might be running 'adk web' from inside an"
234+
" agent directory. Try running 'adk web .' from the parent directory"
235+
" that contains your agent folder, not from within the agent folder"
236+
" itself."
237+
)
238+
227239
raise ValueError(
228240
f"No root_agent found for '{agent_name}'. Searched in"
229241
f" '{actual_agent_name}.agent.root_agent',"
230242
f" '{actual_agent_name}.root_agent' and"
231-
f" '{actual_agent_name}/root_agent.yaml'. Ensure"
232-
f" '{agents_dir}/{actual_agent_name}' is structured correctly, an .env"
233-
" file can be loaded if present, and a root_agent is exposed."
243+
f" '{actual_agent_name}/root_agent.yaml'."
244+
f"\n\nExpected directory structure:"
245+
f"\n <agents_dir>/"
246+
f"\n {actual_agent_name}/"
247+
f"\n agent.py (with root_agent) OR"
248+
f"\n root_agent.yaml"
249+
f"\n\nThen run: adk web <agents_dir>"
250+
f"\n\nEnsure '{agents_dir}/{actual_agent_name}' is structured correctly,"
251+
" an .env file can be loaded if present, and a root_agent is exposed."
252+
f"{hint}"
234253
)
235254

236255
def _ensure_app_name_matches(

0 commit comments

Comments
 (0)