Skip to content

Commit d042ecc

Browse files
fix: narrow A2A warning filter to exact remote_a2a_agent module
Address Copilot review: scope the module regex from the broad `^google\.adk\.` prefix to the exact `^google\.adk\.agents\.remote_a2a_agent$` module where the warning originates. This prevents accidentally suppressing experimental warnings from other google.adk submodules. Also adds a test verifying that warnings from other google.adk modules are not affected by the filter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Optimus (AI Agent) <agent@fulcria.com>
1 parent 728c250 commit d042ecc

2 files changed

Lines changed: 47 additions & 12 deletions

File tree

python/packages/kagent-adk/src/kagent/adk/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
# isort: off
1313
# Show the A2A experimental warning once per process instead of on every call (#1379).
14-
# Scoped to UserWarning from google.adk modules to avoid suppressing unrelated warnings.
15-
warnings.filterwarnings("once", message=r"\[EXPERIMENTAL\].*A2A", category=UserWarning, module=r"^google\.adk\.")
14+
# Scoped to UserWarning from the specific remote_a2a_agent module to avoid suppressing unrelated warnings.
15+
warnings.filterwarnings(
16+
"once",
17+
message=r"\[EXPERIMENTAL\].*A2A",
18+
category=UserWarning,
19+
module=r"^google\.adk\.agents\.remote_a2a_agent$",
20+
)
1621
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH, DEFAULT_TIMEOUT, RemoteA2aAgent # noqa: E402
1722
# isort: on
1823
from google.adk.models.anthropic_llm import Claude as ClaudeLLM

python/packages/kagent-adk/tests/unittests/test_a2a_warning_filter.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ def test_a2a_warning_shown_once():
88
with warnings.catch_warnings(record=True) as caught:
99
warnings.simplefilter("always")
1010

11-
# Re-install the filter as types.py does at import time (scoped to google.adk)
11+
# Re-install the filter as types.py does at import time
12+
# (scoped to the specific remote_a2a_agent module)
1213
warnings.filterwarnings(
1314
"once",
1415
message=r"\[EXPERIMENTAL\].*A2A",
1516
category=UserWarning,
16-
module=r"^google\.adk\.",
17+
module=r"^google\.adk\.agents\.remote_a2a_agent$",
1718
)
1819

19-
# Simulate a warning from a google.adk module by executing in a
20+
# Simulate a warning from the exact upstream module by executing in a
2021
# namespace whose __name__ matches the module filter.
21-
adk_globals = {"__name__": "google.adk.a2a.remote", "__file__": __file__}
22+
adk_globals = {"__name__": "google.adk.agents.remote_a2a_agent", "__file__": __file__}
2223
code = compile(
2324
'import warnings; warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)',
2425
"<test>",
@@ -29,11 +30,11 @@ def test_a2a_warning_shown_once():
2930
assert len(caught) == 1, "First A2A warning should be recorded"
3031

3132
exec(code, adk_globals) # noqa: S102
32-
assert len(caught) == 1, "Duplicate A2A warning from google.adk should be suppressed"
33+
assert len(caught) == 1, "Duplicate A2A warning from remote_a2a_agent should be suppressed"
3334

3435

3536
def test_filter_does_not_suppress_non_adk_warnings():
36-
"""The filter should not suppress warnings from modules outside google.adk."""
37+
"""The filter should not suppress warnings from modules outside remote_a2a_agent."""
3738
with warnings.catch_warnings(record=True) as caught:
3839
warnings.simplefilter("always")
3940

@@ -42,13 +43,42 @@ def test_filter_does_not_suppress_non_adk_warnings():
4243
"once",
4344
message=r"\[EXPERIMENTAL\].*A2A",
4445
category=UserWarning,
45-
module=r"^google\.adk\.",
46+
module=r"^google\.adk\.agents\.remote_a2a_agent$",
4647
)
4748

48-
# A warning from the current test module (not google.adk.*) should not be suppressed
49+
# A warning from the current test module (not remote_a2a_agent) should not be suppressed
4950
warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)
5051
assert len(caught) == 1
5152

5253
warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)
53-
# Both should be recorded because this module is not google.adk.*
54-
assert len(caught) == 2, "Warnings from non-google.adk modules should not be suppressed"
54+
# Both should be recorded because this module is not google.adk.agents.remote_a2a_agent
55+
assert len(caught) == 2, "Warnings from non-remote_a2a_agent modules should not be suppressed"
56+
57+
58+
def test_filter_does_not_suppress_other_adk_modules():
59+
"""The filter should not suppress warnings from other google.adk submodules."""
60+
with warnings.catch_warnings(record=True) as caught:
61+
warnings.simplefilter("always")
62+
63+
# Install the scoped filter (exact module match only)
64+
warnings.filterwarnings(
65+
"once",
66+
message=r"\[EXPERIMENTAL\].*A2A",
67+
category=UserWarning,
68+
module=r"^google\.adk\.agents\.remote_a2a_agent$",
69+
)
70+
71+
# A warning from a different google.adk submodule should NOT be suppressed
72+
other_adk_globals = {"__name__": "google.adk.a2a.executor", "__file__": __file__}
73+
code = compile(
74+
'import warnings; warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)',
75+
"<test>",
76+
"exec",
77+
)
78+
79+
exec(code, other_adk_globals) # noqa: S102
80+
assert len(caught) == 1
81+
82+
exec(code, other_adk_globals) # noqa: S102
83+
# Both should be recorded because the module doesn't match remote_a2a_agent exactly
84+
assert len(caught) == 2, "Warnings from other google.adk modules should not be suppressed"

0 commit comments

Comments
 (0)