fix(AIC-3382): support Bedrock configs in LangChain handlers - #101
Merged
Merged
Conversation
Apply inference-profile prefixes before model construction and report the configured provider so Bedrock calls and telemetry stay aligned. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
Route Bedrock configs through ChatBedrockConverse so callers no longer need to provide a custom model factory. Co-authored-by: Cursor <cursoragent@cursor.com>
andrewklatzke
commented
Sep 18, 2026
| See TELEMETRY-CONTRACT.md section 9. | ||
| """ | ||
| provider = str((config.get("provider") or {}).get("name") or "").lower() | ||
| return "anthropic" if provider == "anthropic" else "openai" |
Contributor
Author
There was a problem hiding this comment.
Not sure where this came from but obviously no bueno - uses the provider name from the config now
jeffdupont
approved these changes
Sep 18, 2026
apucacao
approved these changes
Sep 18, 2026
Prevent payload-owned tool definitions from leaking into ChatBedrockConverse constructor arguments while preserving the evaluated config. Co-authored-by: Cursor <cursoragent@cursor.com>
XieX
reviewed
Sep 18, 2026
| print("Usage:", json_pretty(event.get("usage"))) | ||
| if event.get("judgeResults"): | ||
| print("Judge results:", json_pretty(event["judgeResults"])) | ||
| sys.stdout.write("\n") |
Contributor
There was a problem hiding this comment.
The TS version writes the response as a fallback if no chunk was output, did we want to do the same in this example?
Contributor
Author
There was a problem hiding this comment.
Should be aligned now
Contributor
Author
Keep the streaming example aligned with TypeScript when a provider emits only a final event. Co-authored-by: Cursor <cursoragent@cursor.com>
andrewklatzke
added a commit
to launchdarkly/js-ai-sdk
that referenced
this pull request
Sep 18, 2026
## Summary TypeScript counterpart to launchdarkly/python-ai-sdk#101. Three fixes for LangChain handlers (`langchain-agents` and `langchain-messages`): - Bedrock configs with no explicit `llm` now instantiate `@langchain/aws`'s `ChatBedrockConverse` instead of falling through to `ChatOpenAI`. Model parameters and the region-prefixed model ID are forwarded. `@langchain/aws` is an optional peer dependency, with a clear install error when absent. - For Bedrock, `model.region` is prepended to the model ID as an inference-profile prefix. Prefixing is idempotent and applies to default constructors and user-supplied factories without mutating the caller's config. - `gen_ai.provider.name` now reports the configured provider lower-cased rather than collapsing non-Anthropic providers to OpenAI. `gen_ai.system` remains `langchain`. The streaming example also falls back to the final response when no chunk events are emitted. ## Test plan - [x] Unit tests for both LangChain handlers, including Bedrock default construction, region prefixing, and factory config handling - [x] Integration scenarios for success and failure paths - [x] Biome and TypeScript checks Jira: AIC-3382 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **AWS Bedrock** as a first-class default model path for the `langchain-agents` and `langchain-messages` handlers: Bedrock configs without a custom `llm` now build `ChatBedrockConverse` via dynamic `@langchain/aws` import (optional peer; clear error if missing). > > **Bedrock model IDs** get `model.region` prepended once as an inference-profile prefix (`us.model…`), without double-prefixing or mutating the caller’s config; factories receive a shallow copy with the resolved name. Bedrock constructor args **drop `tools` from `model.parameters`** so tool wiring stays on the agent/handler side. > > **OpenTelemetry** `gen_ai.provider.name` is now the configured provider name lower-cased (empty → `openai`), not only `anthropic` vs `openai`; `gen_ai.system` stays `langchain`. > > The **streaming example** prints the final `response` when no chunk events arrive, and logs usage/judge results on stdout instead of stderr debug noise. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fc1079d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Three fixes for LangChain handlers (
langchain-agentsandlangchain-messages):llmnow instantiatelangchain_aws.ChatBedrockConverseinstead of falling through toChatOpenAI. Model parameters and the region-prefixed model ID are forwarded. Iflangchain-awsis unavailable, the handler raises a clear error with the required install command.model.regionis prepended to the model ID as an inference-profile prefix. Prefixing is idempotent and applies to default constructors and user-supplied factories without mutating the caller's config.gen_ai.provider.namenow reports the configured provider lower-cased rather than collapsing non-Anthropic providers to OpenAI.gen_ai.systemremainslangchain.Test plan
Jira: AIC-3382
Note
Overview
LangChain handlers (
langchain-agents,langchain-messages) now treat Bedrock as a first-class default provider: missingllmbuildsChatBedrockConverse(requireslangchain-aws), resolvesmodel.regioninto an idempotent inference-profile prefix on the model id, and passes that via a non-mutating shallow config copy to default constructors and user factories. Bedrock constructor kwargs droptoolsfrommodel.parametersso tool wiring stays on the handler path.Telemetry changes:
gen_ai.provider.nameis the configured provider name lower-cased (empty →openai), not the previous anthropic-vs-openai collapse;gen_ai.systemstayslangchain.The streaming example prints the final
responsewhen nochunkevents arrived, and adds trailing newline formatting after usage/judge output.Reviewed by Cursor Bugbot for commit 221c23f. Bugbot is set up for automated code reviews on this repo. Configure here.