Repository navigation
Description
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_agentwas 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) # rightReasonable 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
nightcityblade commentedon Aug 6, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
sanketpatil06 commentedon Aug 6, 2026
Hi @aweussom, Could you please try out the latest
google-adkversion and let us know your observations?loponly commentedon Aug 7, 2026
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_packageand_load_from_submoduleincli/utils/agent_loader.pylog the type mismatch at WARNING but then returnNone, soload_agentfalls through to the genericValueError: No root_agent foundwith 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.fix: report root_agent type mismatch instead of 'No root_agent found'
Diwak4r commentedon Aug 9, 2026
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.pysubmodule) are covered by new unit tests.aweussom commentedon Aug 10, 2026
@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:
At
WARNINGlevel the diagnosis is still computed and still discarded:and then, at default log level, you still get the message that describes a different problem:
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 —— but the mismatch branch behaves identically: warn,
return None, fall through to the generic not-found error._load_from_module_or_packageand_load_from_submoduleboth do this, so either layout hits it.Two small corrections to my original report while I'm here:
HINTis 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.app = App(...)→ loads, returnsApp). So the naming contract survived the 1.x → 2.x major intact and the suggested fix still applies as written.Worth mentioning on priority:
LoopAgentandSequentialAgentnow emit removal notices in favour ofWorkflow, 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.
sanketpatil06 commentedon Aug 13, 2026
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?
aweussom commentedon Aug 13, 2026
Tested both open PRs against my repro (each branch installed into a clean venv, each case run in a fresh process):
judge/agent.pywithroot_agent = App(...)(my repro)judge.pyvariantjudge.root_agent✅app = App(...)exportApp(no regression) ✅root_agentat all#6659 on my repro:
#6635 on my repro:
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").
fix: report root_agent type mismatch instead of 'No root_agent found'