Skip to content

fix: report root_agent type mismatch instead of 'No root_agent found' - #6635

Open
loponly wants to merge 4 commits into
google:mainfrom
loponly:fix/agent-loader-root-agent-type-error
Open

fix: report root_agent type mismatch instead of 'No root_agent found'#6635
loponly wants to merge 4 commits into
google:mainfrom
loponly:fix/agent-loader-root-agent-type-error

Conversation

@loponly

@loponly loponly commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #6606

Problem

When a module defines root_agent with a non-agent type, AgentLoader
logs the type mismatch at WARNING but then raises the generic
ValueError: No root_agent found, whose directory-structure guidance
sends users in the wrong direction when their layout is correct.

Fix

_load_from_module_or_package and _load_from_submodule record each
type mismatch; _perform_load raises a targeted ValueError naming the
module and the actual type at its final failure point. When the object
is an App, the error suggests exporting it under the name app.
Fallthrough behavior is preserved: a mismatch in one pattern does not
block a later pattern from loading successfully, and the generic
not-found message is unchanged for the genuinely-missing case.

Testing Plan

  • New unit tests in tests/unittests/cli/utils/test_agent_loader.py:
    • test_wrong_type_root_agent_raises_targeted_error
    • test_app_exported_as_root_agent_suggests_app_name
    • test_wrong_type_root_agent_in_agent_module_raises_targeted_error
    • test_valid_agent_module_wins_over_mistyped_package_root_agent
  • pytest tests/unittests/cli -n auto: 774 passed, 5 skipped, 4 xfailed, 376 warnings in 84.37s (0:01:24)
  • tox (full multi-version matrix): py310 OK, py312 OK, py313 OK, py314 OK.
    py311 has one failure in
    tests/unittests/sessions/migration/test_migration.py::test_migrate_from_sqlalchemy_pickle_preserves_nested_safe_actions_pickle
    that is unrelated to this change and reproduces identically on main:
    the migration unpickler's _ALLOWED_PICKLE_GLOBALS blocks
    builtins.getattr only in the py311 environment (the one where the
    crewai extras install per the pyproject markers). This diff touches
    only cli/utils/agent_loader.py and its test file. Filed separately.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Aug 7, 2026
loponly added 4 commits August 7, 2026 23:11
When a module defines root_agent with a non-agent type, AgentLoader now
raises a targeted ValueError naming the module and the actual type (with
a hint to use the name 'app' when the object is an App), instead of the
misleading generic not-found error. Fixes google#6606.
@loponly
loponly force-pushed the fix/agent-loader-root-agent-type-error branch from e32eff7 to 9a19844 Compare August 7, 2026 15:11
@loponly

loponly commented Aug 7, 2026

Copy link
Copy Markdown
Author

@googlebot I signed it!

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