Skip to content

fix(agents): stop internal Agent Config subclassing from warning on plain imports - #6970

Open
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-6968-suppress-internal-agent-config-import-warning
Open

fix(agents): stop internal Agent Config subclassing from warning on plain imports#6970
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-6968-suppress-internal-agent-config-import-warning

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Problem:

Importing the public LlmAgent, SequentialAgent, LoopAgent, or
ParallelAgent classes emits a BaseAgentConfig DeprecationWarning, even
when 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:

$ python -W error::DeprecationWarning -c 'from google.adk.agents import LlmAgent, SequentialAgent'
...
DeprecationWarning: BaseAgentConfig is deprecated and will be removed in future versions. ...

The root cause: ADK's own internal config classes (LlmAgentConfig,
SequentialAgentConfig, LoopAgentConfig, ParallelAgentConfig) subclass
the deprecated BaseAgentConfig. typing_extensions.deprecated warns on
any 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 internal
import of each *_agent_config module in llm_agent.py, sequential_agent.py,
loop_agent.py, and parallel_agent.py. This only silences the warning at
the exact point ADK defines its own internal subclasses; it does not touch
BaseAgentConfig's deprecation machinery itself, so applications that
actually 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:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added tests/unittests/agents/test_import_deprecation_warnings.py, which
runs imports in a fresh subprocess with -W error::DeprecationWarning (so
module 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):

FAILED tests/unittests/agents/test_import_deprecation_warnings.py::test_importing_runtime_agents_does_not_warn_about_agent_config
...
DeprecationWarning: BaseAgentConfig is deprecated and will be removed in future versions. ...

And passes with the fix:

tests/unittests/agents/test_import_deprecation_warnings.py::test_importing_runtime_agents_does_not_warn_about_agent_config PASSED
tests/unittests/agents/test_import_deprecation_warnings.py::test_directly_importing_llm_agent_config_still_warns PASSED
2 passed in ...

Manually verified genuine Agent Config usage still warns:

$ python -W error::DeprecationWarning -c "from google.adk.agents import LlmAgentConfig"
DeprecationWarning: BaseAgentConfig is deprecated and will be removed in future versions. ...

$ python -W error::DeprecationWarning -c "
from google.adk.agents import LlmAgent
from google.adk.agents.base_agent_config import BaseAgentConfig
BaseAgentConfig(name='x')
"
DeprecationWarning: BaseAgentConfig is deprecated and will be removed in future versions. ...

Ran the full unit test suite:

$ python -m pytest tests/unittests -q
13534 passed, 81 skipped, 26 xfailed, 2 xpassed, 2942 warnings, 24 subtests passed in 449.62s

Formatted and linted with pyink/isort per CONTRIBUTING.md; pylint
score on the touched files is unchanged from main (9.20 vs 9.21, same
pre-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

  • 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. (N/A, import-time-only fix; see testing plan)
  • Any dependent changes have been merged and published in downstream modules. (N/A)

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.

…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.
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.

[BUG]: importing LlmAgent emits BaseAgentConfig deprecation warning from ADK internals

2 participants