Repository navigation
Description
Description
agent-framework-anthropic leaks per-run additional_beta_flags into the raw Anthropic request kwargs.
Passing additional_beta_flags per run is consumed by _prepare_betas(...), but the key remains in the final request kwargs and causes:
TypeError: AsyncMessages.create() got an unexpected keyword argument 'additional_beta_flags'
Workaround: set beta flags on the AnthropicClient constructor instead of per-run options.
Environment
- Repo:
microsoft/agent-framework - Local commit tested:
4ad96b64e755f5d25d5b859e1c7b43b64088a56f - Python packages installed editable from local repo:
python/packages/corepython/packages/anthropic
agent-framework-core:1.3.0agent-framework-anthropic:1.0.0b260507anthropic:0.80.0- Python:
3.14 - Model tested:
claude-opus-4-7
Minimal repro
import asyncio
import os
from typing import Annotated
from agent_framework import Agent, tool
from agent_framework.anthropic import AnthropicClient
@tool(approval_mode="never_require")
def lookup_ticket(ticket_id: Annotated[str, "Ticket id"]) -> str:
"""Look up a test ticket."""
return '{"ticket_id":"40076","status":"open","priority":"high"}'
async def main():
client = AnthropicClient(
api_key=os.environ["ANTHROPIC_API_KEY"],
model="claude-opus-4-7",
)
agent = Agent(
client=client,
name="AnthropicOptionsRepro",
instructions="Use lookup_ticket exactly once for ticket 40076, then summarize it.",
tools=[lookup_ticket],
default_options={
"model": "claude-opus-4-7",
"max_tokens": 4096,
"thinking": {"type": "adaptive", "display": "omitted"},
"output_config": {"effort": "low"},
"additional_beta_flags": ["extended-cache-ttl-2025-04-11"],
"tools": [lookup_ticket],
},
)
async for chunk in agent.run("Validate ticket 40076 now.", stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
asyncio.run(main())Expected: additional_beta_flags should be consumed into betas only.
Actual: it is also forwarded as a raw kwarg to AsyncMessages.create(...), which rejects it.
Root cause
From agent_framework_anthropic/_chat_client.py:
_prepare_options(...)copies all options exceptinstructionsandresponse_formatintorun_options._prepare_betas(...)consumesadditional_beta_flagsintobetas.additional_beta_flagsis not removed fromrun_optionsbefore callingAsyncMessages.create(...).
Compatibility note: Opus 4.7 thinking shape
With additional_beta_flags moved to the AnthropicClient constructor as a workaround, a live streaming local-tool loop succeeds with:
thinking={"type": "adaptive", "display": "omitted"}
output_config={"effort": "low"}This is the expected Opus 4.7 API shape. thinking={"type":"enabled","budget_tokens":...} is expected to return a 400 on Opus 4.7 and is not being reported as a bug here.
There is a separate type/doc freshness gap: agent_framework_anthropic._chat_client.ThinkingConfig currently documents only enabled / disabled plus budget_tokens, while Opus 4.7 uses adaptive thinking. The runtime pass-through works, so this is documentation/typing freshness rather than the runtime failure above.
Expected fix
Pop/filter additional_beta_flags from run_options after consuming it into betas, before dispatching to Anthropic.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rg-ve commentedon May 12, 2026
Additional data point after filing:
I reran the same repro against
claude-opus-4-7.Results:
thinking={"type":"adaptive","display":"omitted"}+output_config={"effort":"low"}: passes for Opus 4.7. The streaming tool loop calls the local function and returns the tool result.thinkingomitted entirely: passes for Opus 4.7.thinking={"type":"enabled","budget_tokens":1024}: fails for Opus 4.7 with:So the adaptive omitted replay failure I reported appears with
claude-sonnet-4-6, while Opus 4.7 requires the adaptive/output_config shape and handles this particular tool-loop repro correctly.The separate
additional_beta_flagsissue still reproduces in the request-shape path:_prepare_options()consumes it intobetasbut leavesadditional_beta_flagsin the final raw Anthropic kwargs if passed per-run. In my live runs I worked around that by setting beta flags on theAnthropicClientconstructor.[-]Python Anthropic: adaptive omitted thinking fails after tool call; additional_beta_flags leaks into request kwargs[/-][+]Python Anthropic: additional_beta_flags leaks into request kwargs; ThinkingConfig docs/types omit adaptive thinking[/+][-]Python Anthropic: additional_beta_flags leaks into request kwargs; ThinkingConfig docs/types omit adaptive thinking[/-][+]Python Anthropic: additional_beta_flags leaks; thinking docs/types stale for Opus 4.7[/+][-]Python Anthropic: additional_beta_flags leaks; thinking docs/types stale for Opus 4.7[/-][+]Python Anthropic: per-run additional_beta_flags leaks into request kwargs[/+]github-actions commentedon May 12, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
Repro: AnthropicClient._prepare_options() in python/packages/anthropic/agent_framework_anthropic/_chat_client.py copies all options into run_options (line 582-583) and calls _prepare_betas() (line 619) which reads additional_beta_flags, but never pops the key from run_options. When run_options is unpacked into AsyncMessages.create(**run_options) at lines 542/551, the unexpected kwarg causes TypeError. Fix: add run_options.pop("additional_beta_flags", None) after line 619, similar to the existing pop of allow_multiple_tool_calls at line 586.
python/packages/anthropic/tests/test_beta_flags_leak_5764.py1.0.0b2605071.0.0b260507Oxygen56 commentedon Jun 10, 2026
Hi Evan Mattson (@moonbox3) — I noticed this has been assigned for a while. The fix looks well-scoped (just a
run_options.pop("additional_beta_flags", None)after_prepare_betas()in_chat_client.py, mirroring the existingallow_multiple_tool_callspop pattern).Happy to submit a PR if you're not already working on it — no worries at all if you'd rather handle it yourself. Just wanted to offer since I recently contributed a fix to this repo (#6270) and am looking for a good next issue to pick up.
Python: fix per-run additional_beta_flags leaking into Anthropic requ…