Skip to content

Commit b31eacd

Browse files
sattensilmtocci-ld
andauthored
Aws integration pr (#18)
Implemented support for AWS Bedrock model catalog for both embedding and gp. The approach enables backwards compatibility with the api key approach for Anthropic and OpenAI, which allows the user to follow the tutorial instructions without modification. Co-authored-by: Mike Tocci <[email protected]>
1 parent 405350e commit b31eacd

16 files changed

+1239
-150
lines changed

.env.example

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,31 @@
33
LD_SDK_KEY=your_launchdarkly_sdk_key_here
44
LD_API_KEY="your key here"
55

6-
# AI Model API Keys
6+
# ============================================
7+
# Authentication Method Selection
8+
# ============================================
9+
10+
# Choose authentication method: "sso" or "api-key"
11+
# AUTH_METHOD=sso # Use Bedrock via AWS SSO
12+
AUTH_METHOD=api-key # Default: backward compatible with direct API keys
13+
14+
# ============================================
15+
# SSO Configuration (when AUTH_METHOD=sso)
16+
# ============================================
17+
18+
AWS_REGION=us-east-1
19+
AWS_PROFILE=your-sso-profile-name # Your AWS SSO profile name
20+
21+
# Bedrock Inference Profile Region (optional)
22+
# Controls the region prefix for auto-corrected model IDs
23+
# If not set, automatically derived from AWS_REGION (e.g., us-east-1 → us)
24+
# Options: us, eu, ap, ca, sa, af, me
25+
# BEDROCK_INFERENCE_REGION=us # Default: auto-detected from AWS_REGION
26+
27+
# ============================================
28+
# API Key Configuration (when AUTH_METHOD=api-key)
29+
# ============================================
30+
731
# Get your Anthropic API key from: https://console.anthropic.com/
832
ANTHROPIC_API_KEY=your_anthropic_api_key_here
933

@@ -13,6 +37,14 @@ OPENAI_API_KEY=your_openai_api_key_here
1337
# Get your Mistral API key from: https://console.mistral.ai/
1438
MISTRAL_API_KEY=your_mistral_api_key_here
1539

40+
# ============================================
41+
# Provider-Specific Configuration
42+
# ============================================
43+
44+
# Bedrock Embedding Configuration (when using Bedrock embeddings)
45+
BEDROCK_EMBEDDING_DIMENSIONS=1024 # Options: 256, 512, 1024
46+
BEDROCK_EMBEDDING_MODEL=amazon.titan-embed-text-v2:0
47+
1648
# Optional: MCP Tool Configuration
1749
# These are used for advanced research capabilities (leave blank if not using MCP tools)
1850
ARXIV_MCP_SERVER_PATH=/Users/your_username/.local/bin/arxiv-mcp-server
@@ -39,10 +71,15 @@ UI_PORT=8501
3971

4072
# Vector Store Configuration
4173
VECTOR_STORE_PATH=data/vector_store/
42-
EMBEDDING_MODEL=text-embedding-3-small
74+
EMBEDDING_MODEL=amazon.titan-embed-text-v2:0 # Bedrock Titan V2
75+
# EMBEDDING_MODEL=text-embedding-3-small # Default: OpenAI (backward compatible)
4376
CHUNK_SIZE=1000
4477
CHUNK_OVERLAP=200
4578

79+
# Optional: Override embedding provider auto-detection
80+
# EMBEDDING_PROVIDER=bedrock # Force Bedrock embeddings
81+
# EMBEDDING_PROVIDER=openai # Force OpenAI embeddings (requires OPENAI_API_KEY)
82+
4683
# Development Mode
4784
DEBUG=true
4885
LOG_LEVEL=INFO

.gitignore

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@ __pycache__/
33
*.pyo
44
*.pyd
55
.Python
6+
*.py[cod]
7+
*$py.class
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# Virtual environments
29+
.venv/
30+
venv/
31+
ENV/
32+
env/
33+
.virtualenv
634

735
# macOS
836
.DS_Store
@@ -36,9 +64,18 @@ test_tutorial_2.py
3664
test_tools_loading.py
3765
data/mythical_pets_kb.py
3866

67+
# Vector store data (generated artifacts)
68+
data/vector_store/documents.pkl
69+
data/vector_store/faiss.index
70+
3971
# Project files
4072
.claude
4173
CLAUDE.md
4274

4375
# Development posts
44-
dev_posts/
76+
dev_posts/
77+
78+
# Temporary LaunchDarkly development files (analysis, tests, helpers)
79+
ld_temp_*
80+
.specify/
81+
specs/

README.md

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ You'll need:
3333

3434
- **Python 3.9+** with `uv` package manager ([install uv](https://docs.astral.sh/uv/getting-started/installation/))
3535
- **LaunchDarkly account** ([sign up for free](https://app.launchdarkly.com/signup))
36+
37+
**Choose your AI provider setup:**
38+
39+
**Option A: AWS Bedrock (Recommended)**
40+
- **AWS Account** with Bedrock access and SSO configured
41+
- **No API keys required** - uses AWS SSO authentication
42+
- **Cost-effective** - enterprise-grade with cross-region failover
43+
44+
**Option B: Direct API Keys (Traditional)**
3645
- **OpenAI API key** (required for RAG architecture embeddings)
37-
- **Anthropic API key** (required for Claude models) or **OpenAI API key** (for GPT models)
46+
- **Anthropic API key** (for Claude models) or **OpenAI API key** (for GPT models)
3847

3948
## Step 1: Clone and Configure (2 minutes)
4049

@@ -103,15 +112,106 @@ First, you need to get your LaunchDarkly SDK key by creating a project:
103112

104113
</div>
105114

106-
Now edit `.env` with your keys:
115+
Now configure your authentication method in `.env`:
116+
117+
### Option A: AWS Bedrock Setup (Recommended)
118+
119+
```bash
120+
# LaunchDarkly Configuration
121+
LD_SDK_KEY=your-launchdarkly-sdk-key # From step above
122+
123+
# AWS Bedrock Configuration
124+
AUTH_METHOD=sso # Use AWS SSO authentication
125+
AWS_REGION=us-east-1 # Your AWS region
126+
AWS_PROFILE=your-sso-profile-name # Your AWS SSO profile name
127+
128+
# Optional: Bedrock Embedding Configuration
129+
BEDROCK_EMBEDDING_DIMENSIONS=1024 # Options: 256, 512, 1024
130+
BEDROCK_EMBEDDING_MODEL=amazon.titan-embed-text-v2:0
131+
```
132+
133+
**Then configure AWS SSO:**
134+
```bash
135+
# Configure AWS SSO (one-time setup)
136+
aws configure sso --profile your-sso-profile-name
137+
138+
# Login to AWS SSO (run when token expires)
139+
aws sso login --profile your-sso-profile-name
140+
141+
# Test your access
142+
aws bedrock list-foundation-models --region us-east-1 --profile your-sso-profile-name
143+
```
144+
145+
### Option B: Direct API Keys Setup
146+
107147
```bash
148+
# LaunchDarkly Configuration
108149
LD_SDK_KEY=your-launchdarkly-sdk-key # From step above
150+
151+
# Direct API Configuration
152+
AUTH_METHOD=api-key # Use direct API keys (default)
109153
OPENAI_API_KEY=your-openai-key # Required for RAG embeddings
110154
ANTHROPIC_API_KEY=your-anthropic-key # Required for Claude models
111155
```
112156

113157
This sets up a **LangGraph** application that uses LaunchDarkly to control AI behavior. Think of it like swapping actors, directors, even props mid-performance without stopping the show.
114-
Do not check the `.env` into your source control. Keep those secrets safe!
158+
159+
**Security Note:** Do not check the `.env` into your source control. Keep those secrets safe!
160+
161+
### 🚨 **Common AWS SSO Issue:**
162+
163+
If you get `AccessDeniedException` errors, verify your Python code is using the correct AWS profile:
164+
165+
```bash
166+
# Check which AWS account your profile uses
167+
aws sts get-caller-identity --profile your-sso-profile-name
168+
169+
# If the account numbers don't match your error message, add AWS_PROFILE to your .env
170+
```
171+
172+
**The error message will show the account number your Python code is using.** Make sure it matches your SSO profile account.
173+
174+
### 🚨 **Bedrock Model ID Requirements:**
175+
176+
When configuring AI models in LaunchDarkly for Bedrock, you should use **inference profile IDs** (with region prefix):
177+
178+
**✅ BEST PRACTICE - Inference Profile IDs (with region prefix):**
179+
```
180+
us.anthropic.claude-3-5-sonnet-20241022-v2:0
181+
us.anthropic.claude-3-7-sonnet-20250219-v1:0
182+
eu.anthropic.claude-3-5-haiku-20241022-v2:0
183+
```
184+
185+
**⚠️ AUTO-CORRECTED - Direct Model IDs (will be fixed automatically):**
186+
```
187+
anthropic.claude-3-7-sonnet-20250219-v1:0 → us.anthropic.claude-3-7-sonnet-20250219-v1:0
188+
anthropic.claude-3-5-sonnet-20241022-v2:0 → us.anthropic.claude-3-5-sonnet-20241022-v2:0
189+
```
190+
191+
**How Auto-Correction Works:**
192+
193+
The system automatically converts direct model IDs to inference profile IDs to prevent `ValidationException` errors from Bedrock. The region prefix is determined by:
194+
195+
1. **`BEDROCK_INFERENCE_REGION`** env var (if set) - explicit user preference
196+
2. **`AWS_REGION`** env var (e.g., `us-east-1``us` prefix) - automatic detection
197+
3. **Default to `us`** if neither is set
198+
199+
**Configuring Region Prefix:**
200+
201+
To use European inference profiles, add to your `.env`:
202+
```bash
203+
BEDROCK_INFERENCE_REGION=eu # Force EU inference profiles
204+
```
205+
206+
**Finding Available Inference Profiles:**
207+
```bash
208+
# List available Bedrock inference profiles
209+
aws bedrock list-inference-profiles --region us-east-1 --profile your-sso-profile-name
210+
```
211+
212+
**Why Inference Profiles?**
213+
214+
Bedrock requires inference profile IDs for on-demand throughput. The region prefix (`us.`, `eu.`, `ap.`, etc.) enables cross-region inference profiles for better availability and failover.
115215

116216
## Step 2: Add Your Business Knowledge (2 minutes)
117217

@@ -141,7 +241,12 @@ Turn your documents into searchable **RAG** knowledge:
141241
uv run python initialize_embeddings.py --force
142242
```
143243

144-
This builds your **RAG** (Retrieval-Augmented Generation) foundation using **OpenAI's** text-embedding model and FAISS vector database. **RAG** converts documents into vector embeddings that capture semantic meaning rather than just keywords, making search actually understand context.
244+
This builds your **RAG** (Retrieval-Augmented Generation) foundation using FAISS vector database. The system automatically detects your authentication method:
245+
246+
- **AWS Bedrock**: Uses Amazon Titan V2 embeddings (1024 dimensions by default)
247+
- **Direct API Keys**: Uses OpenAI text-embedding-3-small (1536 dimensions)
248+
249+
**RAG** converts documents into vector embeddings that capture semantic meaning rather than just keywords, making search actually understand context.
145250

146251
## Step 4: Define Your Tools (3 minutes)
147252

@@ -232,7 +337,7 @@ The `reranking` tool takes search results from `search_v2` and reorders them usi
232337
233338
> **🔍 How Your RAG Architecture Works**
234339
>
235-
> Your **RAG** system works in two stages: `search_v2` performs semantic similarity search using FAISS by converting queries into the same vector space as your documents (via **OpenAI** embeddings), while `reranking` reorders results for maximum relevance. This **RAG** approach significantly outperforms keyword search by understanding context, so asking "My app is broken" can find troubleshooting guides that mention "application errors" or "system failures."
340+
> Your **RAG** system works in two stages: `search_v2` performs semantic similarity search using FAISS by converting queries into the same vector space as your documents (via **OpenAI** or **Bedrock Titan** embeddings), while `reranking` reorders results for maximum relevance. This **RAG** approach significantly outperforms keyword search by understanding context, so asking "My app is broken" can find troubleshooting guides that mention "application errors" or "system failures."
236341
237342
## Step 5: Create Your AI Agents in LaunchDarkly (5 minutes)
238343
@@ -255,20 +360,25 @@ Create LaunchDarkly AI Configs to control your **LangGraph** multi-agent system
255360
3. Name it `supervisor-agent`
256361
4. Add this configuration:
257362
258-
>
259-
> **variation:**
363+
>
364+
> **variation:**
260365
> ```
261366
> supervisor-basic
262367
> ```
263368
>
264-
> **Model configuration:**
369+
> **Model configuration:**
265370
> ```
266371
> Anthropic
267-
> ```
372+
> ```
268373
> ```
269374
> claude-3-7-sonnet-latest
270375
> ```
271376
>
377+
> **Note for Bedrock users:** The system auto-corrects direct model IDs to inference profiles:
378+
> - Use either `claude-3-7-sonnet-latest` (auto-corrected) or `us.anthropic.claude-3-7-sonnet-20250219-v1:0` (explicit)
379+
> - Control region prefix via `BEDROCK_INFERENCE_REGION` env var (defaults to `us`)
380+
> - See "Bedrock Model ID Requirements" section above for details
381+
>
272382
> **Goal or task:**
273383
> ```
274384
> You are an intelligent routing supervisor for a multi-agent system. Your primary job is to assess whether user input likely contains PII (personally identifiable information) to determine the most efficient processing route.

0 commit comments

Comments
 (0)