Skip to content

feat(cli): support Python versions other than 3.11 in adk deploy images - #7747

Open
juliays wants to merge 2 commits into
google:mainfrom
juliays:feat/deploy-python-version
Open

juliays wants to merge 2 commits into
google:mainfrom
juliays:feat/deploy-python-version

Conversation

@juliays

@juliays juliays commented Oct 26, 2026

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
_DOCKERFILE_TEMPLATE hard-codes FROM python:3.11-slim, so agents whose dependencies require Python 3.12+ cannot be deployed with adk deploy (cloud_run, docker, gke, or agent_engine). Additionally, setting "python_version" in .agent_engine_config.json (which the Agent Engine SDK accepts) was previously a silent no-op for ADK deployments because ADK builds from a generated Dockerfile (image_spec = {}), where the SDK ignores python_version.

Solution:

  • Add --python_version (default 3.11) across all four adk deploy targets (cloud_run, docker, gke, agent_engine) and render FROM python:{python_version}-slim in _DOCKERFILE_TEMPLATE.
  • Validate python_version against a strict Python 3.11+ pattern (^3\.(1[1-9]|[2-9][0-9])(\.[0-9]+)?$) before interpolating into the Dockerfile and fail fast in to_agent_engine before staging files.
  • Support "python_version" in .agent_engine_config.json for adk deploy agent_engine (popped before calling client.runtimes.update), with precedence: explicit --python_version CLI flag > .agent_engine_config.json > '3.11'.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
uv run pytest tests/unittests/cli/utils/test_cli_deploy.py tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py tests/unittests/cli/utils/test_cli_tools_click.py
387 passed, 1 xfailed in 4.60s

Also verified uv run pre-commit run --files ... and uv run mypy on all touched files (no issues found).

Manual End-to-End (E2E) Tests:

# Deploy with an explicit Python version via CLI flag:
adk deploy cloud_run --python_version=3.12 --project=<project> --region=<region> path/to/my_agent

# Or via .agent_engine_config.json for Agent Engine:
# {"python_version": "3.12"}
adk deploy agent_engine --project=<project> --region=<region> path/to/my_agent

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

  • Follow-up documentation update can be opened in google/adk-docs for the CLI reference and deployment guides once this lands.

The generated Dockerfile hard-coded `FROM python:3.11-slim`, so an agent
whose dependencies need a newer interpreter could not be deployed with
`adk deploy` at all. Every target now takes `--python_version`:

    adk deploy cloud_run --python_version=3.12 path/to/my_agent

`agent_engine` also reads `python_version` from `.agent_engine_config.json`,
the key the Agent Engine SDK already defines. The SDK ignores that key when
the image is built from a Dockerfile, which is how ADK deploys, so the value
was previously a silent no-op; ADK now renders it into the Dockerfile and
drops it from the API request. An explicit flag overrides the file, and the
default stays 3.11 when neither is set.

Values are validated against a strict `3.<minor>[.<patch>]` pattern, 3.11
and up, before being interpolated into the Dockerfile, and the flag is
checked before any agent source is staged.

Fixes google#4784
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for overriding Python version in "adk deploy" commands

2 participants