Skip to content

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

Closed

Description

@aweussom

When a module exposes a root_agent that is not a BaseAgent, AgentLoader detects the
exact problem, formats it with the offending type, writes it to a logger.warning, and
then falls through to raise an error describing something else entirely.

What the user sees

ValueError: No root_agent found for 'agent'. Searched in 'agent.agent.root_agent',
'agent.root_agent' and 'agent/root_agent.yaml'.

Expected directory structure:
  <agents_dir>/
    agent/
      agent.py (with root_agent) OR
      root_agent.yaml

Then run: adk web <agents_dir>

Ensure '/path/to/agents/judge' is structured correctly, an .env file can be loaded if
present, and a root_agent is exposed.

HINT: It looks like this command might be running from inside an agent directory. Run it
from the parent directory that contains your agent folder (for example the project root)
so the loader can locate your agents.

Every actionable statement in that message 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 sends you to restructure a working layout.

The actual cause

google/adk/cli/utils/agent_loader.py::_load_from_module_or_package (v1.28.0):

if hasattr(module_candidate, "app") and isinstance(module_candidate.app, App):
    return module_candidate.app
elif hasattr(module_candidate, "root_agent"):
    if isinstance(module_candidate.root_agent, BaseAgent):
        return module_candidate.root_agent
    else:
        logger.warning(
            "Root agent found is not an instance of BaseAgent. But a type %s",
            type(module_candidate.root_agent),
        )

The contract is that an App must be exported as app, and root_agent must be a
BaseAgent. My module did this:

root_agent = App(name="judge", root_agent=judge_agent)   # wrong
app = App(name="judge", root_agent=judge_agent)          # right

Reasonable mistake to make — App has a root_agent field, so assigning an App to a
module-level root_agent reads naturally, and the sample I was working from imports App
without showing the export name.

Reproduction

# agents/judge/agent.py
from google.adk.agents import Agent
from google.adk.apps.app import App

root_agent = App(name="judge", root_agent=Agent(name="judge", model="gemini-3-flash-preview"))

Load it with AgentLoader. At default log level the WARNING is invisible and you get the
directory-structure message.

Suggested fix

When the type-mismatch branch is taken, remember it and raise with that instead of the
generic not-found error. Roughly:

mismatched_type = None
...
else:
    mismatched_type = type(module_candidate.root_agent)
    logger.warning(...)
...
if mismatched_type is not None:
    raise ValueError(
        f"'{agent_name}.root_agent' is a {mismatched_type.__name__}, not a BaseAgent. "
        f"If you meant to export an App, name it `app` instead of `root_agent`."
    )
raise ValueError("No root_agent found ...")

The information is already computed; it is just being thrown away. Suppressing the
directory-structure diagram and the wrong-directory HINT in this case would also help,
since both actively mislead.

Impact

Low severity, high friction. Cost for one user was reading the loader source to discover a
naming contract. Anyone hitting it will plausibly restructure a correct directory tree
first, because that is what the error tells them to do.


Environment: google-adk 1.28.0, Python 3.12, Ubuntu 24.04 (WSL2).

Activity

  1. nightcityblade commented on Aug 6, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

  2. added theissue type on Aug 6, 2026
  3. added
    core
    on Aug 6, 2026
  4. self-assigned this
    on Aug 6, 2026
  5. sanketpatil06 commented on Aug 6, 2026

    @sanketpatil06

    Hi @aweussom, Could you please try out the latest google-adk version and let us know your observations?

  6. added
    request clarification
    on Aug 6, 2026
  7. loponly commented on Aug 7, 2026

    @loponly
    Contributor

    Hi, I'd like to work on this one if it's available.

    I can still reproduce it on current main: _load_from_module_or_package and _load_from_submodule in cli/utils/agent_loader.py log the type mismatch at WARNING but then return None, so load_agent falls through to the generic ValueError: No root_agent found with the directory-structure hint, which points users in the wrong direction when their layout is actually correct.

    Plan: track the mismatched type observed by the loader helpers and raise a targeted error instead (e.g. '<app>.root_agent' is a <type>, not a BaseAgent — if you are exporting an App, name it 'app'), keeping the existing not-found message for the genuinely-missing case, plus unit tests for both loader paths. Will follow up with a PR.

  8. added a commit that references this issue on Aug 7, 2026
    ac958b8
  9. Diwak4r commented on Aug 9, 2026

    @Diwak4r
    Contributor

    Fixed in #6659: the loader now remembers the type mismatch instead of discarding it, and raises a precise error naming the offending type and location (e.g. 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 generic "No root_agent found" path with the directory-structure diagram and HINT is no longer hit for this failure. Both dispatch paths (module and {agent}/agent.py submodule) are covered by new unit tests.

  10. aweussom commented on Aug 10, 2026

    @aweussom
    Author

    @sanketpatil06 Thanks for the nudge — I've retested on the latest release. It still reproduces.

    Environment: google-adk 2.6.3, Python 3.12.3, clean venv, Ubuntu 24.04 (WSL2). Original report was 1.28.0.

    Repro, unchanged from the original:

    # agents/judge/agent.py
    from google.adk.agents import Agent
    from google.adk.apps.app import App
    
    root_agent = App(name="judge", root_agent=Agent(name="judge", model="gemini-3-flash-preview"))
    from google.adk.cli.utils.agent_loader import AgentLoader
    AgentLoader(agents_dir="agents").load_agent("judge")

    At WARNING level the diagnosis is still computed and still discarded:

    WARNING:google_adk.google.adk.cli.utils.agent_loader:Root agent found is not an
    instance of BaseAgent. But a type <class 'google.adk.apps.app.App'>
    

    and then, at default log level, you still get the message that describes a different problem:

    ValueError: No root_agent found for 'judge'. Searched in 'judge.agent.root_agent',
    'judge.root_agent' and 'judge/root_agent.yaml'.
    
    Expected directory structure:
      <agents_dir>/
        judge/
          agent.py (with root_agent) OR
          root_agent.yaml
    ...
    

    One thing that has changed since 1.28.0, and it's worth noting for whoever picks this up: the accepted-type tuple has widened to (BaseAgent, BaseNode) in both dispatch paths —

    if isinstance(module_candidate.root_agent, (BaseAgent, BaseNode)):
        return module_candidate.root_agent
    else:
        logger.warning(...)
    # ... falls through to return None

    — but the mismatch branch behaves identically: warn, return None, fall through to the generic not-found error. _load_from_module_or_package and _load_from_submodule both do this, so either layout hits it.

    Two small corrections to my original report while I'm here:

    • The wrong-directory HINT is conditional on cwd. I hit it because I was running from inside the agent directory; from the parent it doesn't appear. The misleading directory-structure diagram appears either way, so that's the part that reliably points people at a layout that was already correct.
    • Exporting it the documented way still works fine on 2.6.3 (app = App(...) → loads, returns App). So the naming contract survived the 1.x → 2.x major intact and the suggested fix still applies as written.

    Worth mentioning on priority: LoopAgent and SequentialAgent now emit removal notices in favour of Workflow, so a fair amount of existing sample-shaped code is going to need restructuring shortly. Anyone doing that migration who trips this error will be told to fix a directory layout that isn't the problem — so the payoff for a precise message goes up during the churn, not down.

    I see #6659 is open against this — the approach there matches what I had in mind, and it covers both dispatch paths. Happy to test a branch against my repro if that's useful.

  11. removed
    request clarification
    on Aug 11, 2026
  12. sanketpatil06 commented on Aug 13, 2026

    @sanketpatil06

    Hi @aweussom, thank you for confirming and providing those details. Could you please test the open PRs on your end and let us know if they resolve the issue before we proceed with merging?

  13. added
    request clarification
    on Aug 13, 2026
  14. aweussom commented on Aug 13, 2026

    @aweussom
    Author

    Tested both open PRs against my repro (each branch installed into a clean venv, each case run in a fresh process):

    Case #6635 #6659
    judge/agent.py with root_agent = App(...) (my repro) targeted error ✅ targeted error ✅
    module-level judge.py variant targeted error, judge.root_agent ✅ same ✅
    documented app = App(...) export loads, returns App (no regression) ✅ same ✅
    no root_agent at all generic not-found preserved ✅ same ✅

    #6659 on my repro:

    ValueError: 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`.
    

    #6635 on my repro:

    ValueError: A 'root_agent' was found for 'judge' but it is not a BaseAgent
    (or workflow node) instance:
      - 'judge.agent.root_agent' is of type 'google.adk.apps.app.App'
    
    Expose a BaseAgent instance named 'root_agent'.
    
    HINT: To serve an App, expose it under the name 'app' instead of 'root_agent'.
    

    Both resolve the issue as filed: the mismatch is raised with the real location and type instead of being logged and discarded, and both dispatch paths are covered. Either message would have sent me to the right fix immediately. No preference on which to merge — #6659's is more compact, #6635's carries the fully-qualified type and handles multiple mismatch locations (cosmetic nit on #6659: "a App").

  15. added a commit that references this issue on Aug 14, 2026
    4f07c93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

corerequest clarification

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions