Toolkit for working with AWS code interpreter environment.
This toolkit provides a set of tools for working with a remote code interpreter environment:
The toolkit lazily initializes the code interpreter session on first use. It supports multiple threads by maintaining separate code interpreter sessions for each thread ID.
CodeInterpreterToolkit(
self,
region: str = 'us-west-2',
)Example:
import asyncio
from langchain.agents import create_agent
from langchain_aws.tools import create_code_interpreter_toolkit
async def main():
# Create and setup the code interpreter toolkit
toolkit, code_tools = await create_code_interpreter_toolkit(region="us-west-2")
# Create a ReAct agent using the code interpreter tools
agent = create_agent(
"bedrock_converse:us.anthropic.claude-haiku-4-5-20251001-v1:0",
tools=code_tools
)
# Create runnable config with thread ID
config = {
"configurable": {
"thread_id": "session123"
}
}
# Invoke the agent with a specific task using thread ID
result = await agent.ainvoke(
"Create a simple Python function that calculates the factorial of a number.",
config=config
)
# Cleanup when done
await toolkit.cleanup()
return result
# Run the example
asyncio.run(main())| Name | Type | Description |
|---|---|---|
region | str | Default: 'us-west-2'AWS region for the code interpreter |
| Name | Type |
|---|---|
| region | str |