Skip to content

fix(agent-loader): report the actual root_agent type mismatch - #6659

Open
Diwak4r wants to merge 1 commit into
google:mainfrom
Diwak4r:fix/agent-loader-mismatch-diagnosis
Open

fix(agent-loader): report the actual root_agent type mismatch#6659
Diwak4r wants to merge 1 commit into
google:mainfrom
Diwak4r:fix/agent-loader-mismatch-diagnosis

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #6606: AgentLoader no longer discards its own diagnosis when a module's root_agent has the wrong type.

The bug

When a module exposes a root_agent that is not a BaseAgent/BaseNode (for example an App assigned to root_agent instead of app), the loader detected the exact problem, formatted it with the offending type, wrote it to logger.warning, and then fell through to raise the generic "No root_agent found" error.

Every actionable statement in that generic error is wrong for this failure:

  • root_agent was found, it exists in the module.
  • The directory structure was correct.
  • The cwd was correct; the HINT tells the user to restructure a working layout.

The fix

  • _load_from_module_or_package and _load_from_submodule now remember the mismatch (location, wrong_type) instead of throwing it away.
  • _perform_load raises the precise error when a mismatch was recorded and no pattern produced a valid load:
Found 'judge.agent.root_agent' in module, but it is a App, not a BaseAgent or BaseNode. If you meant to export an App, name it `app` instead of `root_agent`.
  • The mismatch state is reset per load, so caching/reuse across agents is unaffected.
  • The fallback behavior is preserved: if a later pattern (e.g. agent.py with a correct root_agent) loads successfully, the mismatch is never surfaced.

Tests

Added two unit tests covering both dispatch paths:

  • test_agent_with_wrong_root_agent_type_error — module file with root_agent = App(...).
  • test_agent_submodule_wrong_root_agent_type_error{agent}/agent.py with root_agent = App(...).

Both assert the precise diagnosis appears and that the misleading "No root_agent found" path is not taken. Full suite: tests/unittests/cli/utils/test_agent_loader.py 41 passed, test_nested_agent_loader.py 7 passed.

When a module exposes a root_agent that is not a BaseAgent or BaseNode (for example an App assigned to root_agent instead of app), the loader logged the offending type at WARNING and then raised the generic 'No root_agent found' error, which claims the root_agent is missing, the directory structure is wrong, and the cwd is wrong. Remember the mismatch and raise a precise error pointing at the real fix (name the App 'app' instead of 'root_agent').
@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Aug 9, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentLoader discards its own diagnosis: type mismatch on root_agent is logged at WARNING, then reported as "No root_agent found"

3 participants