fix: pick the Anthropic computer use tool version from the model on every platform (#31657)

#31521 made computer use send `computer_toolset_20260801` to Claude 4.8
and later, but swapped it back to `computer_20251124` on Claude Platform
on AWS and Bedrock, since Anthropic's docs say neither offers the
toolset. That's wrong for Claude Platform on AWS, so computer use on
dogfood's Opus 5.5 fails with `'claude-opus-5-5' does not support tool
types: computer_20251124`.

I probed the AI gateway, and Claude Platform on AWS accepts exactly the
versions the Claude API does, e.g. the toolset for Opus 4.8 and 5.5, and
`computer_20251124` for Opus 4.6. The harnesses that get this right
(Anthropic's computer-use demo and SDK toolset helpers, the Vercel AI
SDK, LiteLLM) pick the version from the model ID alone and leave the
wire format to the platform client, so we'll do the same and drop the
override. fantasy's doc comment repeated the docs, which
coder/fantasy#83 fixed, so this bumps fantasy too.

Bedrock follows the same model table. AWS's Opus 4.8 model card only
lists `computer_20251124`, but it's just behind: Anthropic's Bedrock
docs list Opus 4.8 as taking the toolset with no beta header, and
`anthropic.claude-opus-4-8` on Bedrock (via Mantle in us-east-1)
returned a `screenshot` tool call for the toolset with no beta.
Dogfood's InvokeModel route, which runs Opus 5.5, does the same.

Bedrock was also broken on `main`, since aibridge's Bedrock beta
allowlist drops `computer-use-2025-11-24`, so `computer_20251124` never
got through validation. I've added it. On InvokeModel, Opus 4.7 returned
a `computer` tool call for `computer_20251124` once the flag reached
Bedrock, but a 400 when the flag went through dogfood's gateway, which
runs `main` and drops it. Unlike the effort and context management
flags, the flag doesn't need gating per model, as Bedrock accepts it on
models that don't support `computer_20251124`. On Bedrock InvokeModel in
us-east-2, Haiku 4.5 returned a 200 with the flag on its own and with
`computer-use-2025-01-24` and a `computer_20250124` tool, whilst a
made-up flag got a 400. Bedrock only rejects the tool type itself, and
the model table never sends `computer_20251124` to Haiku 4.5 anyway.

InvokeModel does still run the provider's `settings.model` rather than
the model the chat config names, so the version can disagree with what
actually runs if the two differ. That's the known model swap in #29511,
and it's no worse here, as `main` picked the version from the model
config too. The documented setup is one provider per model, so the two
match, and the native `bedrock-runtime` protocol will remove the swap.

I verified Claude Platform on AWS end to end, running Coder Agents from
this branch against dogfood's AWS gateway route. Computer use on Opus
5.5 and Sonnet 5.5 sent the toolset and got a 200 on every request,
across multi-step turns, an interrupted turn, a page reload, and a chat
that switched to Opus 4.6 (which sent `computer_20251124`) and back. The
same setup on `main` reproduced the 400.

I also ran the same scenarios against dogfood's Bedrock InvokeModel
route. Opus 5.5 and Haiku 5.5 got a 200 on every computer use request,
with up to 22 screenshots in the history, including a chat that switched
to Opus 4.6 on Claude Platform on AWS and back. That went through
dogfood's gateway, so it covers what Bedrock accepts from Coder Agents,
but not a Bedrock provider configured in Coder itself, which I still
haven't run end to end.
This commit is contained in:
Ethan authored and GitHub committed 2026-11-03 16:52:56 +11:00
1 parent e9e8d3416d
commit ff40ec6900
7 files changed
+27 -29

No files matched your search

+2
View File
@@ -50,6 +50,8 @@ import (
var bedrockSupportedBetaFlags = map[string]bool{
// Supported on Claude 3.7 Sonnet.
"computer-use-2025-01-24": true,
// Supported on Claude Opus 4.5 and later. Enables computer_20251124.
"computer-use-2025-11-24": true,
// Supported on Claude 3.7 Sonnet and Claude 4+.
"token-efficient-tools-2025-02-19": true,
// Supported on Claude 4+ models.
@@ -1196,6 +1196,12 @@ func TestFilterBedrockBetaFlags(t *testing.T) {
inputValues: []string{"context-management-2025-06-27,interleaved-thinking-2025-05-14"},
expectValues: []string{"interleaved-thinking-2025-05-14"},
},
{
name: "computer use flag kept",
model: "anthropic.claude-opus-4-6-v1",
inputValues: []string{"computer-use-2025-11-24,claude-code-20250219"},
expectValues: []string{"computer-use-2025-11-24"},
},
{
name: "separate header values are handled correctly",
model: "anthropic.claude-sonnet-4-5-20250929-v1:0",
-12
View File
@@ -148,18 +148,6 @@ func (p *Server) resolveComputerUseModel(
return model, "", nil
}
// anthropicComputerUseToolVersion picks the Anthropic computer use tool version
// for a model of an Anthropic AI provider. Claude Platform on AWS and Amazon
// Bedrock offer computer use only through the earlier tool versions, so a
// model that takes the toolset on the Claude API takes computer_20251124 there.
func anthropicComputerUseToolVersion(modelID string, settings codersdk.AIProviderSettings) fantasyanthropic.ComputerUseToolVersion {
version := fantasyanthropic.ComputerUseToolVersionForModel(modelID)
if version == fantasyanthropic.ComputerUseToolset20260801 && (settings.ClaudePlatformAWS != nil || settings.Bedrock != nil) {
return fantasyanthropic.ComputerUse20251124
}
return version
}
type computerUseProviderToolOptions struct {
provider codersdk.ChatComputerUseProvider
toolVersion fantasyanthropic.ComputerUseToolVersion
+1 -6
View File
@@ -24,7 +24,6 @@ import (
"cdr.dev/slog/v3"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/db2sdk"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/x/chatd/agentselect"
@@ -235,11 +234,7 @@ func (p *Server) buildTurnEnvironment(
)
}
if computerUseProvider == codersdk.ChatComputerUseProviderAnthropic {
settings, err := db2sdk.AIProviderSettings(resolved.route.Provider.Settings)
if err != nil {
return turnEnvironment{}, xerrors.Errorf("decode settings of AI provider %q: %w", resolved.route.Provider.Name, err)
}
computerUseToolVersion = anthropicComputerUseToolVersion(modelConfig.Model, settings)
computerUseToolVersion = anthropic.ComputerUseToolVersionForModel(modelConfig.Model)
}
}
model := resolved.model
@@ -298,7 +298,8 @@ func TestBuildTurnEnvironmentReplacesUnsupportedToolMedia(t *testing.T) {
}
// Computer use chats run on their own model config; the tool flavor follows
// that model's AI provider type.
// that model's AI provider type, and the Anthropic tool version follows the
// model on every platform.
func TestBuildTurnEnvironmentComputerUseRunsOnChatModel(t *testing.T) {
t.Parallel()
@@ -328,25 +329,31 @@ func TestBuildTurnEnvironmentComputerUseRunsOnChatModel(t *testing.T) {
wantToolVersion: fantasyanthropic.ComputerUse20251124,
},
{
// Claude Platform on AWS has no toolset.
name: "AnthropicUnknownModel",
providerType: database.AIProviderTypeAnthropic,
model: "company-default-model",
wantProvider: codersdk.ChatComputerUseProviderAnthropic,
wantToolVersion: fantasyanthropic.ComputerUse20251124,
},
{
// The platform does not change the version.
name: "ClaudePlatformAWS",
providerType: database.AIProviderTypeAnthropic,
settings: codersdk.AIProviderSettings{ClaudePlatformAWS: &codersdk.AIProviderClaudePlatformAWSSettings{
Region: "us-east-2",
WorkspaceID: "wrkspc_test",
}},
model: "claude-opus-5",
model: "claude-opus-5-5",
wantProvider: codersdk.ChatComputerUseProviderAnthropic,
wantToolVersion: fantasyanthropic.ComputerUse20251124,
wantToolVersion: fantasyanthropic.ComputerUseToolset20260801,
},
{
// Amazon Bedrock has no toolset.
name: "AnthropicBedrock",
providerType: database.AIProviderTypeAnthropic,
settings: codersdk.AIProviderSettings{Bedrock: &codersdk.AIProviderBedrockSettings{Region: "us-east-1"}},
model: "claude-opus-5-5",
model: "us.anthropic.claude-opus-5-5",
wantProvider: codersdk.ChatComputerUseProviderAnthropic,
wantToolVersion: fantasyanthropic.ComputerUse20251124,
wantToolVersion: fantasyanthropic.ComputerUseToolset20260801,
},
{
// The model is absent from the SDK's known Responses models, so
+2 -2
View File
@@ -131,8 +131,8 @@ replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713
// the toolset tool definition, ComputerUseToolVersionForModel, and
// mapping of toolset member calls to and from the computer tool.
// Since coder/fantasy#82, unknown model IDs take computer_20251124.
// See: https://github.com/coder/fantasy/commits/7882f906a89a
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20261102054736-7882f906a89a
// See: https://github.com/coder/fantasy/commits/647b1ef66f42
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20261103005632-647b1ef66f42
// coder/coder uses a fork of charmbracelet's fork of the Anthropic Go SDK
// with performance improvements and Bedrock header cleanup.
+2 -2
View File
@@ -323,8 +323,8 @@ github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41 h1:SBN/DA63+ZHwu
github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41/go.mod h1:I9ULxr64UaOSUv7hcb3nX4kowodJCVS7vt7VVJk/kW4=
github.com/coder/clistat v1.2.1 h1:P9/10njXMyj5cWzIU5wkRsSy5LVQH49+tcGMsAgWX0w=
github.com/coder/clistat v1.2.1/go.mod h1:m7SC0uj88eEERgvF8Kn6+w6XF21BeSr+15f7GoLAw0A=
github.com/coder/fantasy v0.0.0-20261102054736-7882f906a89a h1:f/LQisTaV1hfYV9h9LnrAHQ60nZR4SmqeIUWlmtop7Y=
github.com/coder/fantasy v0.0.0-20261102054736-7882f906a89a/go.mod h1:qTrE+p9h8zW+x0f0mU8ih2VdmYHX4ULCaWImvuMHJMc=
github.com/coder/fantasy v0.0.0-20261103005632-647b1ef66f42 h1:yu64TMLxag3H8VT1pH0mZ0u0EStlcy/Byo4Pl+eXcQU=
github.com/coder/fantasy v0.0.0-20261103005632-647b1ef66f42/go.mod h1:qTrE+p9h8zW+x0f0mU8ih2VdmYHX4ULCaWImvuMHJMc=
github.com/coder/flog v1.1.0 h1:kbAes1ai8fIS5OeV+QAnKBQE22ty1jRF/mcAwHpLBa4=
github.com/coder/flog v1.1.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
github.com/coder/go-httpstat v0.0.0-20230801153223-321c88088322 h1:m0lPZjlQ7vdVpRBPKfYIFlmgevoTkBxB10wv6l2gOaU=