A simple code-editing agent built with AWS Bedrock and Anthropic Claude, following the pattern from ampcode.com/how-to-build-an-agent.
The agent implements a simple loop:
- User sends a message
- Agent forwards to Claude via AWS Bedrock
- Claude decides if it needs tools
- Agent executes requested tools locally
- Tool results are sent back to Claude
- Repeat until Claude provides final answer
- read_file: Read contents of a file
- list_files: List files in a directory
- edit_file: Edit a file by replacing text
-
Install dependencies:
pip install -r requirements.txt
-
Set AWS credentials:
export AWS_BEARER_TOKEN_BEDROCK=your-token export AWS_REGION=us-east-1 # optional, defaults to us-east-1
-
Run the agent:
# Use default model (Claude Sonnet 4.5) python bedrock_agent.py # Or specify a model ID python bedrock_agent.py anthropic.claude-haiku-4-5-20251001-v1:0 # Or set via environment variable export BEDROCK_MODEL_ID=anthropic.claude-opus-4-5-20251101-v1:0 python bedrock_agent.py
Sinä: What files are in the current directory?
[TYÖKALU] Käytetään: list_files
Parametrit: {
"path": "."
}
Agentti: The current directory contains:
[FILE] bedrock_agent.py
[FILE] example.py
[FILE] requirements.txt
[FILE] README_AGENT.md
Sinä: What's in example.py?
[TYÖKALU] Käytetään: read_file
Parametrit: {
"path": "example.py"
}
Agentti: The example.py file contains a simple Python script with...
Sinä: Change the hello_world function to print "Hello, Agent!" instead
[TYÖKALU] Käytetään: read_file
Parametrit: {
"path": "example.py"
}
[TYÖKALU] Käytetään: edit_file
Parametrit: {
"path": "example.py",
"old_str": "print(\"Hello, World!\")",
"new_str": "print(\"Hello, Agent!\")"
}
Agentti: I've successfully updated the hello_world function...
Uses anthropic.claude-sonnet-4-5-20250929-v1:0 (Claude Sonnet 4.5) by default. Available Anthropic models on Bedrock:
anthropic.claude-opus-4-5-20251101-v1:0(Claude Opus 4.5 - most capable)anthropic.claude-sonnet-4-5-20250929-v1:0(Claude Sonnet 4.5 - balanced)anthropic.claude-haiku-4-5-20251001-v1:0(Claude Haiku 4.5 - fastest)anthropic.claude-sonnet-4-20250514-v1:0(Claude Sonnet 4)anthropic.claude-3-7-sonnet-20250219-v1:0(Claude 3.7 Sonnet)
Claude autonomously decides when tools are helpful. You don't need to explicitly tell it to use tools - it understands tool utility through its training.