Skip to content

Commit 1860079

Browse files
author
Chris Brown
committed
Exclude additional_beta_flags from filtered_kwargs too
Copilot's review on the original fix pointed out the exclusion only covered the options-dict copy, not kwargs passed directly to _prepare_options — so additional_beta_flags supplied as a raw kwarg would still leak through and reproduce the same TypeError. Add the same exclusion to filtered_kwargs for consistency, with a regression test covering the kwarg path.
1 parent 091be73 commit 1860079

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎python/packages/anthropic/agent_framework_anthropic/_chat_client.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,9 @@ def _prepare_options(
594594
# This includes underscore-prefixed internal objects (like _function_middleware_pipeline)
595595
# and framework kwargs like 'thread' and 'middleware'.
596596
filtered_kwargs = {
597-
k: v for k, v in kwargs.items() if not k.startswith("_") and k not in {"thread", "middleware"}
597+
k: v
598+
for k, v in kwargs.items()
599+
if not k.startswith("_") and k not in {"thread", "middleware", "additional_beta_flags"}
598600
}
599601
_apply_option_translations(filtered_kwargs)
600602
run_options.update(filtered_kwargs)

‎python/packages/anthropic/tests/test_anthropic_client.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,27 @@ async def test_prepare_options_consumes_additional_beta_flags(
12911291
assert "extended-cache-ttl-2025-04-11" in run_options["betas"]
12921292

12931293

1294+
async def test_prepare_options_drops_additional_beta_flags_passed_as_kwarg(
1295+
mock_anthropic_client: MagicMock,
1296+
) -> None:
1297+
"""additional_beta_flags must also be excluded when passed as a raw kwarg,
1298+
not just via the options dict.
1299+
1300+
Flagged in code review on the fix for #5764: the initial fix only excluded
1301+
the key from the options-dict copy, but filtered_kwargs (built from
1302+
**kwargs at the call site) had no equivalent exclusion, so
1303+
``_prepare_options(messages, {}, additional_beta_flags=[...])`` would still
1304+
forward the raw key and reproduce the same TypeError.
1305+
"""
1306+
client = create_test_anthropic_client(mock_anthropic_client)
1307+
1308+
messages = [Message(role="user", contents=["Hello"])]
1309+
1310+
run_options = client._prepare_options(messages, {}, additional_beta_flags=["extended-cache-ttl-2025-04-11"])
1311+
1312+
assert "additional_beta_flags" not in run_options
1313+
1314+
12941315
async def test_prepare_options_filters_internal_kwargs(
12951316
mock_anthropic_client: MagicMock,
12961317
) -> None:

0 commit comments

Comments
 (0)