Skip to content

feat(py/plugins/amazon-bedrock): add model capability registry#5699

Open
cabljac wants to merge 2 commits into
py-bedrock-pluginfrom
py-bedrock-model-info
Open

feat(py/plugins/amazon-bedrock): add model capability registry#5699
cabljac wants to merge 2 commits into
py-bedrock-pluginfrom
py-bedrock-model-info

Conversation

@cabljac

@cabljac cabljac commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Slice 2 of the Amazon Bedrock Python plugin train, into the py-bedrock-plugin base branch.

Ports the Go plugin's models.go (aws-bedrock-go-plugin):

  • 47-entry model capability registry (Claude 3.x/4.x incl. provisioned-throughput variants, Nova, Cohere Command, Mistral/Pixtral, Jamba, Llama 3.x/4, DeepSeek R1, Writer, TwelveLabs) - verified key-for-key and flag-for-flag against the Go source.
  • Inference-profile prefix stripping (global. us-gov. us. eu. jp. apac. au.) for capability lookup only; the full original model ID is always sent to Bedrock untouched.
  • get_model_info(): known models are stable with registry capabilities; unknown chat/text models default to multimodal + tools at the unstable stage so newer or inference-profile-only models remain callable without a plugin release; image models advertise media output only; embedding models advertise nothing.

Tests: 12 new (prefix stripping incl. us-gov. vs us. ordering, registry lookups via profile IDs, unknown-model defaults, image/embedding shapes, registry size + base-ID invariants). ruff clean, 24/24 plugin tests pass.

Next slice: generate sync path (Converse).

Port of the Go plugin's models.go: 47-entry capability registry
(verified key-for-key and flag-for-flag against the source), cross-region
inference-profile prefix stripping for capability lookup only, and
get_model_info() with modern Converse defaults at the unstable stage for
unknown chat/text models so newer or profile-only models stay callable.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a model capability registry for the Amazon Bedrock plugin, mapping model IDs to their respective capabilities (multimodal and tools support) and handling cross-region inference-profile prefixes. The review feedback suggests improving robustness by parsing full Amazon Resource Names (ARNs) to extract the base model ID before stripping prefixes, along with adding corresponding unit tests to verify this behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +111 to +125
def strip_inference_profile_prefix(model_id: str) -> str:
"""Strips a cross-region inference-profile prefix from a model ID.

Used for capability lookup only; requests always carry the original ID.

Args:
model_id: Bedrock model ID, possibly prefixed (e.g. ``us.anthropic...``).

Returns:
The base model ID without the inference-profile prefix.
"""
for prefix in INFERENCE_PROFILE_PREFIXES:
if model_id.startswith(prefix):
return model_id.removeprefix(prefix)
return model_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In AWS Bedrock, models and inference profiles are frequently referenced by their full Amazon Resource Names (ARNs) rather than just their short IDs (e.g., when configuring IAM policies or using application inference profiles).

Currently, if a full ARN is passed as the model_id, strip_inference_profile_prefix will return the ARN untouched, causing the capability lookup in MODEL_CAPABILITIES to fail and fallback to Stage.UNSTABLE with default capabilities.

We can make this more robust by extracting the base model/profile ID from the ARN (the part after the last /) before stripping the prefix.

Suggested change
def strip_inference_profile_prefix(model_id: str) -> str:
"""Strips a cross-region inference-profile prefix from a model ID.
Used for capability lookup only; requests always carry the original ID.
Args:
model_id: Bedrock model ID, possibly prefixed (e.g. ``us.anthropic...``).
Returns:
The base model ID without the inference-profile prefix.
"""
for prefix in INFERENCE_PROFILE_PREFIXES:
if model_id.startswith(prefix):
return model_id.removeprefix(prefix)
return model_id
def strip_inference_profile_prefix(model_id: str) -> str:
"""Strips a cross-region inference-profile prefix from a model ID.
Used for capability lookup only; requests always carry the original ID.
Args:
model_id: Bedrock model ID, possibly prefixed (e.g. ``us.anthropic...``) or an ARN.
Returns:
The base model ID without the inference-profile prefix.
"""
if model_id.startswith('arn:aws:'):
model_id = model_id.split('/')[-1]
for prefix in INFERENCE_PROFILE_PREFIXES:
if model_id.startswith(prefix):
return model_id.removeprefix(prefix)
return model_id

Comment on lines +36 to +37
def test_strip_leaves_bare_model_id_untouched() -> None:
assert strip_inference_profile_prefix('amazon.nova-lite-v1:0') == 'amazon.nova-lite-v1:0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure that the ARN parsing logic works correctly, we should add a unit test that verifies strip_inference_profile_prefix correctly extracts and strips prefixes from full Bedrock ARNs.

Suggested change
def test_strip_leaves_bare_model_id_untouched() -> None:
assert strip_inference_profile_prefix('amazon.nova-lite-v1:0') == 'amazon.nova-lite-v1:0'
def test_strip_leaves_bare_model_id_untouched() -> None:
assert strip_inference_profile_prefix('amazon.nova-lite-v1:0') == 'amazon.nova-lite-v1:0'
def test_strip_handles_arns() -> None:
arn = 'arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0'
assert strip_inference_profile_prefix(arn) == 'anthropic.claude-3-5-sonnet-20241022-v2:0'

…k ARNs

Reduce foundation-model and inference-profile ARNs to their resource ID
before capability lookup, across all AWS partitions (aws, aws-us-gov,
aws-cn). Lookup-only, requests still carry the original identifier.
Addresses PR review feedback.
@cabljac

cabljac commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Both review points addressed in 075d69d. Went slightly broader than the suggestion: matching on arn: rather than arn:aws: so GovCloud (arn:aws-us-gov:) and China (arn:aws-cn:) partition ARNs also resolve, which matters given the registry handles the us-gov. profile prefix. Tests cover inference-profile ARNs, foundation-model ARNs, the GovCloud partition, and opaque application-inference-profile IDs falling back to unstable defaults. Worth noting the Go plugin doesn't reduce ARNs before lookup either, so this may be worth backporting.

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

Labels

python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant