Skip to content

feat: propagate context into Bedrock region/ARN/model-family resolution for per-alias overrides - #4016

Merged
akshaydeo merged 1 commit into
devfrom
06-02-feat_add_bedrock_alias_config_support
Jun 9, 2026
Merged

feat: propagate context into Bedrock region/ARN/model-family resolution for per-alias overrides#4016
akshaydeo merged 1 commit into
devfrom
06-02-feat_add_bedrock_alias_config_support

Conversation

@Pratham-Mishra04

@Pratham-Mishra04 Pratham-Mishra04 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Model-family detection in the Bedrock provider previously relied on substring matching against the raw model string. This meant that aliases pointing to opaque Bedrock deployments (e.g., inference profiles or cross-region ARNs) could not be correctly routed to the right request/response shape. This PR threads *BifrostContext through all family-detection call sites so that an alias's explicit ModelFamily, Region, and BedrockAliasCfg.InferenceProfileARN fields take precedence over substring heuristics.

Changes

  • resolveBedrockRegion and getModelPathAndRegion now accept *BifrostContext and consult the resolved alias's Region field before falling back to the key-level region and then the default.
  • A new resolveBedrockARN helper reads BedrockAliasCfg.InferenceProfileARN from the resolved alias first, falling back to BedrockKeyConfig.ARN. This replaces the inline ARN check that was scattered across getModelPathAndRegion.
  • All model-family boolean checks (IsAnthropicModel, IsMistralModel, IsNovaModel, IsLlamaModel, IsCohereModel, IsTitanModel) are replaced with context-aware *ModelFamily variants (IsAnthropicModelFamily, IsMistralModelFamily, etc.) that call ResolveFamily, which checks the alias config before falling back to substring detection.
  • ModelFamilyLlama is added as a recognized ModelFamily constant and included in IsValid() and ResolveFamily.
  • IsCohereModel and IsTitanModel substring helpers are added to schemas/utils.go and wired into ResolveFamily so those families are covered by alias-level overrides.
  • DetermineEmbeddingModelType and ToBedrockEmbeddingInvokeResponse now accept *BifrostContext so embedding model routing honors alias family tags.
  • convertToolConfigFromFiltered signature updated from context.Context to *BifrostContext to enable family-aware tool-choice gating.
  • New tests cover alias-level Region and InferenceProfileARN override priority in TestResolveBedrockRegion_AliasOverride and TestResolveBedrockARN_AliasOverride.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/bedrock/... ./core/schemas/...

Key scenarios to validate:

  • An alias with ModelFamily: "anthropic" pointing to a cross-region inference profile ARN correctly uses the Anthropic request/response shape and the alias-level region.
  • An alias with BedrockAliasCfg.InferenceProfileARN set overrides the key-level ARN in the constructed URL path.
  • An alias with ModelFamily: "cohere" routes embedding requests to the Cohere envelope format regardless of the model ID string.
  • Existing behavior is preserved when no alias is present (nil context falls through to key-level config and substring matching).

Breaking changes

  • Yes
  • No

ToBedrockEmbeddingInvokeResponse and DetermineEmbeddingModelType now require a *BifrostContext as their first argument. Callers outside this repo that reference these functions directly will need to pass the context. convertToolConfigFromFiltered now takes *BifrostContext instead of context.Context.

Related issues

Security considerations

No new secrets or auth surfaces introduced. ARN values flow through the existing EnvVar/GetValue() resolution path, consistent with all other credential handling.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Summary by CodeRabbit

  • New Features

    • Context-aware model path/region/ARN resolution with alias override support
    • Added Llama model family and new model-family detection helpers
  • Bug Fixes

    • Consistent family detection across completions, embeddings, images, and token counting
    • Family-gated Anthropic assistant-prefill and whitespace trimming
    • Improved inference-profile ARN and region precedence
  • Refactor

    • Unified routing, reasoning, and tool-behavior to use context-aware family predicates
  • Tests

    • Added/updated tests for alias, region, and ARN precedence

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Pratham-Mishra04, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 55cfd308-f889-4fd4-b4bf-ac0dfb4e5e5f

📥 Commits

Reviewing files that changed from the base of the PR and between fd94131 and 92a9e27.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go
📝 Walkthrough

Walkthrough

Refactors Bedrock provider to use ctx-aware model-family predicates and alias-driven region/ARN resolution; threads ctx into path/region helpers and conversion functions used by chat, embedding, responses, image, Mantle routing, and tests.

Changes

Bedrock Provider Model Family Refactor

Layer / File(s) Summary
Model Family Schema Foundation
core/schemas/account.go, core/schemas/utils.go
Adds ModelFamilyLlama, extends ResolveFamily to detect Llama, and exports family-aware helpers (Is*ModelFamily) plus IsCohereModel/IsTitanModel predicates.
Region & ARN Resolution Infrastructure
core/providers/bedrock/utils.go, core/providers/bedrock/bedrock.go
Adds resolveBedrockRegion/resolveBedrockARN and applies ctx-aware path/region resolution across invoke/chat/image/count-tokens paths and Mantle routing; updates request path formatting for ARN-resolved models.
Embedding detection & invoke conversion
core/providers/bedrock/bedrock.go, core/providers/bedrock/embedding.go, core/providers/bedrock/invoke.go, transports/bifrost-http/integrations/bedrock.go
Threads *schemas.BifrostContext into embedding model-type determination and ToBedrockEmbeddingInvokeResponse, updates embedding invoke paths to use provider.getModelPathAndRegion(ctx, ...), and updates the transport embedding converter to forward ctx.
Request/Response Conversion Family Gates
core/providers/bedrock/chat.go, core/providers/bedrock/responses.go, core/providers/bedrock/utils.go
Replaces exact-model checks with ctx-aware family predicates for assistant prefill trimming, reasoning/thinking mapping, Nova cache emission, and Llama tool-choice suppression; updates helper signatures and nil-safety for alias maps.
Mantle Endpoint Region Resolution
core/providers/bedrock/mantle.go
Uses ctx-aware region resolution when constructing Mantle URLs and signing headers across Mantle request paths.
Region Resolution Tests & Alias Precedence
core/providers/bedrock/region_test.go
Updates tests to call new ctx-aware helpers and adds tests that assert alias overrides for region and inference-profile ARN precedence.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • maximhq/bifrost#3771: Touches Bedrock request/response conversion and structured-output behavior overlapping with family/ctx gating changes.
  • maximhq/bifrost#3525: Updates Bedrock structured-output/tool injection tests and Anthropic thinking handling closely related to this PR.
  • maximhq/bifrost#3890: Related tool-name aliasing and convertToolConfig changes that interact with ctx-aware alias resolution.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 A rabbit’s note on family-aware routing:
I sniff the context, aliases in tow,
Families guide where each request should go,
Regions and ARNs find their proper nest,
Paths now follow context — hop to the best.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: propagating context into Bedrock region/ARN/model-family resolution to support per-alias overrides.
Description check ✅ Passed The PR description covers all key template sections: summary explains the problem and solution, changes detail the implementation, type of change is marked, affected areas are checked, test instructions provided, breaking changes are documented, and the checklist is partially completed.
Docstring Coverage ✅ Passed Docstring coverage is 89.29% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-02-feat_add_bedrock_alias_config_support

Comment @coderabbitai help to get the list of available commands and usage tips.

Pratham-Mishra04 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge after fixing the two missed IsNovaModel calls in invoke.go response-dispatch branches.

The migration is thorough across request-path code (chat, responses, utils, mantle, embedding), but ToBedrockInvokeMessagesResponse and ToBedrockInvokeMessagesStreamResponse in invoke.go still use the bare schemas.IsNovaModel(model) substring check. Both functions already accept ctx *schemas.BifrostContext. For a Nova alias whose resolved model ID is an opaque string not containing 'nova' — exactly the scenario this PR is fixing — the response-dispatch branch silently falls through to the Anthropic envelope, producing a malformed API response.

core/providers/bedrock/invoke.go — lines 910 and 1188 still use the non-context-aware IsNovaModel check.

Important Files Changed

Filename Overview
core/providers/bedrock/invoke.go Added ctx to ToBedrockEmbeddingInvokeResponse and migrated IsCohereModelFamily, but two IsNovaModel calls at the response-dispatch branch (ToBedrockInvokeMessagesResponse and ToBedrockInvokeMessagesStreamResponse) were not migrated — these will misformat Nova alias responses when the resolved model ID is opaque.
core/providers/bedrock/utils.go New resolveBedrockRegion and resolveBedrockARN helpers with correct priority ordering; convertToolConfigFromFiltered signature changed to *BifrostContext; all inline IsNovaModel/IsAnthropicModel/IsLlamaModel calls migrated to context-aware variants. Nil-ctx guards added to bedrockAliasToolName and bedrockRestoreToolName.
core/providers/bedrock/embedding.go DetermineEmbeddingModelType now accepts ctx and delegates to IsTitanModelFamily/IsCohereModelFamily; the Titan family gate is broader than the original "amazon.titan-embed-text" prefix check.
core/providers/bedrock/bedrock.go All call sites of resolveBedrockRegion and getModelPathAndRegion updated to pass ctx; logic is consistent and region/ARN priority is correctly threaded through non-streaming and streaming paths.
core/providers/bedrock/chat.go Two IsAnthropicModel calls migrated to IsAnthropicModelFamily for assistant-prefill trimming; change is correct and complete.
core/providers/bedrock/responses.go All IsAnthropicModel, IsNovaModel, and IsLlamaModel calls migrated to context-aware variants across ToBedrockResponsesRequest and ToBifrostResponsesRequest; change is thorough.
core/providers/bedrock/mantle.go All four resolveBedrockRegion calls updated to pass ctx; straightforward and complete.
core/schemas/account.go ModelFamilyLlama added to constants and IsValid(); ResolveFamily extended with Llama, Titan, and Cohere cases; new IsXxxModelFamily helpers added.
core/schemas/utils.go IsCohereModel and IsTitanModel helpers added with bare strings.Contains (no ToLower, inconsistent with IsImagenModel).
core/providers/bedrock/region_test.go Tests updated to pass nil ctx for existing cases; new alias override tests added with good priority-ordering coverage.
transports/bifrost-http/integrations/bedrock.go EmbeddingResponseConverter updated to pass ctx to ToBedrockEmbeddingInvokeResponse; single-line change, correct.

Comments Outside Diff (2)

  1. core/providers/bedrock/invoke.go, line 909-912 (link)

    P1 ToBedrockInvokeMessagesResponse still calls schemas.IsNovaModel(model) (plain substring check) even though ctx *schemas.BifrostContext is available. For a Nova alias whose resolved model ID does not contain the substring "nova" (e.g., an opaque cross-region inference profile ARN set as the alias ModelID), this check returns false and the response is serialized with toBedrockInvokeAnthropicResponse — producing the wrong envelope. Every other Nova branch in this PR was migrated to IsNovaModelFamily(ctx, …).

  2. core/providers/bedrock/invoke.go, line 1187-1189 (link)

    P1 ToBedrockInvokeMessagesStreamResponse has the same unconverted schemas.IsNovaModel call. For a Nova alias with an opaque model ID (one that doesn't contain "nova"), the streaming response would fall through to toAnthropicInvokeStreamBytes and produce the wrong SSE envelope format. ctx is already available in the function signature.

Reviews (11): Last reviewed commit: "feat: add bedrock alias config support" | Re-trigger Greptile

Comment thread core/schemas/utils.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from c0e6a75 to c6f574f Compare June 3, 2026 21:47
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from 287990c to 465ebbd Compare June 3, 2026 21:47
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from c6f574f to f172720 Compare June 4, 2026 20:49
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from 465ebbd to c2dfe18 Compare June 4, 2026 20:49
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from c2dfe18 to ce05d2f Compare June 5, 2026 09:48
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from f172720 to 97b80bd Compare June 5, 2026 09:48
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from ce05d2f to a079ffc Compare June 7, 2026 07:25
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from 97b80bd to 8e6a6bb Compare June 7, 2026 07:25

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/bedrock/utils.go (1)

383-397: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Alias-aware Anthropic reasoning still falls back to raw model sniffing.

This branch is family-aware, but anthropic.SupportsAdaptiveThinking and anthropic.IsOpus47Plus still inspect bifrostReq.Model. For aliases backed by opaque Bedrock deployment IDs or inference-profile ARNs, the request now enters the Anthropic path and then incorrectly downgrades to the legacy budget_tokens shape, so Opus 4.6+/4.7 aliases lose adaptive thinking and output_config.effort.

♻️ Suggested fix
+				resolvedAnthropicModel := bifrostReq.Model
+				if ra := schemas.GetResolvedAlias(ctx); ra != nil && ra.Config != nil && ra.Config.ModelName != nil && *ra.Config.ModelName != "" {
+					resolvedAnthropicModel = *ra.Config.ModelName
+				}
-			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
-				if anthropic.SupportsAdaptiveThinking(bifrostReq.Model) {
+			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
+				if anthropic.SupportsAdaptiveThinking(resolvedAnthropicModel) {
 					// Opus 4.6+: adaptive thinking + output_config.effort
 					effort := anthropic.MapBifrostEffortToAnthropic(*bifrostReq.Params.Reasoning.Effort)
 					thinkingConfig := map[string]any{
 						"type": "adaptive",
 					}
 					if bifrostReq.Params.Reasoning.Display != nil {
 						thinkingConfig["display"] = *bifrostReq.Params.Reasoning.Display
-					} else if anthropic.IsOpus47Plus(bifrostReq.Model) {
+					} else if anthropic.IsOpus47Plus(resolvedAnthropicModel) {
 						// Opus 4.7+ omits reasoning text by default; default to "summarized"
 						thinkingConfig["display"] = "summarized"
 					}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/utils.go` around lines 383 - 397, The branch treats
the model as Anthropic but still passes the raw bifrostReq.Model into
anthropic.SupportsAdaptiveThinking and anthropic.IsOpus47Plus, which causes
alias-backed models to be mis-classified; change those calls to use the
resolved/normalized model identifier that was used for the family check (i.e.,
the same value used in schemas.IsAnthropicModelFamily) or explicitly resolve the
alias first (e.g., via the project's model-resolution helper) and pass that
resolved model into anthropic.SupportsAdaptiveThinking and
anthropic.IsOpus47Plus so adaptive thinking and output_config.effort are
preserved for alias-backed Opus 4.6+/4.7 models.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/utils.go`:
- Around line 1717-1722: convertToolConfigFromFiltered currently accepts a
typed-nil *schemas.BifrostContext and later calls bedrockAliasToolName which
type-asserts and may call (*BifrostContext).SetValue on that receiver, causing a
panic; ensure we never call SetValue on a nil receiver by adding a nil-check in
convertToolConfigFromFiltered (or at its call-site convertToolConfig) and
supplying a non-nil temporary BifrostContext when ctx is nil, or by changing
bedrockAliasToolName to tolerate a nil ctx and avoid calling SetValue; locate
references to convertToolConfigFromFiltered, convertToolConfig, and
bedrockAliasToolName and implement the nil guard so mutations only occur on a
real, allocated *schemas.BifrostContext.

---

Outside diff comments:
In `@core/providers/bedrock/utils.go`:
- Around line 383-397: The branch treats the model as Anthropic but still passes
the raw bifrostReq.Model into anthropic.SupportsAdaptiveThinking and
anthropic.IsOpus47Plus, which causes alias-backed models to be mis-classified;
change those calls to use the resolved/normalized model identifier that was used
for the family check (i.e., the same value used in
schemas.IsAnthropicModelFamily) or explicitly resolve the alias first (e.g., via
the project's model-resolution helper) and pass that resolved model into
anthropic.SupportsAdaptiveThinking and anthropic.IsOpus47Plus so adaptive
thinking and output_config.effort are preserved for alias-backed Opus 4.6+/4.7
models.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c058122-6cc5-4340-996f-cb6736057a5d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e6a6bb and a079ffc.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go

Comment thread core/providers/bedrock/utils.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from 8e6a6bb to f22ce96 Compare June 8, 2026 06:54
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from a079ffc to e2d88f2 Compare June 8, 2026 06:54

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/bedrock/utils.go (1)

383-395: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Alias-aware family routing is bypassed by raw-model adaptive-thinking checks.

Line 384 and Line 392 still use bifrostReq.Model for Anthropic capability gating after switching to alias-aware family checks. For aliases with model_family=anthropic and opaque model_id, this can select the wrong reasoning payload path (budget_tokens vs adaptive output_config.effort).

Suggested fix
+			reasoningModel := bifrostReq.Model
+			if ra := schemas.GetResolvedAlias(ctx); ra != nil && ra.Config != nil && ra.Config.ModelName != nil && *ra.Config.ModelName != "" {
+				reasoningModel = *ra.Config.ModelName
+			}
-			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
-				if anthropic.SupportsAdaptiveThinking(bifrostReq.Model) {
+			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
+				if anthropic.SupportsAdaptiveThinking(reasoningModel) {
 					// Opus 4.6+: adaptive thinking + output_config.effort
 					effort := anthropic.MapBifrostEffortToAnthropic(*bifrostReq.Params.Reasoning.Effort)
 					thinkingConfig := map[string]any{
 						"type": "adaptive",
 					}
 					if bifrostReq.Params.Reasoning.Display != nil {
 						thinkingConfig["display"] = *bifrostReq.Params.Reasoning.Display
-					} else if anthropic.IsOpus47Plus(bifrostReq.Model) {
+					} else if anthropic.IsOpus47Plus(reasoningModel) {
 						// Opus 4.7+ omits reasoning text by default; default to "summarized"
 						thinkingConfig["display"] = "summarized"
 					}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/utils.go` around lines 383 - 395, The capability
checks for adaptive thinking incorrectly call
anthropic.SupportsAdaptiveThinking(...) and anthropic.IsOpus47Plus(...) with raw
bifrostReq.Model, bypassing alias-aware routing; change those calls to use the
same alias-resolved model identifier used for
schemas.IsAnthropicModelFamily(...) (i.e., the resolved model variable used
earlier in the family check) so capability gating is based on the alias-aware
model id instead of the raw model string.
core/providers/bedrock/responses.go (1)

1924-1930: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add table-driven coverage for the new alias-family branches in responses conversion.

This file now changes four separate behaviors based on ctx-resolved family state: cache-point translation, Anthropic assistant-prefill trimming, reasoning config translation, and Llama tool-choice suppression. The supplied PR context only mentions region/ARN precedence tests, so these new branches can regress without any direct coverage. A small table-driven suite here using aliased ModelFamily overrides would close that gap.

As per coding guidelines, "Apply standard Go review practices: clear ownership, small interfaces, explicit error handling and wrapping, context propagation and cancellation, bounded goroutines/channels, race-safe shared state, deterministic tests, and table-driven coverage for behavior changes."

Also applies to: 2021-2029, 2154-2191, 2220-2353, 2452-2519

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 1924 - 1930, Add
table-driven tests that exercise the four new context-resolved model-family
branches in core/providers/bedrock/responses.go: the cache-point translation
branch that sets CacheControl on bifrostReq.Params.Tools when tool.CachePoint !=
nil and !schemas.IsNovaModelFamily(ctx, bifrostReq.Model) (uses
CacheControlTypeEphemeral), the Anthropic assistant-prefill trimming behavior,
the reasoning config translation, and the Llama tool-choice suppression. For
each case, create test rows that set up a base request and then override the
resolved ModelFamily (via the same context/alias mechanism used by
IsNovaModelFamily and related helpers) to exercise both the family and
non-family paths, assert the expected modification to bifrostReq (e.g., last
tool CacheControl set or not), and include clear names, deterministic inputs,
and explicit assertions; keep tests table-driven, isolated, and small. Ensure
you exercise the conversion function(s) in responses.go that perform these
changes and handle context propagation and error returns explicitly in the
tests.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3599-3601: resolveBedrockARN returns the full Bedrock model
identifier and we must not concatenate the original bare model; change the block
that builds encodedModelIdentifier and p to use only the resolved arn (e.g.,
call url.PathEscape(arn) instead of url.PathEscape(fmt.Sprintf("%s/%s", arn,
bareModel))) and then build p from that escaped arn and basePath so
BedrockAliasCfg.InferenceProfileARN overrides work correctly (refer to
resolveBedrockARN, encodedModelIdentifier, bareModel, basePath, and p).

In `@core/providers/bedrock/mantle.go`:
- Around line 16-20: isMantleModel currently routes anything with a raw "gpt-"
substring through Mantle; change it to consult alias-level metadata instead of
substring matching: use the alias resolution contract (Key.Aliases) and check
alias metadata fields like ModelFamily or InferenceProfileARN (or call the
existing ctx-aware family/path helpers) to decide Mantle routing, and ensure
isMantleModel is invoked after alias resolution so alias-level overrides take
precedence over raw model string matching.

In `@core/providers/bedrock/responses.go`:
- Around line 2483-2485: The current logic clears bedrockToolChoice (in the
branch using schemas.IsLlamaModelFamily(ctx, bifrostReq.Model)) which silently
downgrades a forced tool to auto while bedrockReq.ToolConfig.Tools may still
contain multiple tools; update the code around bedrockToolChoice and the
schemas.IsLlamaModelFamily check to either (a) detect when
bedrockReq.ToolConfig.Tools has more than one entry and return an error /
fail-fast for multi-tool Llama-family requests, or (b) when there truly is a
single allowed tool, collapse bedrockReq.ToolConfig.Tools to that single tool
before clearing bedrockToolChoice so structured-output tooling is preserved;
ensure the changes reference bedrockToolChoice, bedrockReq.ToolConfig.Tools and
schemas.IsLlamaModelFamily so the behavior is consistent (also apply equivalent
fix at the other occurrence around lines handling the same branch).

---

Outside diff comments:
In `@core/providers/bedrock/responses.go`:
- Around line 1924-1930: Add table-driven tests that exercise the four new
context-resolved model-family branches in core/providers/bedrock/responses.go:
the cache-point translation branch that sets CacheControl on
bifrostReq.Params.Tools when tool.CachePoint != nil and
!schemas.IsNovaModelFamily(ctx, bifrostReq.Model) (uses
CacheControlTypeEphemeral), the Anthropic assistant-prefill trimming behavior,
the reasoning config translation, and the Llama tool-choice suppression. For
each case, create test rows that set up a base request and then override the
resolved ModelFamily (via the same context/alias mechanism used by
IsNovaModelFamily and related helpers) to exercise both the family and
non-family paths, assert the expected modification to bifrostReq (e.g., last
tool CacheControl set or not), and include clear names, deterministic inputs,
and explicit assertions; keep tests table-driven, isolated, and small. Ensure
you exercise the conversion function(s) in responses.go that perform these
changes and handle context propagation and error returns explicitly in the
tests.

In `@core/providers/bedrock/utils.go`:
- Around line 383-395: The capability checks for adaptive thinking incorrectly
call anthropic.SupportsAdaptiveThinking(...) and anthropic.IsOpus47Plus(...)
with raw bifrostReq.Model, bypassing alias-aware routing; change those calls to
use the same alias-resolved model identifier used for
schemas.IsAnthropicModelFamily(...) (i.e., the resolved model variable used
earlier in the family check) so capability gating is based on the alias-aware
model id instead of the raw model string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5f7b3b1f-b8c1-486c-a321-d56f183dec05

📥 Commits

Reviewing files that changed from the base of the PR and between a079ffc and e2d88f2.

📒 Files selected for processing (10)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go

@coderabbitai coderabbitai 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/bedrock/utils.go (1)

383-395: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Alias-aware family routing is bypassed by raw-model adaptive-thinking checks.

Line 384 and Line 392 still use bifrostReq.Model for Anthropic capability gating after switching to alias-aware family checks. For aliases with model_family=anthropic and opaque model_id, this can select the wrong reasoning payload path (budget_tokens vs adaptive output_config.effort).

Suggested fix
+			reasoningModel := bifrostReq.Model
+			if ra := schemas.GetResolvedAlias(ctx); ra != nil && ra.Config != nil && ra.Config.ModelName != nil && *ra.Config.ModelName != "" {
+				reasoningModel = *ra.Config.ModelName
+			}
-			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
-				if anthropic.SupportsAdaptiveThinking(bifrostReq.Model) {
+			} else if schemas.IsAnthropicModelFamily(ctx, bifrostReq.Model) {
+				if anthropic.SupportsAdaptiveThinking(reasoningModel) {
 					// Opus 4.6+: adaptive thinking + output_config.effort
 					effort := anthropic.MapBifrostEffortToAnthropic(*bifrostReq.Params.Reasoning.Effort)
 					thinkingConfig := map[string]any{
 						"type": "adaptive",
 					}
 					if bifrostReq.Params.Reasoning.Display != nil {
 						thinkingConfig["display"] = *bifrostReq.Params.Reasoning.Display
-					} else if anthropic.IsOpus47Plus(bifrostReq.Model) {
+					} else if anthropic.IsOpus47Plus(reasoningModel) {
 						// Opus 4.7+ omits reasoning text by default; default to "summarized"
 						thinkingConfig["display"] = "summarized"
 					}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/utils.go` around lines 383 - 395, The capability
checks for adaptive thinking incorrectly call
anthropic.SupportsAdaptiveThinking(...) and anthropic.IsOpus47Plus(...) with raw
bifrostReq.Model, bypassing alias-aware routing; change those calls to use the
same alias-resolved model identifier used for
schemas.IsAnthropicModelFamily(...) (i.e., the resolved model variable used
earlier in the family check) so capability gating is based on the alias-aware
model id instead of the raw model string.
core/providers/bedrock/responses.go (1)

1924-1930: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add table-driven coverage for the new alias-family branches in responses conversion.

This file now changes four separate behaviors based on ctx-resolved family state: cache-point translation, Anthropic assistant-prefill trimming, reasoning config translation, and Llama tool-choice suppression. The supplied PR context only mentions region/ARN precedence tests, so these new branches can regress without any direct coverage. A small table-driven suite here using aliased ModelFamily overrides would close that gap.

As per coding guidelines, "Apply standard Go review practices: clear ownership, small interfaces, explicit error handling and wrapping, context propagation and cancellation, bounded goroutines/channels, race-safe shared state, deterministic tests, and table-driven coverage for behavior changes."

Also applies to: 2021-2029, 2154-2191, 2220-2353, 2452-2519

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 1924 - 1930, Add
table-driven tests that exercise the four new context-resolved model-family
branches in core/providers/bedrock/responses.go: the cache-point translation
branch that sets CacheControl on bifrostReq.Params.Tools when tool.CachePoint !=
nil and !schemas.IsNovaModelFamily(ctx, bifrostReq.Model) (uses
CacheControlTypeEphemeral), the Anthropic assistant-prefill trimming behavior,
the reasoning config translation, and the Llama tool-choice suppression. For
each case, create test rows that set up a base request and then override the
resolved ModelFamily (via the same context/alias mechanism used by
IsNovaModelFamily and related helpers) to exercise both the family and
non-family paths, assert the expected modification to bifrostReq (e.g., last
tool CacheControl set or not), and include clear names, deterministic inputs,
and explicit assertions; keep tests table-driven, isolated, and small. Ensure
you exercise the conversion function(s) in responses.go that perform these
changes and handle context propagation and error returns explicitly in the
tests.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3599-3601: resolveBedrockARN returns the full Bedrock model
identifier and we must not concatenate the original bare model; change the block
that builds encodedModelIdentifier and p to use only the resolved arn (e.g.,
call url.PathEscape(arn) instead of url.PathEscape(fmt.Sprintf("%s/%s", arn,
bareModel))) and then build p from that escaped arn and basePath so
BedrockAliasCfg.InferenceProfileARN overrides work correctly (refer to
resolveBedrockARN, encodedModelIdentifier, bareModel, basePath, and p).

In `@core/providers/bedrock/mantle.go`:
- Around line 16-20: isMantleModel currently routes anything with a raw "gpt-"
substring through Mantle; change it to consult alias-level metadata instead of
substring matching: use the alias resolution contract (Key.Aliases) and check
alias metadata fields like ModelFamily or InferenceProfileARN (or call the
existing ctx-aware family/path helpers) to decide Mantle routing, and ensure
isMantleModel is invoked after alias resolution so alias-level overrides take
precedence over raw model string matching.

In `@core/providers/bedrock/responses.go`:
- Around line 2483-2485: The current logic clears bedrockToolChoice (in the
branch using schemas.IsLlamaModelFamily(ctx, bifrostReq.Model)) which silently
downgrades a forced tool to auto while bedrockReq.ToolConfig.Tools may still
contain multiple tools; update the code around bedrockToolChoice and the
schemas.IsLlamaModelFamily check to either (a) detect when
bedrockReq.ToolConfig.Tools has more than one entry and return an error /
fail-fast for multi-tool Llama-family requests, or (b) when there truly is a
single allowed tool, collapse bedrockReq.ToolConfig.Tools to that single tool
before clearing bedrockToolChoice so structured-output tooling is preserved;
ensure the changes reference bedrockToolChoice, bedrockReq.ToolConfig.Tools and
schemas.IsLlamaModelFamily so the behavior is consistent (also apply equivalent
fix at the other occurrence around lines handling the same branch).

---

Outside diff comments:
In `@core/providers/bedrock/responses.go`:
- Around line 1924-1930: Add table-driven tests that exercise the four new
context-resolved model-family branches in core/providers/bedrock/responses.go:
the cache-point translation branch that sets CacheControl on
bifrostReq.Params.Tools when tool.CachePoint != nil and
!schemas.IsNovaModelFamily(ctx, bifrostReq.Model) (uses
CacheControlTypeEphemeral), the Anthropic assistant-prefill trimming behavior,
the reasoning config translation, and the Llama tool-choice suppression. For
each case, create test rows that set up a base request and then override the
resolved ModelFamily (via the same context/alias mechanism used by
IsNovaModelFamily and related helpers) to exercise both the family and
non-family paths, assert the expected modification to bifrostReq (e.g., last
tool CacheControl set or not), and include clear names, deterministic inputs,
and explicit assertions; keep tests table-driven, isolated, and small. Ensure
you exercise the conversion function(s) in responses.go that perform these
changes and handle context propagation and error returns explicitly in the
tests.

In `@core/providers/bedrock/utils.go`:
- Around line 383-395: The capability checks for adaptive thinking incorrectly
call anthropic.SupportsAdaptiveThinking(...) and anthropic.IsOpus47Plus(...)
with raw bifrostReq.Model, bypassing alias-aware routing; change those calls to
use the same alias-resolved model identifier used for
schemas.IsAnthropicModelFamily(...) (i.e., the resolved model variable used
earlier in the family check) so capability gating is based on the alias-aware
model id instead of the raw model string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5f7b3b1f-b8c1-486c-a321-d56f183dec05

📥 Commits

Reviewing files that changed from the base of the PR and between a079ffc and e2d88f2.

📒 Files selected for processing (10)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
🛑 Comments failed to post (3)
core/providers/bedrock/bedrock.go (1)

3599-3601: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the resolved ARN as the full model identifier.

resolveBedrockARN already returns the Bedrock model ID to invoke. Appending "/"+bareModel manufactures a different identifier, so alias or key InferenceProfileARN requests will hit the wrong model path and fail on the new override flow.

Based on the PR objective, BedrockAliasCfg.InferenceProfileARN is supposed to override model resolution, not be concatenated with the original model string.

Suggested fix
  if arn := resolveBedrockARN(ctx, key); arn != "" {
-		encodedModelIdentifier := url.PathEscape(fmt.Sprintf("%s/%s", arn, bareModel))
+		encodedModelIdentifier := url.PathEscape(arn)
 		p = fmt.Sprintf("%s/%s", encodedModelIdentifier, basePath)
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/bedrock.go` around lines 3599 - 3601,
resolveBedrockARN returns the full Bedrock model identifier and we must not
concatenate the original bare model; change the block that builds
encodedModelIdentifier and p to use only the resolved arn (e.g., call
url.PathEscape(arn) instead of url.PathEscape(fmt.Sprintf("%s/%s", arn,
bareModel))) and then build p from that escaped arn and basePath so
BedrockAliasCfg.InferenceProfileARN overrides work correctly (refer to
resolveBedrockARN, encodedModelIdentifier, bareModel, basePath, and p).
core/providers/bedrock/mantle.go (1)

16-20: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t route Bedrock aliases through Mantle from a raw gpt- substring.

isMantleModel runs before the ctx-aware family/path helpers. With this broadened check, any alias name containing gpt- gets forced through Mantle even if the resolved alias points to Anthropic, Mistral, Nova, etc., so the new alias ModelFamily / InferenceProfileARN overrides are bypassed before they can take effect.

Based on the PR objective and the Key.Aliases contract, alias-level metadata should drive Bedrock routing instead of raw substring matching on the incoming model string.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/mantle.go` around lines 16 - 20, isMantleModel
currently routes anything with a raw "gpt-" substring through Mantle; change it
to consult alias-level metadata instead of substring matching: use the alias
resolution contract (Key.Aliases) and check alias metadata fields like
ModelFamily or InferenceProfileARN (or call the existing ctx-aware family/path
helpers) to decide Mantle routing, and ensure isMantleModel is invoked after
alias resolution so alias-level overrides take precedence over raw model string
matching.
core/providers/bedrock/responses.go (1)

2483-2485: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't silently downgrade forced tool selection to auto on Llama when multiple tools are bound.

These branches drop toolChoice.tool for every Llama-family request, but bedrockReq.ToolConfig.Tools can still contain multiple tools here (user tools plus the synthetic structured-output tool). In that case auto is not equivalent: Bedrock can pick the wrong tool or skip the structured-output tool entirely. Please fail fast for multi-tool Llama requests or collapse the tool list to the single allowed tool before removing the pin.

Possible guard
-		if bedrockToolChoice != nil && bedrockToolChoice.Tool != nil && schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) {
+		if bedrockToolChoice != nil && bedrockToolChoice.Tool != nil && schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) {
+			if bedrockReq.ToolConfig != nil && len(bedrockReq.ToolConfig.Tools) > 1 {
+				return nil, fmt.Errorf("bedrock llama models do not support forcing a specific tool when multiple tools are configured")
+			}
 			bedrockToolChoice = nil
 		}
@@
-		if !schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) && !thinkingEnabled {
+		if schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) && len(bedrockReq.ToolConfig.Tools) > 1 {
+			return nil, fmt.Errorf("structured output on bedrock llama requires the synthetic tool to be the only configured tool")
+		}
+		if !schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) && !thinkingEnabled {
 			bedrockReq.ToolConfig.ToolChoice = &BedrockToolChoice{
 				Tool: &BedrockToolChoiceTool{
 					Name: responsesStructuredOutputTool.ToolSpec.Name,

Also applies to: 2513-2518

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2483 - 2485, The current
logic clears bedrockToolChoice (in the branch using
schemas.IsLlamaModelFamily(ctx, bifrostReq.Model)) which silently downgrades a
forced tool to auto while bedrockReq.ToolConfig.Tools may still contain multiple
tools; update the code around bedrockToolChoice and the
schemas.IsLlamaModelFamily check to either (a) detect when
bedrockReq.ToolConfig.Tools has more than one entry and return an error /
fail-fast for multi-tool Llama-family requests, or (b) when there truly is a
single allowed tool, collapse bedrockReq.ToolConfig.Tools to that single tool
before clearing bedrockToolChoice so structured-output tooling is preserved;
ensure the changes reference bedrockToolChoice, bedrockReq.ToolConfig.Tools and
schemas.IsLlamaModelFamily so the behavior is consistent (also apply equivalent
fix at the other occurrence around lines handling the same branch).

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from f22ce96 to fcd9882 Compare June 8, 2026 07:18
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from e2d88f2 to 6a8fd31 Compare June 8, 2026 07:18

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3582-3596: getModelPathAndRegion currently ignores
alias-configured region overrides when parseBedrockRegionAndModel returns a
region, causing inconsistent endpoints versus resolveBedrockRegion; change
getModelPathAndRegion to use the same precedence as resolveBedrockRegion by
checking schemas.GetResolvedAlias(ctx).Config.Region (and falling back to
key.BedrockKeyConfig.Region and then DefaultBedrockRegion) even when
parseBedrockRegionAndModel found a region prefix, and ensure the returned path
still strips any model-region prefix if necessary (use
parseBedrockRegionAndModel, resolveBedrockRegion, schemas.GetResolvedAlias,
key.BedrockKeyConfig, and DefaultBedrockRegion to implement the precedence),
then add a regression test covering an alias-configured region with an input
like "us-*/model".

In `@core/providers/bedrock/responses.go`:
- Around line 2483-2484: The transports config schema lacks "llama" in the
base_key.aliases.*.model_family enum, but core/providers/bedrock/responses.go
uses schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) to gate Bedrock
tool_choice logic (including the bedrockToolChoice = nil and thinkingEnabled
branches); update transports/config.schema.json to add "llama" to the
model_family enum under base_key.aliases so alias configs validating against
that schema can specify "llama" and allow the IsLlamaModelFamily-based
routing/tool-choice behavior to run correctly.

In `@core/schemas/account.go`:
- Around line 152-161: You added a new Go enum value ModelFamilyLlama in
core/schemas/account.go but did not update the JSON schema, causing config
validation to reject model_family:"llama"; update transports/config.schema.json
to include "llama" in the base_key.aliases.*.model_family enum (the schema is
the source of truth), ensure spelling matches ModelFamilyLlama, run schema
lint/validation and tests to confirm configs with model_family:"llama" pass.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9ca5c127-257f-4192-a5a4-bbe6a1549dfa

📥 Commits

Reviewing files that changed from the base of the PR and between e2d88f2 and 6a8fd31.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go

@coderabbitai coderabbitai 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3582-3596: getModelPathAndRegion currently ignores
alias-configured region overrides when parseBedrockRegionAndModel returns a
region, causing inconsistent endpoints versus resolveBedrockRegion; change
getModelPathAndRegion to use the same precedence as resolveBedrockRegion by
checking schemas.GetResolvedAlias(ctx).Config.Region (and falling back to
key.BedrockKeyConfig.Region and then DefaultBedrockRegion) even when
parseBedrockRegionAndModel found a region prefix, and ensure the returned path
still strips any model-region prefix if necessary (use
parseBedrockRegionAndModel, resolveBedrockRegion, schemas.GetResolvedAlias,
key.BedrockKeyConfig, and DefaultBedrockRegion to implement the precedence),
then add a regression test covering an alias-configured region with an input
like "us-*/model".

In `@core/providers/bedrock/responses.go`:
- Around line 2483-2484: The transports config schema lacks "llama" in the
base_key.aliases.*.model_family enum, but core/providers/bedrock/responses.go
uses schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) to gate Bedrock
tool_choice logic (including the bedrockToolChoice = nil and thinkingEnabled
branches); update transports/config.schema.json to add "llama" to the
model_family enum under base_key.aliases so alias configs validating against
that schema can specify "llama" and allow the IsLlamaModelFamily-based
routing/tool-choice behavior to run correctly.

In `@core/schemas/account.go`:
- Around line 152-161: You added a new Go enum value ModelFamilyLlama in
core/schemas/account.go but did not update the JSON schema, causing config
validation to reject model_family:"llama"; update transports/config.schema.json
to include "llama" in the base_key.aliases.*.model_family enum (the schema is
the source of truth), ensure spelling matches ModelFamilyLlama, run schema
lint/validation and tests to confirm configs with model_family:"llama" pass.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9ca5c127-257f-4192-a5a4-bbe6a1549dfa

📥 Commits

Reviewing files that changed from the base of the PR and between e2d88f2 and 6a8fd31.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go
🛑 Comments failed to post (3)
core/providers/bedrock/bedrock.go (1)

3582-3596: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Alias region overrides are still skipped when the model string already has a region prefix.

getModelPathAndRegion only reads schemas.GetResolvedAlias(ctx).Config.Region when parseBedrockRegionAndModel(model) returns no region. That makes streaming paths keep the model’s embedded region while unary paths now use resolveBedrockRegion(ctx, ...), so the same alias can resolve to different Bedrock endpoints depending on request type.

Please make this helper use the same precedence as resolveBedrockRegion and add a regression for an alias-configured region with a us-*/model input.

Suggested fix
 func (provider *BedrockProvider) getModelPathAndRegion(ctx *schemas.BifrostContext, basePath, model string, key schemas.Key) (path, region string) {
 	r, bareModel := parseBedrockRegionAndModel(model)
-	if r == "" {
-		if ra := schemas.GetResolvedAlias(ctx); ra != nil && ra.Config != nil && ra.Config.Region != nil {
-			if v := ra.Config.Region.GetValue(); v != "" {
-				r = v
-			}
-		}
-		if r == "" {
-			if key.BedrockKeyConfig != nil && key.BedrockKeyConfig.Region != nil && key.BedrockKeyConfig.Region.GetValue() != "" {
-				r = key.BedrockKeyConfig.Region.GetValue()
-			} else {
-				r = DefaultBedrockRegion
-			}
-		}
+	if ra := schemas.GetResolvedAlias(ctx); ra != nil && ra.Config != nil && ra.Config.Region != nil {
+		if v := ra.Config.Region.GetValue(); v != "" {
+			r = v
+		}
+	}
+	if r == "" {
+		if key.BedrockKeyConfig != nil && key.BedrockKeyConfig.Region != nil && key.BedrockKeyConfig.Region.GetValue() != "" {
+			r = key.BedrockKeyConfig.Region.GetValue()
+		} else {
+			r = DefaultBedrockRegion
+		}
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/bedrock.go` around lines 3582 - 3596,
getModelPathAndRegion currently ignores alias-configured region overrides when
parseBedrockRegionAndModel returns a region, causing inconsistent endpoints
versus resolveBedrockRegion; change getModelPathAndRegion to use the same
precedence as resolveBedrockRegion by checking
schemas.GetResolvedAlias(ctx).Config.Region (and falling back to
key.BedrockKeyConfig.Region and then DefaultBedrockRegion) even when
parseBedrockRegionAndModel found a region prefix, and ensure the returned path
still strips any model-region prefix if necessary (use
parseBedrockRegionAndModel, resolveBedrockRegion, schemas.GetResolvedAlias,
key.BedrockKeyConfig, and DefaultBedrockRegion to implement the precedence),
then add a regression test covering an alias-configured region with an input
like "us-*/model".
core/providers/bedrock/responses.go (1)

2483-2484: ⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify that the config schema source of truth accepts the new alias model family.
rg -n -C2 '"model_family"|llama' transports/config.schema.json

Repository: maximhq/bifrost

Length of output: 2016


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Locate the Bedrock llama-family gating logic in core/providers/bedrock/responses.go
rg -n "IsLlamaModelFamily|bedrockToolChoice|ToolChoice|ToolChoice.*nil" core/providers/bedrock/responses.go

# Show the surrounding blocks where the llama gate is applied (limit output)
sed -n '2400,2600p' core/providers/bedrock/responses.go | nl -ba | sed -n '1,250p'

# 2) Locate model_family enum in transports/config.schema.json
rg -n "\"model_family\"\\s*:\\s*\\{" transports/config.schema.json
rg -n "model_family.*enum|\"model_family\".*enum" transports/config.schema.json

# Print the section around the enum
# (Use a smaller window around the first match)
first_match_line="$(rg -n "\"model_family\"\\s*:\\s*\\{" transports/config.schema.json | head -n1 | cut -d: -f1)"
start=$(( first_match_line - 40 ))
end=$(( first_match_line + 120 ))
sed -n "${start},${end}p" transports/config.schema.json | nl -ba | head -n 220

Repository: maximhq/bifrost

Length of output: 3105


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Show the bedrock llama-family gating block (around the lines that appeared in prior output)
sed -n '2455,2535p' core/providers/bedrock/responses.go | cat -n

# 2) Locate and print the actual model_family enum section in transports/config.schema.json
rg -n "\"model_family\"\\s*:\\s*\\{" transports/config.schema.json
# Print a small window around the first match
line="$(rg -n "\"model_family\"\\s*:\\s*\\{" transports/config.schema.json | head -n1 | cut -d: -f1)"
start=$((line-60))
end=$((line+140))
sed -n "${start},${end}p" transports/config.schema.json | cat -n

# 3) Inspect IsLlamaModelFamily implementation to understand whether it keys off config "model_family" or the model string itself
rg -n "func\\s+IsLlamaModelFamily\\b" -S core
rg -n "IsLlamaModelFamily\\(" -S core/schemas core | head -n 50
# Print implementation if found
file="$(rg -n "func\\s+IsLlamaModelFamily\\b" -S core | head -n1 | cut -d: -f1)"
impl_start="$(rg -n "func\\s+IsLlamaModelFamily\\b" -S core | head -n1 | cut -d: -f1)"
sed -n "$((impl_start-40)),$((impl_start+120))p" "$file" | cat -n

Repository: maximhq/bifrost

Length of output: 14316


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '360,460p' core/schemas/account.go | cat -n

Repository: maximhq/bifrost

Length of output: 4368


Add "llama" to base_key.aliases.*.model_family enum in transports/config.schema.json
core/providers/bedrock/responses.go gates Bedrock tool_choice handling on schemas.IsLlamaModelFamily(ctx, bifrostReq.Model) (including around the bedrockToolChoice = nil and thinkingEnabled blocks), but the config schema currently restricts model_family to ["anthropic","openai","mistral","cohere","gemini","nova","titan"], so alias configs can’t specify "llama" and will fail validation before routing/tool-choice behavior can rely on that family classification.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2483 - 2484, The transports
config schema lacks "llama" in the base_key.aliases.*.model_family enum, but
core/providers/bedrock/responses.go uses schemas.IsLlamaModelFamily(ctx,
bifrostReq.Model) to gate Bedrock tool_choice logic (including the
bedrockToolChoice = nil and thinkingEnabled branches); update
transports/config.schema.json to add "llama" to the model_family enum under
base_key.aliases so alias configs validating against that schema can specify
"llama" and allow the IsLlamaModelFamily-based routing/tool-choice behavior to
run correctly.

Source: Coding guidelines

core/schemas/account.go (1)

152-161: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

ModelFamilyLlama must be mirrored in config schema enum to avoid config rejection.

Adding "llama" here without updating transports/config.schema.json base_key.aliases.*.model_family enum creates a cross-layer contract break: configs using alias model_family: "llama" will fail schema validation before reaching this logic.

Please add "llama" to the schema enum in transports/config.schema.json in the same stack/PR set.

As per coding guidelines, transports/config.schema.json is the source of truth and must include new model-family values accepted by Go types.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/schemas/account.go` around lines 152 - 161, You added a new Go enum
value ModelFamilyLlama in core/schemas/account.go but did not update the JSON
schema, causing config validation to reject model_family:"llama"; update
transports/config.schema.json to include "llama" in the
base_key.aliases.*.model_family enum (the schema is the source of truth), ensure
spelling matches ModelFamilyLlama, run schema lint/validation and tests to
confirm configs with model_family:"llama" pass.

Source: Coding guidelines

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from 6a8fd31 to fd94131 Compare June 8, 2026 11:55

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/bedrock/responses.go (2)

2154-2188: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add table-driven coverage for these family-gated branches.

This PR changes Anthropic prefill trimming, Anthropic/Nova reasoning encoding, and Llama tool-choice suppression in ToBedrockResponsesRequest, but the provided PR context only adds region/ARN tests. A focused table-driven suite for alias-tagged Anthropic, Nova, and Llama models would lock down the new behavior.

As per coding guidelines, Go behavior changes should have “table-driven coverage,” and Bedrock alias routing must honor model_family as the canonical signal.

Also applies to: 2220-2348, 2483-2514

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2154 - 2188, Add
table-driven unit tests exercising ToBedrockResponsesRequest (and its helpers
like ConvertBifrostMessagesToBedrockMessages) to cover the family-gated
branches: Anthropic prefill trimming (alias-tagged Anthropic models), Nova
reasoning encoding, and Llama tool-choice suppression; for each case include
variants where model is provided via alias/Routing vs model_family so Bedrock
routing honors model_family as canonical, assert resulting
bedrockReq.Messages/System/flags are exactly as expected, and include negative
cases (no system messages, instructions present) to lock down the logic around
bedrockReq.System population and the trailing-text trimming behavior.

Source: Coding guidelines


2452-2458: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep cache-point support family-aware end-to-end.

Line 2452 starts honoring alias-resolved families, but Line 2525 still strips cache points via the raw-model BedrockModelSupportsCachePoints(bifrostReq.Model) gate. For aliases whose wire model ID does not advertise caching support, the cache points added here get removed again, so prompt caching still fails on the new alias-family path.

As per coding guidelines, model_family is the canonical routing signal and should be used “without substring-sniffing the wire model ID”.

Also applies to: 2525-2527

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2452 - 2458, The
cache-point addition currently uses alias-resolved family via
schemas.IsNovaModelFamily(ctx, bifrostReq.Model) but later removal still gates
on the raw wire model via BedrockModelSupportsCachePoints(bifrostReq.Model),
which strips cache points for aliased families; change the gating logic so
cache-point support is determined from the canonical model_family signal (e.g.
bifrostReq.ModelFamily) rather than the raw wire model ID — update the checks
that call BedrockModelSupportsCachePoints(...) and any
schemas.IsNovaModelFamily(...) usage in this flow to accept/inspect
bifrostReq.ModelFamily (or equivalent canonical field) so the
BedrockTool/BedrockCachePoint additions (BedrockCachePointTypeDefault) are
preserved for alias-resolved families end-to-end.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3599-3601: The code is appending bareModel to the resolved Bedrock
inference-profile ARN (resolveBedrockARN), producing an invalid synthetic ARN;
instead use the resolved ARN as the full modelId. Replace the current logic that
builds encodedModelIdentifier from fmt.Sprintf("%s/%s", arn, bareModel) and then
sets p to include bareModel, and instead URL-escape only the resolved arn (e.g.,
url.PathEscape(arn)) and compose p from that escaped arn and basePath (so p uses
the inference-profile ARN as the model identifier), leaving bareModel out of the
ARN path construction.

In `@core/providers/bedrock/region_test.go`:
- Around line 100-137: Add a symmetric test case to
TestResolveBedrockRegion_AliasOverride to cover an empty alias Region falling
back to the key Region: modify the test to create a ctx where
schemas.ResolvedAlias.Config.Region is an empty schemas.EnvVar (or nil/empty
equivalent), then call resolveBedrockRegion(ctx, key, "anthropic.claude-v2") and
assert the returned region equals keyRegion; place this case alongside the
existing "No alias in ctx" and alias override checks so the behavior mirrors the
ARN empty-alias test.

In `@core/schemas/account.go`:
- Around line 339-379: ResolveFamily currently prefers alias ModelFamily → alias
ModelName → alias ModelID → alias Key and only uses fallbackModel when there is
no resolved alias/config; confirm and, if intended, document this precedence and
fallback behavior in the ResolveFamily function (and update tests) so Bedrock's
family-gated logic that calls Is*ModelFamily(ctx, <request model>) behaves
predictably when both ModelName and ModelID are present. Specifically, verify
GetResolvedAlias and ra.Config.ModelFamily handling, ensure the early return for
ra.Config.ModelFamily and the candidate ordering (ra.Config.ModelName,
ra.Config.ModelID, ra.Key) are correct, and add/adjust unit tests for
ResolveFamily to cover cases with both model_name and model_id set plus the
no-alias fallbackModel path.

---

Outside diff comments:
In `@core/providers/bedrock/responses.go`:
- Around line 2154-2188: Add table-driven unit tests exercising
ToBedrockResponsesRequest (and its helpers like
ConvertBifrostMessagesToBedrockMessages) to cover the family-gated branches:
Anthropic prefill trimming (alias-tagged Anthropic models), Nova reasoning
encoding, and Llama tool-choice suppression; for each case include variants
where model is provided via alias/Routing vs model_family so Bedrock routing
honors model_family as canonical, assert resulting
bedrockReq.Messages/System/flags are exactly as expected, and include negative
cases (no system messages, instructions present) to lock down the logic around
bedrockReq.System population and the trailing-text trimming behavior.
- Around line 2452-2458: The cache-point addition currently uses alias-resolved
family via schemas.IsNovaModelFamily(ctx, bifrostReq.Model) but later removal
still gates on the raw wire model via
BedrockModelSupportsCachePoints(bifrostReq.Model), which strips cache points for
aliased families; change the gating logic so cache-point support is determined
from the canonical model_family signal (e.g. bifrostReq.ModelFamily) rather than
the raw wire model ID — update the checks that call
BedrockModelSupportsCachePoints(...) and any schemas.IsNovaModelFamily(...)
usage in this flow to accept/inspect bifrostReq.ModelFamily (or equivalent
canonical field) so the BedrockTool/BedrockCachePoint additions
(BedrockCachePointTypeDefault) are preserved for alias-resolved families
end-to-end.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6b5a0e63-5dcd-4b6f-9ee5-f0b665b69820

📥 Commits

Reviewing files that changed from the base of the PR and between 6a8fd31 and fd94131.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go

@coderabbitai coderabbitai 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/bedrock/responses.go (2)

2154-2188: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add table-driven coverage for these family-gated branches.

This PR changes Anthropic prefill trimming, Anthropic/Nova reasoning encoding, and Llama tool-choice suppression in ToBedrockResponsesRequest, but the provided PR context only adds region/ARN tests. A focused table-driven suite for alias-tagged Anthropic, Nova, and Llama models would lock down the new behavior.

As per coding guidelines, Go behavior changes should have “table-driven coverage,” and Bedrock alias routing must honor model_family as the canonical signal.

Also applies to: 2220-2348, 2483-2514

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2154 - 2188, Add
table-driven unit tests exercising ToBedrockResponsesRequest (and its helpers
like ConvertBifrostMessagesToBedrockMessages) to cover the family-gated
branches: Anthropic prefill trimming (alias-tagged Anthropic models), Nova
reasoning encoding, and Llama tool-choice suppression; for each case include
variants where model is provided via alias/Routing vs model_family so Bedrock
routing honors model_family as canonical, assert resulting
bedrockReq.Messages/System/flags are exactly as expected, and include negative
cases (no system messages, instructions present) to lock down the logic around
bedrockReq.System population and the trailing-text trimming behavior.

Source: Coding guidelines


2452-2458: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep cache-point support family-aware end-to-end.

Line 2452 starts honoring alias-resolved families, but Line 2525 still strips cache points via the raw-model BedrockModelSupportsCachePoints(bifrostReq.Model) gate. For aliases whose wire model ID does not advertise caching support, the cache points added here get removed again, so prompt caching still fails on the new alias-family path.

As per coding guidelines, model_family is the canonical routing signal and should be used “without substring-sniffing the wire model ID”.

Also applies to: 2525-2527

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/responses.go` around lines 2452 - 2458, The
cache-point addition currently uses alias-resolved family via
schemas.IsNovaModelFamily(ctx, bifrostReq.Model) but later removal still gates
on the raw wire model via BedrockModelSupportsCachePoints(bifrostReq.Model),
which strips cache points for aliased families; change the gating logic so
cache-point support is determined from the canonical model_family signal (e.g.
bifrostReq.ModelFamily) rather than the raw wire model ID — update the checks
that call BedrockModelSupportsCachePoints(...) and any
schemas.IsNovaModelFamily(...) usage in this flow to accept/inspect
bifrostReq.ModelFamily (or equivalent canonical field) so the
BedrockTool/BedrockCachePoint additions (BedrockCachePointTypeDefault) are
preserved for alias-resolved families end-to-end.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 3599-3601: The code is appending bareModel to the resolved Bedrock
inference-profile ARN (resolveBedrockARN), producing an invalid synthetic ARN;
instead use the resolved ARN as the full modelId. Replace the current logic that
builds encodedModelIdentifier from fmt.Sprintf("%s/%s", arn, bareModel) and then
sets p to include bareModel, and instead URL-escape only the resolved arn (e.g.,
url.PathEscape(arn)) and compose p from that escaped arn and basePath (so p uses
the inference-profile ARN as the model identifier), leaving bareModel out of the
ARN path construction.

In `@core/providers/bedrock/region_test.go`:
- Around line 100-137: Add a symmetric test case to
TestResolveBedrockRegion_AliasOverride to cover an empty alias Region falling
back to the key Region: modify the test to create a ctx where
schemas.ResolvedAlias.Config.Region is an empty schemas.EnvVar (or nil/empty
equivalent), then call resolveBedrockRegion(ctx, key, "anthropic.claude-v2") and
assert the returned region equals keyRegion; place this case alongside the
existing "No alias in ctx" and alias override checks so the behavior mirrors the
ARN empty-alias test.

In `@core/schemas/account.go`:
- Around line 339-379: ResolveFamily currently prefers alias ModelFamily → alias
ModelName → alias ModelID → alias Key and only uses fallbackModel when there is
no resolved alias/config; confirm and, if intended, document this precedence and
fallback behavior in the ResolveFamily function (and update tests) so Bedrock's
family-gated logic that calls Is*ModelFamily(ctx, <request model>) behaves
predictably when both ModelName and ModelID are present. Specifically, verify
GetResolvedAlias and ra.Config.ModelFamily handling, ensure the early return for
ra.Config.ModelFamily and the candidate ordering (ra.Config.ModelName,
ra.Config.ModelID, ra.Key) are correct, and add/adjust unit tests for
ResolveFamily to cover cases with both model_name and model_id set plus the
no-alias fallbackModel path.

---

Outside diff comments:
In `@core/providers/bedrock/responses.go`:
- Around line 2154-2188: Add table-driven unit tests exercising
ToBedrockResponsesRequest (and its helpers like
ConvertBifrostMessagesToBedrockMessages) to cover the family-gated branches:
Anthropic prefill trimming (alias-tagged Anthropic models), Nova reasoning
encoding, and Llama tool-choice suppression; for each case include variants
where model is provided via alias/Routing vs model_family so Bedrock routing
honors model_family as canonical, assert resulting
bedrockReq.Messages/System/flags are exactly as expected, and include negative
cases (no system messages, instructions present) to lock down the logic around
bedrockReq.System population and the trailing-text trimming behavior.
- Around line 2452-2458: The cache-point addition currently uses alias-resolved
family via schemas.IsNovaModelFamily(ctx, bifrostReq.Model) but later removal
still gates on the raw wire model via
BedrockModelSupportsCachePoints(bifrostReq.Model), which strips cache points for
aliased families; change the gating logic so cache-point support is determined
from the canonical model_family signal (e.g. bifrostReq.ModelFamily) rather than
the raw wire model ID — update the checks that call
BedrockModelSupportsCachePoints(...) and any schemas.IsNovaModelFamily(...)
usage in this flow to accept/inspect bifrostReq.ModelFamily (or equivalent
canonical field) so the BedrockTool/BedrockCachePoint additions
(BedrockCachePointTypeDefault) are preserved for alias-resolved families
end-to-end.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6b5a0e63-5dcd-4b6f-9ee5-f0b665b69820

📥 Commits

Reviewing files that changed from the base of the PR and between 6a8fd31 and fd94131.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/embedding.go
  • core/providers/bedrock/invoke.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/region_test.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/utils.go
  • core/schemas/account.go
  • core/schemas/utils.go
  • transports/bifrost-http/integrations/bedrock.go
🛑 Comments failed to post (3)
core/providers/bedrock/bedrock.go (1)

3599-3601: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the resolved inference-profile ARN as the full modelId.

resolveBedrockARN() is already the alias/key override identifier. Appending bareModel turns it into a synthetic arn/.../model value, so every invoke/converse/count-tokens/image call routed through an alias inference_profile_arn will hit an invalid Bedrock runtime path.

🐛 Proposed fix
 	if arn := resolveBedrockARN(ctx, key); arn != "" {
-		encodedModelIdentifier := url.PathEscape(fmt.Sprintf("%s/%s", arn, bareModel))
+		encodedModelIdentifier := url.PathEscape(arn)
 		p = fmt.Sprintf("%s/%s", encodedModelIdentifier, basePath)
 	}

As per coding guidelines, base_key.aliases[].inference_profile_arn is the per-alias Bedrock inference profile ARN override, and the PR objective says resolveBedrockARN should prefer that override when building Bedrock routing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/bedrock.go` around lines 3599 - 3601, The code is
appending bareModel to the resolved Bedrock inference-profile ARN
(resolveBedrockARN), producing an invalid synthetic ARN; instead use the
resolved ARN as the full modelId. Replace the current logic that builds
encodedModelIdentifier from fmt.Sprintf("%s/%s", arn, bareModel) and then sets p
to include bareModel, and instead URL-escape only the resolved arn (e.g.,
url.PathEscape(arn)) and compose p from that escaped arn and basePath (so p uses
the inference-profile ARN as the model identifier), leaving bareModel out of the
ARN path construction.

Source: Coding guidelines

core/providers/bedrock/region_test.go (1)

100-137: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider adding an empty alias region test case for symmetry with the ARN test.

The ARN test includes a case where the alias ARN is empty and verifies fallback to the key ARN (lines 171–183). Adding a parallel case here would validate that an empty alias Region also falls through to the key region, improving test coverage symmetry.

✅ Suggested test case
 	if got := resolveBedrockRegion(emptyCtx, key, "anthropic.claude-v2"); got != keyRegion {
 		t.Errorf("no alias: should use key.Region: got %q, want %q", got, keyRegion)
 	}
+
+	// Empty alias region — falls through to key.Region.
+	ctx3 := schemas.NewBifrostContext(nil, schemas.NoDeadline)
+	ctx3.SetValue(schemas.BifrostContextKeyResolvedAlias, &schemas.ResolvedAlias{
+		Key: "empty-region",
+		Config: &schemas.AliasConfig{
+			ModelID: "anthropic.claude-v2",
+			Region:  schemas.NewEnvVar(""),
+		},
+	})
+	if got := resolveBedrockRegion(ctx3, key, "anthropic.claude-v2"); got != keyRegion {
+		t.Errorf("empty alias region should fall through to key region: got %q, want %q", got, keyRegion)
+	}
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/bedrock/region_test.go` around lines 100 - 137, Add a
symmetric test case to TestResolveBedrockRegion_AliasOverride to cover an empty
alias Region falling back to the key Region: modify the test to create a ctx
where schemas.ResolvedAlias.Config.Region is an empty schemas.EnvVar (or
nil/empty equivalent), then call resolveBedrockRegion(ctx, key,
"anthropic.claude-v2") and assert the returned region equals keyRegion; place
this case alongside the existing "No alias in ctx" and alias override checks so
the behavior mirrors the ARN empty-alias test.
core/schemas/account.go (1)

339-379: ⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify that Bedrock conversion paths and tests reflect the same precedence.
# Expected: alias ModelFamily > alias ModelName > alias ModelID > alias Key > request.Model substring.

echo "=== Checking Bedrock provider usage of ResolveFamily and family helpers ==="
rg -n 'IsAnthropicModelFamily|IsMistralModelFamily|IsLlamaModelFamily|IsNovaModelFamily|IsCohereModelFamily|IsTitanModelFamily' core/providers/bedrock/

echo ""
echo "=== Checking test coverage for alias precedence ==="
rg -n 'ResolveBedrockRegion.*Alias|ResolveBedrockARN.*Alias' core/providers/bedrock/ --type go

Repository: maximhq/bifrost

Length of output: 4172


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Locate ResolveFamily + GetResolvedAlias in core/schemas/account.go ==="
rg -n "func (GetResolvedAlias|ResolveFamily)\b" core/schemas/account.go

echo ""
echo "=== Show ResolveFamily + surrounding logic (for actual fallback behavior) ==="
python3 - <<'PY'
import itertools
path="core/schemas/account.go"
start=1
# print around the ResolveFamily definition
import re
with open(path,'r',encoding='utf-8') as f:
    lines=f.readlines()
for i,l in enumerate(lines,1):
    if re.search(r'func ResolveFamily\b', l):
        start=max(1,i-40)
        end=i+80
        for j in range(start,end+1):
            if j<=len(lines):
                print(f"{j:5d}:{lines[j-1].rstrip()}")
        break
PY

echo ""
echo "=== Show GetResolvedAlias + resolved alias struct usage ==="
python3 - <<'PY'
import re
path="core/schemas/account.go"
with open(path,'r',encoding='utf-8') as f:
    lines=f.readlines()
for i,l in enumerate(lines,1):
    if re.search(r'func GetResolvedAlias\b', l):
        start=max(1,i-60)
        end=i+60
        for j in range(start,end+1):
            if j<=len(lines):
                print(f"{j:5d}:{lines[j-1].rstrip()}")
        break
PY

echo ""
echo "=== Find implementations of Is*ModelFamily helpers ==="
rg -n "func Is(Anthropic|Mistral|Gemini|Llama|Nova|Titan|Cohere)ModelFamily\b" core/schemas/

echo ""
echo "=== Show one representative Is*ModelFamily implementation (where fallbackModel is passed) ==="
python3 - <<'PY'
import re,glob
# pick IsAnthropicModelFamily if exists
targets=["IsAnthropicModelFamily","IsMistralModelFamily","IsGeminiModelFamily","IsLlamaModelFamily"]
for t in targets:
    for path in glob.glob("core/schemas/*.go"):
        with open(path,'r',encoding='utf-8') as f:
            s=f.read()
        if re.search(rf'func {re.escape(t)}\b', s):
            # print around definition
            lines=s.splitlines()
            # find line number
            all=open(path,'r',encoding='utf-8').read().splitlines()
            for i,l in enumerate(all,1):
                if re.search(rf'func {re.escape(t)}\b', l):
                    start=max(1,i-30); end=i+70
                    print("=== file:",path,"around",t,"===")
                    for j in range(start,end+1):
                        if j<=len(all):
                            print(f"{j:5d}:{all[j-1]}")
                    raise SystemExit(0)
PY

echo ""
echo "=== Inspect bedrock region/ARN alias override tests to see what precedence is asserted ==="
sed -n '1,220p' core/providers/bedrock/region_test.go

Repository: maximhq/bifrost

Length of output: 24172


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Locate Is*Model substring helpers ==="
rg -n "func Is(Anthropic|Mistral|Gemini|Llama|Nova|Titan|Cohere)Model\\b" core/schemas/

echo ""
echo "=== Show IsAnthropicModel + IsMistralModel implementations (representative) ==="
python3 - <<'PY'
import re,glob
targets=["IsAnthropicModel","IsMistralModel","IsGeminiModel","IsLlamaModel","IsNovaModel","IsTitanModel","IsCohereModel"]
paths=glob.glob("core/schemas/*.go")
for t in targets:
    for path in paths:
        txt=open(path,'r',encoding='utf-8').read().splitlines()
        for i,l in enumerate(txt,1):
            if re.search(rf'func {re.escape(t)}\b', l):
                start=max(1,i-5); end=i+25
                print(f"\n=== {path}:{t} ===")
                for j in range(start,end+1):
                    if j<=len(txt):
                        print(f"{j:5d}:{txt[j-1]}")
                break
        else:
            continue
        break
PY

Repository: maximhq/bifrost

Length of output: 9753


Confirm alias model-family precedence in ResolveFamily (and clarify fallback behavior)

ResolveFamily checks (with first-match wins): alias model_family → alias model_name → alias model_id → alias key; it only uses fallbackModel when there is no resolved alias/config in ctx. Bedrock’s family-gated logic relies on schemas.Is*ModelFamily(ctx, <request model>), so when both model_name and model_id are set, model_name will take precedence for the family match. Existing Bedrock alias tests cover Region/ARN overrides, not model-family precedence.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/schemas/account.go` around lines 339 - 379, ResolveFamily currently
prefers alias ModelFamily → alias ModelName → alias ModelID → alias Key and only
uses fallbackModel when there is no resolved alias/config; confirm and, if
intended, document this precedence and fallback behavior in the ResolveFamily
function (and update tests) so Bedrock's family-gated logic that calls
Is*ModelFamily(ctx, <request model>) behaves predictably when both ModelName and
ModelID are present. Specifically, verify GetResolvedAlias and
ra.Config.ModelFamily handling, ensure the early return for
ra.Config.ModelFamily and the candidate ordering (ra.Config.ModelName,
ra.Config.ModelID, ra.Key) are correct, and add/adjust unit tests for
ResolveFamily to cover cases with both model_name and model_id set plus the
no-alias fallbackModel path.

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from fd94131 to e79b4d0 Compare June 8, 2026 12:24
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from ad191cb to c34eafa Compare June 8, 2026 12:24
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_azure_alias_config_support branch from c34eafa to e033c73 Compare June 8, 2026 12:28
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-02-feat_add_bedrock_alias_config_support branch from e79b4d0 to 92a9e27 Compare June 8, 2026 12:28

akshaydeo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 9, 5:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 5:24 AM UTC: @akshaydeo merged this pull request with Graphite.

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.

3 participants