Skip to content

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

Closed
RudrenduPaul wants to merge 3 commits into
google:mainfrom
RudrenduPaul:fix/agent-loader-flat-module-language-detection
Closed

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

Conversation

@RudrenduPaul

Copy link
Copy Markdown
Contributor

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
Contributor 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

rohityan commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

Hi @DeanChensj , can you please review this.

@haranrk haranrk assigned haranrk and unassigned rohityan Jun 17, 2026
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 1, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 933831825
copybara-service Bot pushed a commit that referenced this pull request Jul 2, 2026
Merge #5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 941382778
@adk-bot

adk-bot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you @RudrenduPaul for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 7a553b7.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jul 2, 2026
@adk-bot adk-bot closed this Jul 2, 2026
FrigaZzz pushed a commit to FrigaZzz/adk-python that referenced this pull request Aug 11, 2026
Merge google#5235

`_determine_agent_language()` handled only 3 of the 4 agent structures that
`load_agent()` supports. When an agent is a flat module
(`agents_dir/my_agent.py`, with no subdirectory), `load_agent()` loads it
successfully but `_determine_agent_language()` raised `ValueError`.

This adds the missing flat-module branch so language detection is consistent
with all four supported load patterns:
- `{name}/agent.py`
- `{name}/__init__.py`
- `{name}/root_agent.yaml`
- `{name}.py` (flat module)

It also adds `__init__.py` to the recognized agent marker files listed in the
`adk web` / `adk api_server` AGENTS_DIR docstrings, and adds a
`TestDetermineAgentLanguage` suite covering all four patterns plus the
unrecognized-structure error case.

Co-authored-by: Haran Rajkumar <haranrk@google.com>
PiperOrigin-RevId: 941382778
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 merged [Status] This PR is merged 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.

4 participants