Skip to content

fix(agent_loader): support flat-module agents in _determine_agent_language#5235

Open
RudrenduPaul wants to merge 3 commits intogoogle:mainfrom
RudrenduPaul:fix/agent-loader-flat-module-language-detection
Open

fix(agent_loader): support flat-module agents in _determine_agent_language#5235
RudrenduPaul wants to merge 3 commits intogoogle:mainfrom
RudrenduPaul:fix/agent-loader-flat-module-language-detection

Conversation

@RudrenduPaul
Copy link
Copy Markdown

Problem

_determine_agent_language() in agent_loader.py handles only 3 of the 4 agent structures that load_agent() supports. When a user structures their agent as a flat module (agents_dir/my_agent.py with no subdirectory), load_agent() successfully loads it, but _determine_agent_language() raises ValueError — causing list_agents_detailed() (used by adk web and adk api_server) to fail with a crash for that agent.

The four load patterns load_agent() supports:

  • {name}/agent.py ✅ detected
  • {name}/__init__.py ✅ detected
  • {name}/root_agent.yaml ✅ detected
  • {name}.py flat module ❌ raised ValueError — this PR fixes this

Changes

  • src/google/adk/cli/utils/agent_loader.py: Add elif (base_path.parent / f"{agent_name}.py").exists(): return "python" branch to _determine_agent_language()
  • src/google/adk/cli/cli_tools_click.py: Update docstrings for cli_web and cli_api_server that incorrectly stated agents must be subdirectories with __init__.py and agent.py
  • tests/unittests/cli/utils/test_agent_loader.py: Add TestDetermineAgentLanguage class with 5 tests covering all 4 supported patterns plus the unrecognized-structure error case

Testing plan

New TestDetermineAgentLanguage class added with tests for:

  1. Flat-module agent (agents_dir/my_agent.py) → returns "python"
  2. Subdirectory with agent.py → returns "python"
  3. Subdirectory with __init__.py → returns "python"
  4. Subdirectory with root_agent.yaml → returns "yaml"
  5. Unrecognized structure → raises ValueError

Full CI run required to verify (local run requires google.genai dependency installation).

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Apr 9, 2026
@RudrenduPaul
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@rohityan rohityan self-assigned this Apr 13, 2026
@rohityan rohityan added the needs review [Status] The PR/issue is awaiting review from the maintainer label Apr 13, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

Hi @RudrenduPaul ,Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan
Copy link
Copy Markdown
Collaborator

rohityan commented Apr 13, 2026

Hi @DeanChensj , can you please review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants