2025-07-17 10:14:13 -04:00
# Strands Agent with Bedrock AgentCore Integration
2025-07-18 12:04:54 -04:00
| Information | Details |
|---------------------|------------------------------------------------------------------------------|
| Agent type | Synchronous |
| Agentic Framework | Strands |
| LLM model | Anthropic Claude 3 Haiku |
| Components | AgentCore Runtime |
| Example complexity | Easy |
| SDK used | Amazon BedrockAgentCore Python SDK |
2025-07-17 10:14:13 -04:00
These example demonstrate how to integrate a Strands agents with AWS Bedrock AgentCore, enabling you to deploy your agent as a managed service. You can use the `agentcore` CLI to configure and launch these agents.
## Prerequisites
- Python 3.10+
- [uv ](https://github.com/astral-sh/uv ) - Fast Python package installer and resolver
- AWS account with Bedrock Agentcore access
## Setup Instructions
### 1. Create a Python Environment with uv
```bash
# Install uv if you don't have it already
# Create and activate a virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
### 2. Install Requirements
```bash
uv pip install -r requirements.txt
```
2025-07-23 14:12:58 -04:00
### 3. Configure API Key Provider (for OpenAI + strands example)
If you're using OpenAI models with your Strands agent, you'll need to set up an API key provider:
```python
from bedrock_agentcore.services.identity import IdentityClient
from boto3.session import Session
import boto3
boto_session = Session()
region = boto_session.region_name
# Configure API Key Provider
identity_client = IdentityClient(region=region)
api_key_provider = identity_client.create_api_key_credential_provider({
"name": "openai-apikey-provider",
"apiKey": "sk-..." # Replace it with the API key you obtain from OpenAI
})
print(api_key_provider)
```
### 4. Understanding the Agent Code
2025-07-17 10:14:13 -04:00
The `strands_agent_file_system.py` file contains a simple Strands agent with file system capabilities, integrated with Bedrock AgentCore:
```python
import os
os.environ["BYPASS_TOOL_CONSENT"]="true"
from strands import Agent
from strands_tools import file_read, file_write, editor
# Initialize Strands agent with file system tools
agent = Agent(tools=[file_read, file_write, editor])
# Integrate with Bedrock AgentCore
from bedrock_agentcore.runtime import BedrockAgentCoreApp
app = BedrockAgentCoreApp()
@app .entrypoint
def agent_invocation(payload, context):
"""Handler for agent invocation"""
user_message = payload.get("prompt", "No prompt found in input, please guide customer to create a json payload with prompt key")
result = agent(user_message)
return {"result": result.message}
app.run()
```
2025-07-23 14:12:58 -04:00
### 5. Configure and Launch with Bedrock AgentCore Toolkit
2025-07-17 10:14:13 -04:00
```bash
# Configure your agent for deployment
agentcore configure -e strands_agent_file_system.py
# Deploy your agent
agentcore launch
```
2025-07-23 14:12:58 -04:00
### 6. Testing Your Agent
2025-07-17 10:14:13 -04:00
Once deployed, you can test your agent using:
```bash
agentcore invoke '{"prompt":"hello"}'
```