adk deploy agent_engine no longer validates that the agent imports (regressed in 2.2.0); broken agents deploy cleanly and fail only at query time
Describe the bug
When adk deploy agent_engine switched to a Dockerfile-based build in v2.2.0 (ffa057c1), the pre-deployment _validate_agent_import() call introduced in v1.24.0 (2ac468ea) was removed while leaving --validate-agent-import and --skip-agent-import-validation as no-op deprecated flags.
Because the container entrypoint (adk api_server /app/agents) loads agents lazily on the first request via agent_loader, an agent with a broken import (e.g., an out-of-directory sibling import without --extra_packages, a missing requirement, or a module-level exception) or a missing root_agent/app definition builds and starts cleanly (Application startup complete). The deployment LRO succeeds with exit code 0, overwriting the live runtime if --agent_engine_id was passed, and the failure only surfaces on the first query (400 FAILED_PRECONDITION: Reasoning Engine Execution failed ... Error Details: with empty error details, while ModuleNotFoundError only appears in Cloud Logging).
Steps to Reproduce
- Create an agent
my_agent/agent.pythat imports a nonexistent module (import non_existent_pkg). - Run
adk deploy agent_engine --project=<project> --region=us-central1 my_agent. - Observe that deployment succeeds (exit code 0).
- Query the deployed runtime with
async_stream_query("ping")and observe400 FAILED_PRECONDITIONwith emptyError Details, while Cloud Logging recordsModuleNotFoundError: Fail to load 'my_agent' module.
Expected behavior
- Validate that
<app_name>.agentcan be imported and definesroot_agentorappduring the container image build (afterpip install -r requirements.txtandextra_packagessetup in the generated Dockerfile), so a broken agent fails the image build and leaves the previous revision serving. - Wire
--validate-agent-import(enabled by default) and--no-validate-agent-import/--skip-agent-import-validationto control this build-time check for agents that require runtime-only credentials at import time.
Thanks so much for offering to take this on, @aditya-upadhye! Just a quick heads-up so we don't duplicate effort — I already have a fix for this in review right now, which will sync out to main once approved. Really appreciate you jumping in!
@hlzuo, confirmed on 2.14.1: an agent with import non_existent_pkg deploys with exit 0 even with --validate-agent-import, and _validate_agent_import() is never called after the 2.2.0 Dockerfile switch.
Until your change lands, one workaround that worked for me is running python -c "import my_agent.agent" (or a small wrapper doing that in a clean subprocess) before deploying. The broken agent then stops before anything gets pushed.
Could you link your in-review change here once it’s up? It’d be good to check that it adds the import step to the Dockerfile after pip install, turns the flag on by default, and skips YAML config agents.
Please test it with a real image build too (broken import, missing root_agent, and an agent that needs credentials at import time with --no-validate-agent-import) before it syncs to main.