Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/active_agent/model_capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module ModelCapabilities
{ pattern: /\Agpt-5/, unsupported: SAMPLING_PARAMS }
].freeze

# Cloud-hosted ids wrap the bare model name, e.g. Bedrock's
# "eu.anthropic.claude-sonnet-5-v1:0" or "anthropic.claude-opus-5-v1:0".
PROVIDER_PREFIX = /\A(?:[a-z]{2,6}\.)?(?:anthropic|openai)[.\/]/
VERSION_SUFFIX = /-v\d+(?::\d+)?\z/

class << self
# Master switch; on by default. Set false to send parameters through
# untouched (the vendor then enforces its own rules).
Expand Down Expand Up @@ -61,12 +66,21 @@ def reset!
def unsupported_params(model)
return [] if model.nil?

name = model.to_s
bare = normalize_model(name)

(custom_rules + BUILTIN_RULES).each do |rule|
return rule[:unsupported] if model.to_s.match?(rule[:pattern])
return rule[:unsupported] if name.match?(rule[:pattern]) || bare.match?(rule[:pattern])
end
[]
end

# Strips the region/provider prefix and "-vN:M" suffix that Bedrock-style
# ids add around the bare model name.
def normalize_model(name)
name.sub(PROVIDER_PREFIX, "").sub(VERSION_SUFFIX, "")
end

def sampling_supported?(model)
(unsupported_params(model) & SAMPLING_PARAMS).empty?
end
Expand Down
7 changes: 7 additions & 0 deletions test/model_capabilities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class ModelCapabilitiesTest < ActiveSupport::TestCase
end
end

test "region- and provider-prefixed ids resolve to the bare model" do
%w[eu.anthropic.claude-sonnet-5-v1:0 us.anthropic.claude-opus-5-v1:0 anthropic.claude-fable-5-v2:0 anthropic/claude-sonnet-5 openai.gpt-5].each do |model|
assert_not ActiveAgent::ModelCapabilities.sampling_supported?(model), "expected #{model} to reject sampling"
end
assert ActiveAgent::ModelCapabilities.sampling_supported?("eu.anthropic.claude-haiku-4-5-v1:0")
end

test "OpenAI reasoning models reject sampling params" do
%w[o1 o1-mini o3-mini o4-mini gpt-5.1 gpt-5].each do |model|
assert_not ActiveAgent::ModelCapabilities.sampling_supported?(model), "expected #{model} to reject sampling"
Expand Down