From 8ce9ff6a221a04299de5912a8b22c9d6270a565e Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Tue, 12 May 2026 16:19:03 +0800 Subject: [PATCH] fix: consume anthropic beta flags --- .../agent_framework_anthropic/_chat_client.py | 1 + .../anthropic/tests/test_anthropic_client.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/python/packages/anthropic/agent_framework_anthropic/_chat_client.py b/python/packages/anthropic/agent_framework_anthropic/_chat_client.py index 98c181f152..b4982deeaa 100644 --- a/python/packages/anthropic/agent_framework_anthropic/_chat_client.py +++ b/python/packages/anthropic/agent_framework_anthropic/_chat_client.py @@ -617,6 +617,7 @@ def _prepare_options( # betas run_options["betas"] = self._prepare_betas(options) + run_options.pop("additional_beta_flags", None) # extra headers run_options["extra_headers"] = {"User-Agent": get_user_agent()} diff --git a/python/packages/anthropic/tests/test_anthropic_client.py b/python/packages/anthropic/tests/test_anthropic_client.py index 0cfec3423c..3c5b830a59 100644 --- a/python/packages/anthropic/tests/test_anthropic_client.py +++ b/python/packages/anthropic/tests/test_anthropic_client.py @@ -946,6 +946,24 @@ async def test_prepare_options_with_tool_choice_auto( assert "allow_multiple_tool_calls" not in run_options +async def test_prepare_options_consumes_additional_beta_flags( + mock_anthropic_client: MagicMock, +) -> None: + client = create_test_anthropic_client(mock_anthropic_client) + + messages = [Message(role="user", contents=["Hello"])] + run_options = client._prepare_options( + messages, + { + "model": "claude-3-5-sonnet-20241022", + "additional_beta_flags": ["extended-cache-ttl-2025-04-11"], + }, + ) + + assert "extended-cache-ttl-2025-04-11" in run_options["betas"] + assert "additional_beta_flags" not in run_options + + async def test_prepare_options_with_tool_choice_required( mock_anthropic_client: MagicMock, ) -> None: