fix(agents): stop internal Agent Config subclassing from warning on plain imports - #6970
Open
chelsealong wants to merge 1 commit into
Open
Conversation
…lain imports Importing LlmAgent, SequentialAgent, LoopAgent, or ParallelAgent emitted a BaseAgentConfig DeprecationWarning purely because ADK's own internal config subclasses (LlmAgentConfig, etc.) subclass the deprecated BaseAgentConfig at module load time. Applications that never touch the deprecated YAML Agent Config feature saw the warning anyway, breaking test suites that treat deprecations as errors. Scope the warning suppression to just the internal import of each config module, so an application that actually imports or instantiates the deprecated config classes directly still gets warned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Problem:
Importing the public
LlmAgent,SequentialAgent,LoopAgent, orParallelAgentclasses emits aBaseAgentConfigDeprecationWarning, evenwhen the application never imports or uses the deprecated YAML Agent Config
feature. Test suites that treat deprecations as errors fail during an
ordinary ADK import:
The root cause: ADK's own internal config classes (
LlmAgentConfig,SequentialAgentConfig,LoopAgentConfig,ParallelAgentConfig) subclassthe deprecated
BaseAgentConfig.typing_extensions.deprecatedwarns onany subclassing of a deprecated class, so simply defining these built-in
subclasses at import time — before any application code touches Agent
Config — triggers the warning.
Solution:
Scope a
warnings.catch_warnings()suppression around just the internalimport of each
*_agent_configmodule inllm_agent.py,sequential_agent.py,loop_agent.py, andparallel_agent.py. This only silences the warning atthe exact point ADK defines its own internal subclasses; it does not touch
BaseAgentConfig's deprecation machinery itself, so applications thatactually use the deprecated Agent Config APIs (importing a config class
directly, instantiating
BaseAgentConfig, or subclassing it themselves)still get warned as before.
Testing Plan
Unit Tests:
Added
tests/unittests/agents/test_import_deprecation_warnings.py, whichruns imports in a fresh subprocess with
-W error::DeprecationWarning(somodule caching across tests can't hide the warning), per the reproduction
approach the issue itself suggested.
Confirmed the new test fails without the fix (checked out the pre-fix source
files against the new test):
And passes with the fix:
Manually verified genuine Agent Config usage still warns:
Ran the full unit test suite:
Formatted and linted with
pyink/isortperCONTRIBUTING.md;pylintscore on the touched files is unchanged from
main(9.20 vs 9.21, samepre-existing warnings, none introduced by this change).
Manual End-to-End (E2E) Tests:
Not applicable — this is an import-time warning fix with no behavioral
change to runtime agent execution.
Checklist
AI assistance disclosure
This change was written with the assistance of an AI coding agent (Claude),
with the diff reviewed and tests verified by the submitter before opening
this PR.