A minimal LangGraph agent demonstrating core AgentCore concepts using code deployment.
Alternative: See langgraph-basic-docker for the same agent using Docker/container deployment.
- BedrockAgentCoreApp: Integration pattern for AgentCore Runtime
- LangGraph: Agent orchestration with state management
- Claude Sonnet 5: High-performance reasoning model
- Simple Tools: Calculator and time tools
- Code Deployment: Python-based deployment (no Dockerfile needed)
User Request → AgentCore Runtime → agent_invocation()
↓
LangGraph
↓
Claude Sonnet 5
↓
(uses built-in tools)
↓
Response
- AWS account with Bedrock model access (Claude Sonnet 5)
- Enable access to the
global.anthropic.claude-sonnet-5inference profile in Bedrock console - Serverless Framework v4+
- AWS credentials configured
- No Docker required (unlike container deployment)
Important: This example uses the global cross-region inference profile for better availability and throughput. Direct model IDs may not support on-demand invocation.
# From this directory
serverless deployThe framework will:
- Package Python code with dependencies
- Upload to Amazon S3
- Deploy AgentCore Runtime with managed Python runtime
- Output the invocation URL
Using the provided test script:
# Update RUNTIME_ARN in test-invoke.py first
python3 test-invoke.pyOr invoke programmatically with boto3:
import boto3
import json
import uuid
client = boto3.client('bedrock-agentcore', region_name='us-east-1')
response = client.invoke_agent_runtime(
agentRuntimeArn='YOUR_RUNTIME_ARN', # From deploy output
runtimeSessionId=str(uuid.uuid4()),
payload=json.dumps({"prompt": "What is 25 multiplied by 4?"}).encode()
)
# Parse response
result = json.loads(response['response'].read())
print(result)Important: You cannot invoke AgentCore runtimes directly via curl. You must use the AWS SDK with the
bedrock-agentcoreclient and theinvoke_agent_runtimeAPI method.
Test locally before deploying:
serverless devagent.py implements a simple LangGraph agent:
- Initialize LLM: Uses Claude Sonnet 5 via Bedrock Converse API
- Define Tools: Adds calculator and time tools using
@tooldecorator - Build Graph: Creates a state machine with chatbot and tool nodes
- Entrypoint:
@app.entrypointdecorator marks the invocation function - Process Messages: Handles requests and returns responses
START → chatbot → [decide: use tool or respond]
↑ ↓
└─── tools ←┘
- chatbot node: Invokes Claude with tool availability
- tools node: Executes tools if requested
- conditional edge: Decides whether to use tools based on LLM response
The configuration specifies:
handler: agent.py- Entry point file (triggers code deployment mode)package.patterns- Files to include
Dependencies in requirements.txt are bundled automatically by AgentCore's code deployment packaging.
AgentCore automatically:
- Packages code with dependencies
- Uploads to S3
- Deploys to managed Python runtime
| Aspect | Code (this example) | Docker |
|---|---|---|
| Configuration | handler: agent.py |
chatbot: {} |
| Dependencies | requirements.txt |
pyproject.toml + Dockerfile |
| Build | Automatic packaging to S3 | Docker image to ECR |
| Runtime | AWS managed Python | Custom container |
| Languages | Python only | Any language |
| Setup | No Dockerfile needed | Dockerfile required |
The default model is global.anthropic.claude-sonnet-5, read from the MODEL_ID environment variable in agent.py. Override it via the MODEL_ID env var:
ai:
agents:
chatbot:
handler: agent.py
environment:
MODEL_ID: us.anthropic.claude-opus-4-1-20250805-v1:0 # Different modelAdd tools in agent.py using the @tool decorator:
from langchain_core.tools import tool
@tool
def search_database(query: str) -> str:
"""Search the product database."""
# Your database logic here
return f"Found products matching: {query}"
# Add to tools list
tools = [get_current_time, add, multiply, search_database]Add optional runtime configuration:
ai:
agents:
chatbot:
handler: agent.py
environment:
CUSTOM_VAR: value
lifecycle:
idleRuntimeSessionTimeout: 900 # Idle timeout (60-28800 seconds)
maxLifetime: 3600 # Max lifetime (60-28800 seconds)Remove all resources:
serverless remove- Add gateway tools - Expose Lambda functions as agent tools
- Add memory - Enable conversation persistence