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/core
python/packages/anthropic
agent-framework-core: 1.3.0
agent-framework-anthropic: 1.0.0b260507
anthropic: 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 except instructions and response_format into run_options.
_prepare_betas(...) consumes additional_beta_flags into betas.
additional_beta_flags is not removed from run_options before calling AsyncMessages.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.
Description
agent-framework-anthropicleaks per-runadditional_beta_flagsinto the raw Anthropic request kwargs.Passing
additional_beta_flagsper run is consumed by_prepare_betas(...), but the key remains in the final request kwargs and causes:Workaround: set beta flags on the
AnthropicClientconstructor instead of per-run options.Environment
microsoft/agent-framework4ad96b64e755f5d25d5b859e1c7b43b64088a56fpython/packages/corepython/packages/anthropicagent-framework-core:1.3.0agent-framework-anthropic:1.0.0b260507anthropic:0.80.03.14claude-opus-4-7Minimal repro
Expected:
additional_beta_flagsshould be consumed intobetasonly.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_flagsmoved to theAnthropicClientconstructor as a workaround, a live streaming local-tool loop succeeds with: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.ThinkingConfigcurrently documents onlyenabled/disabledplusbudget_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_flagsfromrun_optionsafter consuming it intobetas, before dispatching to Anthropic.