Skip to content

Commit 2968419

Browse files
refactor(agentcore): restructure code providing more clear view, fix side bar display issue, update ADOT version (#210)
Co-authored-by: Jack Yuan <jackypc@amazon.com>
1 parent 4dd4ad8 commit 2968419

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

docs/user-guide/deploy/deploy_to_bedrock_agentcore.md

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Before you start, you need:
1515

1616
---
1717

18-
## 🚨 Don't forget observability
19-
>
18+
> 🚨 **Don't forget observability**
19+
>
2020
> 📈 **[AgentCore runtime observability](#observability-enablement)** - Distributed tracing, metrics, and debugging
2121
>
2222
> **This section is at the bottom of this document - don't skip it**
@@ -55,21 +55,21 @@ pip install bedrock-agentcore
5555

5656
### Step 2: Prepare Your Agent Code
5757

58-
#### Basic Setup (3 simple steps)
58+
Basic Setup (3 simple steps)
5959

60-
##### Import the runtime
60+
Import the runtime
6161

6262
```python
6363
from bedrock_agentcore.runtime import BedrockAgentCoreApp
6464
```
6565

66-
##### Initialize the app
66+
Initialize the app
6767

6868
```python
6969
app = BedrockAgentCoreApp()
7070
```
7171

72-
##### Decorate your function
72+
Decorate your function
7373

7474
```python
7575
@app.entrypoint
@@ -81,9 +81,9 @@ if __name__ == "__main__":
8181
app.run()
8282
```
8383

84-
#### Complete Examples
84+
Complete Examples
8585

86-
##### Basic Example
86+
- Basic Example
8787

8888
```python
8989
from bedrock_agentcore.runtime import BedrockAgentCoreApp
@@ -103,7 +103,7 @@ if __name__ == "__main__":
103103
app.run()
104104
```
105105

106-
##### Streaming Example
106+
- Streaming Example
107107

108108
```python
109109
from strands import Agent
@@ -142,15 +142,15 @@ curl -X POST http://localhost:8080/invocations \
142142

143143
> **Choose ONE of the following deployment methods:**
144144
145-
### Method A: Starter Toolkit (For quick prototyping)
145+
#### Method A: Starter Toolkit (For quick prototyping)
146146

147147
For quick prototyping with automated deployment:
148148

149149
```bash
150150
pip install bedrock-agentcore-starter-toolkit
151151
```
152152

153-
#### Project Structure
153+
Project Structure
154154

155155
```
156156
your_project_directory/
@@ -159,7 +159,7 @@ your_project_directory/
159159
└── __init__.py # Makes the directory a Python package
160160
```
161161

162-
#### agent_example.py
162+
Example: agent_example.py
163163

164164
```python
165165
from strands import Agent
@@ -179,16 +179,16 @@ if __name__ == "__main__":
179179
app.run()
180180
```
181181

182-
#### requirements.txt
182+
Example: requirements.txt
183183

184184
```
185185
strands-agents
186186
bedrock-agentcore
187187
```
188188

189-
#### Deploy with Starter Toolkit
189+
Deploy with Starter Toolkit
190190

191-
Ensure Docker is running before proceeding:
191+
> Ensure Docker is running before proceeding:
192192
193193
```bash
194194
# Configure your agent
@@ -204,7 +204,7 @@ agentcore launch
204204
agentcore invoke '{"prompt": "Hello"}'
205205
```
206206

207-
### Method B: Manual Deployment with boto3
207+
#### Method B: Manual Deployment with boto3
208208

209209
For more control over the deployment process:
210210

@@ -232,7 +232,7 @@ response = client.create_agent_runtime(
232232
)
233233
```
234234

235-
3. Invoke Your Agent
235+
Invoke Your Agent
236236

237237
```python
238238
import boto3
@@ -252,8 +252,8 @@ response = agent_core_client.invoke_agent_runtime(
252252
)
253253
```
254254

255-
### 📊 Next Steps: Set Up Observability (Optional)
256-
255+
>📊 Next Steps: Set Up Observability (Optional)
256+
>
257257
> **⚠️ IMPORTANT**: Your agent is deployed, you could also set up [Observability](#observability-enablement)
258258
259259

@@ -265,30 +265,31 @@ response = agent_core_client.invoke_agent_runtime(
265265
266266
This approach demonstrates how to deploy a custom agent using FastAPI and Docker, following AgentCore Runtime requirements.
267267

268-
### Requirements
268+
**Requirements**
269269

270270
- **FastAPI Server**: Web server framework for handling requests
271271
- **/invocations Endpoint**: POST endpoint for agent interactions (REQUIRED)
272272
- **/ping Endpoint**: GET endpoint for health checks (REQUIRED)
273273
- **Docker Container**: ARM64 containerized deployment package
274274

275-
### Quick Start Setup
275+
### Step 1: Quick Start Setup
276276

277-
#### Install uv
277+
Install uv
278278

279279
```bash
280280
curl -LsSf https://astral.sh/uv/install.sh | sh
281281
```
282282

283-
#### Create Project
283+
Create Project
284284

285285
```bash
286286
mkdir my-custom-agent && cd my-custom-agent
287287
uv init --python 3.11
288288
uv add fastapi uvicorn[standard] pydantic httpx strands-agents
289289
```
290290

291-
### Project Structure
291+
Project Structure example
292+
292293
```
293294
my-custom-agent/
294295
├── agent.py # FastAPI application
@@ -297,9 +298,9 @@ my-custom-agent/
297298
└── uv.lock # Created automatically by uv
298299
```
299300

300-
### Complete Strands Agent Example
301+
### Step 2: Prepare your agent code
301302

302-
#### agent.py
303+
Example: agent.py
303304

304305
```python
305306
from fastapi import FastAPI, HTTPException
@@ -350,7 +351,7 @@ if __name__ == "__main__":
350351
uvicorn.run(app, host="0.0.0.0", port=8080)
351352
```
352353

353-
### Test Locally
354+
### Step 3: Test Locally
354355

355356
```bash
356357
# Run the application
@@ -367,7 +368,9 @@ curl -X POST http://localhost:8080/invocations \
367368
}'
368369
```
369370

370-
### Create Dockerfile
371+
### Step 4: Prepare your docker image
372+
373+
Create docker file
371374

372375
```dockerfile
373376
# Use uv's ARM64 Python base image
@@ -391,15 +394,13 @@ EXPOSE 8080
391394
CMD ["uv", "run", "uvicorn", "agent:app", "--host", "0.0.0.0", "--port", "8080"]
392395
```
393396

394-
### Build and Deploy ARM64 Image
395-
396-
#### Setup Docker buildx
397+
Setup Docker buildx
397398

398399
```bash
399400
docker buildx create --use
400401
```
401402

402-
#### Build and Test Locally
403+
Build and Test Locally
403404

404405
```bash
405406
# Build the image
@@ -414,7 +415,7 @@ docker run --platform linux/arm64 -p 8080:8080 \
414415
my-agent:arm64
415416
```
416417

417-
#### Deploy to ECR
418+
Deploy to ECR
418419

419420
```bash
420421
# Create ECR repository
@@ -430,9 +431,9 @@ docker buildx build --platform linux/arm64 -t <account-id>.dkr.ecr.us-west-2.ama
430431
aws ecr describe-images --repository-name my-strands-agent --region us-west-2
431432
```
432433

433-
### Deploy Agent Runtime
434+
### Step 5: Deploy Agent Runtime
434435

435-
#### deploy_agent.py
436+
Example: deploy_agent.py
436437

437438
```python
438439
import boto3
@@ -455,13 +456,15 @@ print(f"Agent Runtime ARN: {response['agentRuntimeArn']}")
455456
print(f"Status: {response['status']}")
456457
```
457458

459+
Execute python file
460+
458461
```bash
459462
uv run deploy_agent.py
460463
```
461464

462-
### Invoke Your Agent
465+
### Step 6: Invoke Your Agent
463466

464-
#### invoke_agent.py
467+
Example: invoke_agent.py
465468

466469
```python
467470
import boto3
@@ -484,11 +487,13 @@ response_data = json.loads(response_body)
484487
print("Agent Response:", response_data)
485488
```
486489

490+
Execute python file
491+
487492
```bash
488493
uv run invoke_agent.py
489494
```
490495

491-
### Expected Response Format
496+
Expected Response Format
492497

493498
```json
494499
{
@@ -509,11 +514,11 @@ uv run invoke_agent.py
509514

510515
---
511516

512-
# Shared Information (Both Options)
517+
## Shared Information
513518

514519
> **This section applies to both deployment approaches** - reference as needed regardless of which option you chose.
515520
516-
## AgentCore Runtime Requirements Summary
521+
### AgentCore Runtime Requirements Summary
517522

518523
- **Platform**: Must be linux/arm64
519524
- **Endpoints**: /invocations POST and /ping GET are mandatory
@@ -522,7 +527,7 @@ uv run invoke_agent.py
522527
- **Strands Integration**: Uses Strands Agent for AI processing
523528
- **Credentials**: Require AWS credentials for operation
524529

525-
## Best Practices
530+
### Best Practices
526531

527532
**Development**
528533

@@ -542,7 +547,7 @@ uv run invoke_agent.py
542547
- Secure sensitive information
543548
- Regular security updates
544549

545-
## Troubleshooting
550+
### Troubleshooting
546551

547552
**Deployment Failures**
548553

@@ -572,11 +577,13 @@ Amazon Bedrock AgentCore provides built-in metrics to monitor your Strands agent
572577
Before you can view metrics and traces, complete this one-time setup:
573578

574579
**Via AgentCore Console**
575-
- Look for the "Enable Observability" button when creating a memory resource
580+
581+
Look for the **"Enable Observability"** button when creating a memory resource
576582

577583
>If you don't see this button while configuring your agent (for example, if you don't create a memory resource in the console), you must enable observability manually by using the CloudWatch console to enable Transaction Search as described in the following procedure.
578584
579585
**Via CloudWatch Console**
586+
580587
1. Open the CloudWatch console
581588
2. Navigate to Application Signals (APM) > Transaction search
582589
3. Choose "Enable Transaction Search"
@@ -586,8 +593,6 @@ Before you can view metrics and traces, complete this one-time setup:
586593

587594
### Step 2: Add ADOT to Your Strands Agent
588595

589-
#### 1. Add Dependencies
590-
591596
Add to your `requirements.txt`:
592597
```text
593598
aws-opentelemetry-distro>=0.10.1
@@ -599,23 +604,30 @@ Or install directly:
599604
pip install aws-opentelemetry-distro>=0.10.1 boto3
600605
```
601606

602-
#### 2. Run With Auto-Instrumentation
607+
Run With Auto-Instrumentation
603608

604-
**For SDK Integration (Option A):**
609+
- For SDK Integration (Option A):
605610
```bash
606611
opentelemetry-instrument python my_agent.py
607612
```
608613

609-
**For Docker Deployment:**
614+
- For Docker Deployment:
610615
```dockerfile
611616
CMD ["opentelemetry-instrument", "python", "main.py"]
612617
```
613618

614-
**For Custom Agent (Option B):**
619+
- For Custom Agent (Option B):
615620
```dockerfile
616621
CMD ["opentelemetry-instrument", "uvicorn", "agent:app", "--host", "0.0.0.0", "--port", "8080"]
617622
```
618623

624+
### Step 3: Viewing Your Agent's Observability Data
625+
626+
1. Open the CloudWatch console
627+
2. Navigate to the GenAI Observability page
628+
3. Find your agent service
629+
4. View traces, metrics, and logs
630+
619631
### Session ID support
620632

621633
To propagate session ID, you need to invoke using session identifier in the OTEL baggage:
@@ -643,7 +655,7 @@ def invoke_agent(agent_id, payload, session_id=None):
643655
return response
644656
```
645657

646-
#### Common Tracing Headers
658+
Common Tracing Headers Examples:
647659

648660
| Header | Description | Sample Value |
649661
|--------|-------------|-------------|
@@ -654,19 +666,12 @@ def invoke_agent(agent_id, payload, session_id=None):
654666

655667
For more supported headers details, please check [Bedrock AgentCore Runtime Observability Configuration](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability-configure.html)
656668

657-
### Viewing Your Agent's Observability Data
658-
659-
1. Open the CloudWatch console
660-
2. Navigate to the GenAI Observability page
661-
3. Find your agent service
662-
4. View traces, metrics, and logs
663-
664669
### Best Practices
665670

666-
- **Use consistent session IDs** across related requests
667-
- **Set appropriate sampling rates** (1% is default)
668-
- **Monitor key metrics** like latency, error rates, and token usage
669-
- **Set up CloudWatch alarms** for critical thresholds
671+
- Use consistent session IDs across related requests
672+
- Set appropriate sampling rates (1% is default)
673+
- Monitor key metrics like latency, error rates, and token usage
674+
- Set up CloudWatch alarms for critical thresholds
670675

671676
---
672677

0 commit comments

Comments
 (0)