Skip to content

Send anthropic_beta flags to Anthropic and Bedrock - #754

Open
yorzi wants to merge 2 commits into
activeagents:mainfrom
yorzi:fix/anthropic-beta-option-forwarding
Open

yorzi wants to merge 2 commits into
activeagents:mainfrom
yorzi:fix/anthropic-beta-option-forwarding

Conversation

@yorzi

@yorzi yorzi commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What this does

anthropic_beta is an option of the Anthropic and Bedrock providers. AnthropicProvider#api_prompt_executer reads it to choose client.beta.messages, but the option is extracted from the provider's kwargs into options, so it never reached context, and Anthropic::Request never saw it. The result on main:

  • generate_with :anthropic, anthropic_beta: "context-1m-2025-08-07" called the beta endpoint with no anthropic-beta header, so the flag did nothing;
  • a request with MCP servers always sent mcp-client-2025-04-04, whatever was configured;
  • on Bedrock, the flag would have gone out as an HTTP header, but InvokeModel reads beta flags from the body's anthropic_beta, and neither the SDK's BedrockClient nor Bedrock::BearerClient moves it there.

The change:

  • AnthropicProvider#initialize copies options.anthropic_beta into the request context;
  • Anthropic::Request splits the option on commas into betas, and with MCP servers adds mcp-client-2025-04-04 unless an mcp-client- flag is already listed (so adding a context beta does not drop the MCP one);
  • BedrockProvider#api_prompt_execute moves betas into request_options: { extra_body: { anthropic_beta: [...] } }, for both the SigV4 and the bearer-token client.

The anthropic_beta line in docs/providers/anthropic.md now says what the option takes and where it goes.

Tests

test/providers/anthropic/beta_option_test.rb (WebMock, no cassettes):

  • a configured flag arrives as the anthropic-beta header on the Messages API;
  • two configured flags arrive as the Bedrock InvokeModel body's anthropic_beta array;
  • with MCP servers, a configured flag is sent next to mcp-client-2025-04-04, and the default alone when nothing is configured;
  • a configured mcp-client- flag replaces the default (guard; passes before too);
  • a configured flag appears in preview.

The header, Bedrock body, MCP and preview tests fail on main. The existing Anthropic and Bedrock provider and integration tests (test/providers/anthropic/, test/providers/bedrock/, test/integration/anthropic/) pass.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the contributing guide
  • This fits activeagent's stated focus
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my use case

Related issue

Fixes #750

Quality check

  • The project's hooks and linters pass (bin/rubocop on the changed files)
  • The new tests fail before this change and pass after it
  • The full test suite passes (run in full, Ruby 3.3.5, gemfiles/rails8.gemfile: 4731 runs, 0 failures, 11 errors, 66 skips. The 11 errors are all in actionagent/test/cli_contract_test.rb and are the same on unmodified main in my environment (NoMethodError: undefined method id' for an instance of Hashin rack-session under WebMock'sto_rack`), so they are unrelated to this change)
  • I updated documentation where needed (docs/providers/anthropic.md, CHANGELOG entry)
  • I didn't edit generated files by hand

Ownership

  • I understand every line of this change and can answer questions about it

API changes

  • Breaking change
  • New public methods or classes
  • Changed method signatures
  • No API changes

Not verified against the live APIs: the tests check the outgoing HTTP request only. The Bedrock body field follows AWS's Anthropic Claude Messages API reference (anthropic_beta in the InvokeModel body).

yorzi added 2 commits December 3, 2026 22:24
The client option selected the beta resource but never reached request
construction. Bedrock also needs the flag list in the invocation body.
Sending only the configured flags dropped mcp-client-2025-04-04 from a
request with MCP servers, which the API then rejects. Add the default
MCP beta unless an mcp-client- flag is already listed. Describe the
option in the provider guide and the changelog.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

anthropic_beta is never sent to Anthropic or Bedrock

1 participant