Skip to content

Add AWS Bedrock provider to the ai module - #329

Merged
tmgbedu merged 2 commits into
mainfrom
feat/ai-bedrock-provider
Oct 30, 2026
Merged

tmgbedu merged 2 commits into
mainfrom
feat/ai-bedrock-provider

Conversation

@claude-tmgbedu

Copy link
Copy Markdown

Summary

  • New provider="bedrock", resolved through LangChain's bedrock_converse (ChatBedrockConverse). It goes through the same init_chat_model path as the other providers, so tools, structured output, streaming and fakes work unchanged.
  • BedrockConfig reads AWS_REGION (falls back to AWS_DEFAULT_REGION), AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_PROFILE, AWS_BEARER_TOKEN_BEDROCK (Bedrock API key) and AWS_BEDROCK_MODEL. It is registered in AIConfig.providers and exported from fastapi_startkit.ai.
  • Lab.get_client_options() maps these settings to ChatBedrockConverse arguments and drops empty values, so boto3's default credential chain applies when they are unset. Other providers return {}, so their behaviour is unchanged.
  • langchain-aws is the new optional bedrock extra (fastapi-startkit[ai,bedrock]). The framework never imports it. When it is missing, a Bedrock agent raises LangChain's ImportError naming langchain-aws.
  • ADR 047 is added and indexed.

Notes

  • The default model us.anthropic.claude-sonnet-4-6 is a cross-region inference profile id. Override it with AWS_BEDROCK_MODEL if it is not enabled in your account or region.
  • uv.lock bumps langchain-core and langsmith because langchain-aws requires the newer versions.

Test plan

  • tests/ai/test_bedrock.py: config env mapping, region fallback, empty defaults, provider/model resolution, client options with and without credentials
  • tests/ai/test_agent.py: Bedrock agent build with a mocked init_chat_model (runs where langchain is installed; checked on Python 3.14)
  • Manual check: a real ChatBedrockConverse instance is built with the right model id, region and timeout (no AWS call), and there is a clear ImportError when the extra is missing
  • uv run pytest --ignore=tests/masoniteorm/postgres --cov: 3502 passed, 92.23% coverage

🤖 Generated with Claude Code

Agents can select provider="bedrock", resolved through LangChain's
bedrock_converse (ChatBedrockConverse). BedrockConfig reads region,
IAM credentials, session token, profile, Bedrock API key and model id
from the standard AWS env vars; unset values are omitted so boto3's
default credential chain applies. langchain-aws ships as the optional
bedrock extra.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
langchain-aws does not depend on langchain, which provides
init_chat_model, so installing only fastapi-startkit[bedrock] failed
with ModuleNotFoundError. The extra now self-references
fastapi-startkit[ai].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude-tmgbedu

Copy link
Copy Markdown
Author

The QA note about the bedrock extra is fixed in 279380a.

  • bedrock is now ["fastapi-startkit[ai]", "langchain-aws>=1.0.0"]. langchain-aws doesn't depend on langchain, so the extra now pulls in the ai extra, which keeps the LangChain pins in one place.
  • uv.lock and ADR 047 (including its index entry) are updated.

Verification, on Python 3.14 with fresh venvs:

  • [bedrock] only: langchain and langchain-aws are both installed. A provider = "bedrock" agent built with mocked AWS env returns ChatBedrockConverse (us.anthropic.claude-sonnet-4-6, us-east-1), with no AWS calls.
  • [ai] only: langchain is installed and langchain-aws is not.
  • uv run pytest --ignore=tests/masoniteorm/postgres --cov: 3502 passed, 92.23% coverage.

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu
tmgbedu merged commit 788ccba into main Oct 30, 2026
10 checks passed
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.

2 participants