Michael Chin b33dadae7a test(aws): Make integration test cassettes AWS region agnostic (#1156)
Fixing some cassette errors seen in [live integ test
runs](https://github.com/langchain-ai/langchain-aws/actions/runs/29048020685/job/86221390451)
following the updates in
https://github.com/langchain-ai/langchain-aws/pull/1154:
```
E               vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('tests/cassettes/test_thinking[v0].yaml.gz') in your current record mode (<RecordMode.ONCE: 'once'>).
E               No match for the request (<Request (POST) https://bedrock-runtime.***.amazonaws.com/model/us.anthropic.claude-sonnet-5/converse-stream>) was found.
E               Found 1 similar requests with 1 different matcher(s) :
E               
E               1 - (<Request (POST) https://bedrock-runtime.us-west-2.amazonaws.com/model/us.anthropic.claude-sonnet-5/converse-stream>).
E               Matchers succeeded : ['method', 'body']
E               Matchers failed :
E               uri - assertion failure :
E               https://bedrock-runtime.***.amazonaws.com/model/us.anthropic.claude-sonnet-5/converse-stream != https://bedrock-runtime.us-west-2.amazonaws.com/model/us.anthropic.claude-sonnet-5/converse-stream
```

Basically, the new cassettes for the revised tests with Sonnet 5 were
recorded from my local runs on `us-west-2`, while the CI actually runs
on a different region (that's obfuscated by the `AWS_REGION` secret).
VCR's default matcher requires the endpoint URIs to match exactly, so
the replays fail.

To fix this, I've loosened the URI check by replacing VCR's default
matcher with a custom `region_agnostic_uri` matcher, stripping the
region ID from the host before performing the comparison.

This has two advantages:
- It allows future cassettes to be recorded from any region.
- We can easily move integ CI to a different `AWS_REGION` without having
to update the cassettes to do so.
2026-07-10 20:04:15 -07:00
2026-03-13 11:00:55 -04:00
2024-03-06 13:29:01 -08:00

🦜🔗 LangChain 🤝 Amazon Web Services (AWS)

This monorepo provides LangChain and LangGraph components for various AWS services. It aims to replace and expand upon the existing LangChain AWS components found in the langchain-community package in the LangChain repository.

The following packages are hosted in this repository:

  • langchain-aws (PyPI)
  • langgraph-checkpoint-aws (PyPI)
  • langchain-agentcore-codeinterpreter (PyPI)

Features

LangChain

LangGraph

Deep Agents

...and more to come. This repository will continue to expand and offer additional components for various AWS services as development progresses.

Note: This repository will replace all AWS integrations currently present in the langchain-community package. Users are encouraged to migrate to this repository as soon as possible.

Installation

You can install the langchain-aws package from PyPI.

pip install langchain-aws

The langgraph-checkpoint-aws package can also be installed from PyPI.

pip install langgraph-checkpoint-aws

The langchain-agentcore-codeinterpreter package can also be installed from PyPI.

pip install langchain-agentcore-codeinterpreter

Usage

langchain-aws

Here's a simple example of how to use the langchain-aws package.

from langchain_aws import ChatBedrockConverse

# Initialize the Bedrock chat model
model = ChatBedrockConverse(
    model="us.anthropic.claude-sonnet-4-5-20250929-v1:0"
)

# Invoke the model
response = model.invoke("Hello! How are you today?")
print(response)

AgentCore Tools

from langchain_aws.tools import create_browser_toolkit, create_code_interpreter_toolkit

# Browser automation
browser_toolkit, browser_tools = create_browser_toolkit(region="us-west-2")

# Code execution (async)
code_toolkit, code_tools = await create_code_interpreter_toolkit(region="us-west-2")

# Use with LangGraph agent
agent = create_react_agent(model, tools=browser_tools + code_tools)
result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "Navigate to example.com"}]},
    config={"configurable": {"thread_id": "session-1"}}
)

# Cleanup
await browser_toolkit.cleanup()
await code_toolkit.cleanup()

For more detailed usage examples and documentation, please refer to the LangChain docs.

Tip

For developing, debugging, and deploying AI agents and LLM applications, see LangSmith.

langgraph-checkpoint-aws

You can find usage examples for langgraph-checkpoint-aws in the README.

langchain-agentcore-codeinterpreter

from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
from langchain_agentcore_codeinterpreter import AgentCoreSandbox

interpreter = CodeInterpreter(region="us-west-2")
interpreter.start()

backend = AgentCoreSandbox(interpreter=interpreter)
result = backend.execute("echo hello")
print(result.output)  # hello

interpreter.stop()

Contributing

We welcome contributions to this repository! To get started, please follow the Contributing Guide.

This guide provides detailed instructions on how to set up each project for development and guidance on how to contribute effectively.

License

This project is licensed under the MIT License.

S
Description
Build LangChain Applications on AWS
Readme MIT 55 MiB
Latest
2026-02-26 20:55:17 -05:00
Languages
Python 99.6%
Makefile 0.4%