fix(agent_loader): support flat-module agents in _determine_agent_language - #5235
Closed
RudrenduPaul wants to merge 3 commits into
Closed
fix(agent_loader): support flat-module agents in _determine_agent_language#5235RudrenduPaul wants to merge 3 commits into
RudrenduPaul wants to merge 3 commits into
Conversation
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
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. |
Collaborator
|
Hi @DeanChensj , can you please review this. |
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
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. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_determine_agent_language()inagent_loader.pyhandles only 3 of the 4 agent structures thatload_agent()supports. When a user structures their agent as a flat module (agents_dir/my_agent.pywith no subdirectory),load_agent()successfully loads it, but_determine_agent_language()raisesValueError— causinglist_agents_detailed()(used byadk webandadk 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}.pyflat module ❌ raised ValueError — this PR fixes thisChanges
src/google/adk/cli/utils/agent_loader.py: Addelif (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 forcli_webandcli_api_serverthat incorrectly stated agents must be subdirectories with__init__.pyandagent.pytests/unittests/cli/utils/test_agent_loader.py: AddTestDetermineAgentLanguageclass with 5 tests covering all 4 supported patterns plus the unrecognized-structure error caseTesting plan
New
TestDetermineAgentLanguageclass added with tests for:agents_dir/my_agent.py) → returns"python"✅agent.py→ returns"python"✅__init__.py→ returns"python"✅root_agent.yaml→ returns"yaml"✅ValueError✅Full CI run required to verify (local run requires
google.genaidependency installation).