adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

fix: warn on deprecated Gemini model alias

Open he-yufeng opened this issue 5 months ago • 5 comments

Summary

  • warn when LLMRegistry.new_llm() sees the deprecated gemini-flash-latest alias
  • keep behavior unchanged: the configured model string is still passed through as-is
  • add regression coverage for both plain and gemini:-prefixed alias usage

Fixes #6010.

To verify

  • PYTHONPATH=src python -m pytest tests\unittests\models\test_models.py -q
  • python -m pyink --check src\google\adk\models\registry.py tests\unittests\models\test_models.py
  • git diff --check

he-yufeng avatar Jun 08 '26 03:06 he-yufeng

Response from ADK Triaging Agent

Hello @he-yufeng, thank you for creating this PR!

We noticed a couple of items from our contribution guidelines that could be added to help the review process:

  1. Summary of Passed Pytest Results: Please include the console output or a summary showing that the tests passed successfully when running pytest.
  2. Logs or Screenshots: For bug fixes or features, please provide logs or a screenshot of the fix in action (for example, showing the deprecation warning being logged when the deprecated alias is used).

This additional context will help the reviewers understand and verify the fix more efficiently. Thank you!

adk-bot avatar Jun 08 '26 03:06 adk-bot

🔍 ADK Pull Request Analysis: PR #6011

Title: fix: warn on deprecated Gemini model alias Author: @he-yufeng Status: open Impact: 35 additions, 0 deletions across 2 files

Executive Summary

  1. Core Objective: Warn users early when LLMRegistry.new_llm() is called with a deprecated Gemini alias (specifically 'gemini-flash-latest'), advising them to transition to versioned models (like 'gemini-2.5-flash') before experiencing runtime crashes.
  2. Justification & Value: Justified Fix - Startup validation warnings prevent downstream 404 NOT_FOUND client crashes during agent execution, heavily improving debugging/logging clarity on platform deployments like Cloud Run.
  3. Alignment with Principles: Pass - Features clean, private encapsulation boundaries, lazy key-evaluation logs, strict typing, and comprehensive behavior-focused parametrized unit tests.
  4. Recommendation: Approve (Zero changes or pushback needed).
Detailed Findings & Analysis

1. Objectives & Impact ("What does it do?")

  • Context & Background: Resolves Issue #6010. When older apps or tutorials make use of the gemini-flash-latest alias, the underlying backend (which maps it to gemini-2.0-flash) has been deprecated by Google. This surfaces as a silent 404 NOT_FOUND error far down the agent invocation chain, confounding developers because the error message mentions gemini-2.0-flash which they did not explicitly configure.
  • Implementation Mechanism:
    • Defines the map _deprecated_model_aliases mapping 'gemini-flash-latest' to 'gemini-2.5-flash'.
    • Implements the private helper method _warn_if_deprecated_alias that checks if the resolved model matches any entry in _deprecated_model_aliases and emits a warning on a match.
    • Plugs _warn_if_deprecated_alias into LLMRegistry.new_llm() immediately after model-parsing.
  • Affected Surface: No public namespace changes or API stability concerns; purely logs warnings.

2. Justification & Value ("Is it a valid and useful change?")

  • Workspace Verification:
    • Investigated registry.py in the active workspace.
    • Confirmed that baseline lacks explicit alias validation or deprecation warning checks when resolving or instantiating aliases like gemini-flash-latest.
  • Value Assessment: Highly valuable. Early reporting at creation/configuration time greatly simplifies troubleshooting configuration bugs.
  • Alternative Approaches:
    • Silently upgrading the string mapping internally: Decided against because versioned Gemini engines might exhibit minor quality differences; forcing auto-replacement can cause unwanted behavioral shifts. Emitting a warning leaves the control safely with the developer.
  • Scope & Depth: Systematic Fix / Root Cause - Resolves the systemic feedback problem for deprecated aliases by establishing an extensible _deprecated_model_aliases dictionary pattern for simple future updates.

3. Principle & Style Alignment Checklist ("Does it follow rules?")

  • Public API & Visibility Boundaries:
    • Status: Pass
    • Analysis: Keeps both _deprecated_model_aliases and _warn_if_deprecated_alias private to registry.py ensuring no public-facing changes to existing interfaces.
  • Code Quality, Typing & Conventions:
    • Status: Pass
    • Analysis: Consistently imports futurized annotations via from __future__ import annotations and type-hints parameters correctly. Strictly relies on lazy-evaluated logging templates (uses % format specifiers rather than eager f-strings in logger.warning).
  • Robustness & Edge Cases:
    • Status: Pass
    • Analysis: Properly processes plain aliases as well as those containing prefixed tags (like gemini:gemini-flash-latest) through the parser prior to execution.
  • Test Integrity & Quality:
    • Status: Pass
    • Analysis: Introduces test_new_llm_warns_for_deprecated_model_alias which parameterizes test cases, intercepts log entries with caplog, verifies type correctness to Gemini, and checks message contents under the Arrange-Act-Assert format.

adk-bot avatar Jun 08 '26 03:06 adk-bot

Hit this exact issue while building a multi-agent app for the ADK Hackathon — gemini-flash-latest silently mapping to a deprecated model caused confusing 404s on Cloud Run that were hard to trace back to the alias.

The startup warning in LLMRegistry.new_llm() is exactly the right fix — catches it early, no behavior change. Clean and minimal. Hope this gets merged soon!

pj0201 avatar Jun 09 '26 05:06 pj0201

Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

rohityan avatar Jun 09 '26 18:06 rohityan

Rebased this on current main and re-ran the focused local checks:

  • PYTHONPATH=src python -m pytest tests\unittests\models\test_models.py -q --basetemp .tmp\pytest-6011 -p no:cacheprovider -> 28 passed
  • python -m py_compile on the touched files
  • python -m pyink --check on the touched files
  • git diff --check origin/main..HEAD

All passed locally.

he-yufeng avatar Jun 12 '26 13:06 he-yufeng

Thanks for tackling #6010! We're going to pass on this one. We'd rather not maintain a static alias list, and the dynamic models.list() approach doesn't work as a signal (it only returns fully-versioned IDs, so it false-flags valid aliases like gemini-2.0-flash and *-latest, and varies by backend/region). We'll rely on the backend 404, which already reports the model as unavailable.

GWeale avatar Jun 16 '26 23:06 GWeale