Skip to content

Commit ba056fb

Browse files
sundargthbSundar Raghavan
andauthored
docs: update quickstart example for agentcore-strands CI integration (#311)
* docs: update quickstart example for agentcore-strands CI integration * fix: update Launch logs to match the new experience --------- Co-authored-by: Sundar Raghavan <sdraghav@amazon.com>
1 parent a6d0bc1 commit ba056fb

File tree

1 file changed

+101
-111
lines changed

1 file changed

+101
-111
lines changed

documentation/docs/examples/agentcore-quickstart-example.md

Lines changed: 101 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ For Gateway and Identity features, see the [Gateway quickstart](https://github.c
88

99
## Prerequisites
1010

11-
- **AWS Permissions**: Root users or privileged roles (such as admins) can skip this step. Others need to attach the [starter toolkit policy](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html#runtime-permissions-starter-toolkit) and [AmazonBedrockAgentCoreFullAccess](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/BedrockAgentCoreFullAccess.html) managed policy.
12-
- [AWS CLI version 2.0 or later](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) configured (`aws configure`)
13-
- **Amazon Bedrock model access enabled for Claude 3.7 Sonnet** (Go to AWS Console → Bedrock → Model access → Enable "Claude 3.7 Sonnet" in your region). For information about using a different model with Strands Agents, see the Model Providers section in the [Strands Agents SDK](https://strandsagents.com/latest/documentation/docs/) documentation.
14-
- Python 3.10 or newer
11+
Before you start, make sure you have:
12+
13+
- **AWS permissions**: AWS root users or users with privileged roles (such as the AdministratorAccess role) can skip this step. Others need to attach the [starter toolkit policy](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html#runtime-permissions-starter-toolkit) and [AmazonBedrockAgentCoreFullAccess](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/BedrockAgentCoreFullAccess.html) managed policy.
14+
- **AWS CLI version 2.0 or later**: Configure the AWS CLI using `aws configure`. For more information, see the [AWS Command Line Interface User Guide for Version 2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
15+
- **Python 3.10 or newer**
1516

1617
> **Important: Ensure AWS Region Consistency**
1718
>
@@ -21,18 +22,20 @@ For Gateway and Identity features, see the [Gateway quickstart](https://github.c
2122
> - The region where you've enabled Bedrock model access
2223
> - All resources created during deployment will use this region
2324
24-
### Installation (version 0.1.21 or later)
25+
### Install the AgentCore starter toolkit
26+
27+
Install the AgentCore starter toolkit:
2528

2629
```bash
2730
# Create virtual environment
2831
python -m venv .venv
2932
source .venv/bin/activate # On Windows: .venv\Scripts\activate
3033

31-
# Install required packages
32-
pip install bedrock-agentcore-starter-toolkit strands-agents boto3
34+
# Install required packages (version 0.1.21 or later)
35+
pip install "bedrock-agentcore-starter-toolkit>=0.1.21" strands-agents strands-agents-tools boto3
3336
```
3437

35-
## Step 1A: Create a New Agent
38+
## Step 1: Create the agent
3639

3740
Create `agentcore_starter_strands.py`:
3841

@@ -41,10 +44,10 @@ Create `agentcore_starter_strands.py`:
4144
Strands Agent sample with AgentCore
4245
"""
4346
import os
44-
from strands import Agent, tool
47+
from strands import Agent
48+
from strands_tools.code_interpreter import AgentCoreCodeInterpreter
4549
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig, RetrievalConfig
4650
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
47-
from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
4851
from bedrock_agentcore.runtime import BedrockAgentCoreApp
4952

5053
app = BedrockAgentCoreApp()
@@ -53,64 +56,44 @@ MEMORY_ID = os.getenv("BEDROCK_AGENTCORE_MEMORY_ID")
5356
REGION = os.getenv("AWS_REGION")
5457
MODEL_ID = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
5558

56-
ci_sessions = {}
57-
current_session = None
58-
59-
@tool
60-
def calculate(code: str) -> str:
61-
"""Execute Python code for calculations or analysis."""
62-
session_id = current_session or 'default'
63-
64-
if session_id not in ci_sessions:
65-
ci_sessions[session_id] = {
66-
'client': CodeInterpreter(REGION),
67-
'session_id': None
68-
}
69-
70-
ci = ci_sessions[session_id]
71-
if not ci['session_id']:
72-
ci['session_id'] = ci['client'].start(
73-
name=f"session_{session_id[:30]}",
74-
session_timeout_seconds=1800
75-
)
76-
77-
result = ci['client'].invoke("executeCode", {
78-
"code": code,
79-
"language": "python"
80-
})
81-
82-
for event in result.get("stream", []):
83-
if stdout := event.get("result", {}).get("structuredContent", {}).get("stdout"):
84-
return stdout
85-
return "Executed"
86-
8759
@app.entrypoint
8860
def invoke(payload, context):
89-
global current_session
90-
91-
if not MEMORY_ID:
92-
return {"error": "Memory not configured"}
93-
94-
actor_id = context.headers.get('X-Amzn-Bedrock-AgentCore-Runtime-Custom-Actor-Id', 'user') if hasattr(context, 'headers') else 'user'
95-
96-
session_id = getattr(context, 'session_id', 'default')
97-
current_session = session_id
61+
actor_id = "quickstart-user"
62+
63+
# Get runtime session ID for isolation
64+
session_id = getattr(context, 'session_id', None)
65+
66+
# Configure memory if available
67+
session_manager = None
68+
if MEMORY_ID:
69+
memory_config = AgentCoreMemoryConfig(
70+
memory_id=MEMORY_ID,
71+
session_id=session_id or 'default',
72+
actor_id=actor_id,
73+
retrieval_config={
74+
f"/users/{actor_id}/facts": RetrievalConfig(top_k=3, relevance_score=0.5),
75+
f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5)
76+
}
77+
)
78+
session_manager = AgentCoreMemorySessionManager(memory_config, REGION)
9879

99-
memory_config = AgentCoreMemoryConfig(
100-
memory_id=MEMORY_ID,
101-
session_id=session_id,
102-
actor_id=actor_id,
103-
retrieval_config={
104-
f"/users/{actor_id}/facts": RetrievalConfig(top_k=3, relevance_score=0.5),
105-
f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5)
106-
}
80+
# Create Code Interpreter with runtime session binding
81+
code_interpreter = AgentCoreCodeInterpreter(
82+
region=REGION,
83+
session_name=session_id,
84+
auto_create=True
10785
)
10886

10987
agent = Agent(
11088
model=MODEL_ID,
111-
session_manager=AgentCoreMemorySessionManager(memory_config, REGION),
112-
system_prompt="You are a helpful assistant. Use tools when appropriate.",
113-
tools=[calculate]
89+
session_manager=session_manager,
90+
system_prompt="""You are a helpful assistant with code execution capabilities. Use tools when appropriate.
91+
Response format when using code:
92+
1. Brief explanation of your approach
93+
2. Code block showing the executed code
94+
3. Results and analysis
95+
""",
96+
tools=[code_interpreter.code_interpreter]
11497
)
11598

11699
result = agent(payload.get("prompt", ""))
@@ -125,21 +108,22 @@ Create `requirements.txt`:
125108
```text
126109
strands-agents
127110
bedrock-agentcore
111+
strands-agents-tools
128112
```
129113

130-
## Step 1B: Transform an Existing Agent to be Compatible with Runtime
114+
## Step 2: Configure and deploy the agent
131115

132-
1. Import the Runtime App with from bedrock_agentcore.runtime import BedrockAgentCoreApp
133-
2. Initialize the App in your code with app = BedrockAgentCoreApp()
134-
3. Decorate the invocation function with the @app.entrypoint decorator
135-
4. Create a requirements.txt file with needed packages. Note: if strands-tools is detected, the correct library to add is strands-agents-tools
136-
5. Let AgentCore Runtime control the running of the agent with app.run()
116+
In this step, you'll use the AgentCore CLI to configure and deploy your agent.
137117

138-
## Step 2: Configure and Deploy
118+
### Configure the agent
139119

140-
The AgentCore CLI automates deployment with provisioning.
120+
Configure the agent with memory and execution settings:
141121

142-
### Configure the Agent
122+
**For this tutorial**: When prompted for the execution role, press Enter to auto-create a new role with all required permissions for the Runtime, Memory, Code Interpreter, and Observability features. When prompted for long-term memory, type **yes**.
123+
124+
> **Note**
125+
>
126+
> If the memory configuration prompts do not appear during `agentcore configure`, refer to the [Troubleshooting](#troubleshooting) section (Memory configuration not appearing) for instructions on how to check whether the correct toolkit version is installed.
143127
144128
```bash
145129
agentcore configure -e agentcore_starter_strands.py
@@ -148,21 +132,20 @@ agentcore configure -e agentcore_starter_strands.py
148132

149133
# 1. Execution Role: Press Enter to auto-create or provide existing role ARN/name
150134
# 2. ECR Repository: Press Enter to auto-create or provide existing ECR URI
151-
# 3. OAuth Configuration: Configure OAuth authorizer? (yes/no) - Type `no` for this tutorial
152-
# 4. Request Header Allowlist: Configure request header allowlist? (yes/no) - Type `no` for this tutorial
153-
# 5. Memory Configuration:
135+
# 3. Requirements File: Confirm the detected requirements.txt file or specify a different path
136+
# 4. OAuth Configuration: Configure OAuth authorizer? (yes/no) - Type `no` for this tutorial
137+
# 5. Request Header Allowlist: Configure request header allowlist? (yes/no) - Type `no` for this tutorial
138+
# 6. Memory Configuration:
154139
# - If existing memories found: Choose from list or press Enter to create new
155-
# - If creating new: Enable long-term memory extraction? (yes/no) - Type `yes` for this tutorial
156-
# - Note: Short-term memory is always enabled by default
157-
# If interactive mode fails, use "--non-interactive" for default configs
140+
# - If creating new: Press Enter to create new memory
141+
# - Enable long-term memory extraction? (yes/no) - Type `yes` for this tutorial
142+
#. - Type 's' to skip memory setup
158143
```
159-
**For this tutorial**: When prompted for the execution role, press Enter to auto-create a new role with all required permissions for Runtime, Memory, Code Interpreter, and Observability. When prompted for long-term memory, type **yes** for this tutorial.
160-
161-
**Note**: If the memory configuration prompts do not appear during `agentcore configure`, refer to the [Troubleshooting](#troubleshooting) section (Memory Configuration Not Appearing) to ensure the correct toolkit version is installed.
162-
163144

164145
### Deploy to AgentCore
165146

147+
Launch your agent to the AgentCore runtime environment:
148+
166149
```bash
167150
agentcore launch
168151

@@ -176,9 +159,18 @@ agentcore launch
176159
```
177160

178161
**Expected output:**
162+
During launch, you'll see memory creation progress with elapsed time indicators. Memory provisioning may take around 2-5 minutes to activate:
179163

180164
```text
181-
✅ Memory created: agentcore_starter_strands_mem-abc123
165+
Creating memory resource for agent: agentcore_starter_strands
166+
⏳ Creating memory resource (this may take 30-180 seconds)...
167+
Created memory: agentcore_starter_strands_mem-abc123
168+
Waiting for memory agentcore_starter_strands_mem-abc123 to return to ACTIVE state...
169+
⏳ Memory: CREATING (61s elapsed)
170+
⏳ Memory: CREATING (92s elapsed)
171+
⏳ Memory: CREATING (123s elapsed)
172+
✅ Memory is ACTIVE (took 159s)
173+
✅ Memory created and active: agentcore_starter_strands_mem-abc123
182174
Observability is enabled, configuring Transaction Search...
183175
✅ Transaction Search configured: resource_policy, trace_destination, indexing_rule
184176
🔍 GenAI Observability Dashboard:
@@ -187,65 +179,61 @@ Observability is enabled, configuring Transaction Search...
187179
Agent ARN: arn:aws:bedrock-agentcore:us-west-2:123456789:runtime/agentcore_starter_strands-xyz
188180
```
189181

190-
**If deployment encounters errors or behaves unexpectedly**, check your configuration:
182+
If the deployment encounters errors or behaves unexpectedly, check your configuration:
191183
```bash
192184
cat .bedrock_agentcore.yaml # Review deployed configuration
193185
agentcore status # Verify resource provisioning status
194186
```
187+
195188
Refer to the [Troubleshooting](#troubleshooting) section if you see any issues.
196189

197190
## Step 3: Monitor Deployment
198191

199-
Check deployment status:
192+
Check the agent's deployment status:
200193

201194
```bash
202195
agentcore status
203196

204197
# Shows:
205198
# Memory ID: agentcore_starter_strands_mem-abc123
206-
# Memory Status: CREATING (if still provisioning)
207-
# Memory Type: STM+LTM (provisioning...) (if creating with LTM)
208199
# Memory Type: STM+LTM (3 strategies) (when active with strategies)
209200
# Memory Type: STM only (if configured without LTM)
210201
# Observability: Enabled
211202
```
212203

213-
**Note**: LTM strategies require 2-5 minutes to activate. STM is provisioned immediately if LTM is not selected.
214-
215204
## Step 4: Test Memory and Code Interpreter
216205

206+
In this section, you'll test your agent's memory capabilities and code execution features.
207+
217208
### Test Short-Term Memory (STM)
218209

219-
Testing within a single session:
210+
Test short-term memory within a single session:
220211

221212
```bash
222213
# Store information (session IDs must be 33+ characters)
223214
agentcore invoke '{"prompt": "Remember that my favorite agent platform is AgentCore"}'
224215

225-
# If invoked too early (memory still provisioning), you'll see:
226-
# "Memory is still provisioning (current status: CREATING).
227-
# Long-term memory extraction takes 60-180 seconds to activate.
228-
#
229-
# Please wait and check status with:
230-
# agentcore status"
231-
232216
# Retrieve within same session
233217
agentcore invoke '{"prompt": "What is my favorite agent platform?"}'
234218

235219
# Expected response:
236220
# "Your favorite agent platform is AgentCore."
237221
```
238222

239-
### Test Long-Term Memory (LTM) - Cross-Session Persistence
223+
### Test long-term memory – cross-session persistence
224+
225+
Long-term memory (LTM) lets information persist across different sessions. This requires waiting for long-term memory to be extracted before starting a new session.
240226

241-
LTM enables information persistence across different sessions. This requires waiting for LTM extraction after storing information.
227+
Test long-term memory by starting a session:
242228

243229
```bash
244230
# Session 1: Store facts
245231
agentcore invoke '{"prompt": "My email is user@example.com and I am an AgentCore user"}'
246232
```
247233

248-
Wait for extraction that runs in the background by AgentCore. This typically takes 10-30 seconds. If you do not see the facts, wait a few more seconds and try again.
234+
After invoking the agent, AgentCore runs in the background to perform an extraction. Wait for the extraction to finish. This typically takes 10-30 seconds. If you do not see any facts, wait a few more seconds.
235+
236+
Start another session:
249237

250238
```bash
251239
sleep 20
@@ -260,6 +248,8 @@ agentcore invoke '{"prompt": "Tell me about myself?"}' --session-id $SESSION_ID
260248

261249
### Test Code Interpreter
262250

251+
Test AgentCore Code Interpreter:
252+
263253
```bash
264254
# Store data
265255
agentcore invoke '{"prompt": "My dataset has values: 23, 45, 67, 89, 12, 34, 56."}'
@@ -272,7 +262,9 @@ agentcore invoke '{"prompt": "Create a text-based bar chart visualization showin
272262

273263
## Step 5: View Traces and Logs
274264

275-
### Access CloudWatch Dashboard
265+
In this section, you'll use observability features to monitor your agent's performance.
266+
267+
### Access the Amazon CloudWatch dashboard
276268

277269
Navigate to the GenAI Observability dashboard to view end-to-end request traces including agent execution tracking, memory retrieval operations, code interpreter executions, agent reasoning steps, and latency breakdown by component. The dashboard provides a service map view showing agent runtime connections to Memory and Code Interpreter services with request flow visualization and latency metrics, as well as detailed X-Ray traces for debugging and performance analysis.
278270

@@ -282,10 +274,12 @@ agentcore status
282274

283275
# Navigate to the URL shown, or go directly to:
284276
# https://console.aws.amazon.com/cloudwatch/home?region=us-west-2#gen-ai-observability/agent-core
285-
# Note: Replace the region
277+
# Note: Replace the Region
286278
```
287279

288-
### View Agent Runtime Logs
280+
### View AgentCore Runtime logs
281+
282+
Access detailed AgentCore Runtime logs for debugging and monitoring:
289283

290284
```bash
291285
# The correct log paths are shown in the invoke or status output
@@ -302,15 +296,17 @@ aws logs tail /aws/bedrock-agentcore/runtimes/AGENT_ID-DEFAULT --log-stream-name
302296
aws logs tail /aws/bedrock-agentcore/runtimes/AGENT_ID-DEFAULT --log-stream-name-prefix "YYYY/MM/DD/[runtime-logs]" --since 1h
303297
```
304298

305-
## Clean Up
299+
## Clean up
300+
301+
Remove all resources created during this tutorial:
306302

307303
```bash
308304
agentcore destroy
309305

310306
# Removes:
311-
# - Runtime endpoint and agent
312-
# - Memory resources (STM + LTM)
313-
# - ECR repository and images
307+
# - AgentCore Runtime endpoint and agent
308+
# - AgentCore Memory resources (short- and long-term memory)
309+
# - Amazon ECR repository and images
314310
# - IAM roles (if auto-created)
315311
# - CloudWatch log groups (optional)
316312
```
@@ -407,12 +403,6 @@ pip install --no-cache-dir "bedrock-agentcore-starter-toolkit>=0.1.21" strands-a
407403
<details>
408404
<summary><strong>Memory Issues</strong></summary>
409405

410-
**"Memory status is not active" error:**
411-
412-
- Run `agentcore status` to check memory status
413-
- If showing "provisioning", wait 2-3 minutes
414-
- Retry after status shows "STM+LTM (3 strategies)"
415-
416406
**Cross-session memory not working:**
417407

418408
- Verify LTM is active (not "provisioning")

0 commit comments

Comments
 (0)