Skip to content

awsdataarchitect/bedrock-dining-agent

Repository files navigation

🍽️ Bedrock Dining Agent

A sophisticated AI dining assistant built with Amazon Bedrock AgentCore, featuring BrightData MCP integration for real restaurant search and a React frontend with dynamic model selection.

πŸš€ Quick Start (5 Minutes)

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • AWS CLI configured
  • BrightData API token (Get one here)

1. Clone & Setup

git clone https://github.com/awsdataarchitect/bedrock-dining-agent.git
cd agentcore

# Setup Python environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

# Setup environment variables
cp .env.example .env
# Edit .env and add your BRIGHTDATA_API_TOKEN

2. Install Frontend Dependencies

cd bedrock-dining-agent/frontend
npm install
cd ../..

3. Start All Services

# Start backend (port 8080)
python app.py &

# Start frontend (port 3000)
cd bedrock-dining-agent/frontend && npm start &

4. Test It Works

  • Open http://localhost:3000
  • Try: "Find Italian restaurants in San Francisco"
  • Should return real restaurant results

πŸ—οΈ Architecture

Backend (AgentCore)

  • Framework: Amazon Bedrock AgentCore with Strands Agent
  • Models: 5 selectable models (Nova Premier, Nova Micro, Claude Sonnet 4, Claude Opus 4.1, GPT-OSS 120B)
  • MCP Integration: BrightData for real restaurant search
  • Port: 8080

Frontend (React)

  • Framework: React with TypeScript + Tailwind CSS
  • Features: Model selector, restaurant search, dining plans
  • Port: 3000

πŸ”§ Configuration

Required Environment Variables

Create .env file with:

# Required: BrightData MCP API Token
BRIGHTDATA_API_TOKEN=your_brightdata_token_here

# Optional: Frontend URL for CORS (default: http://localhost:3000)
FRONTEND_URL=http://localhost:3000

# Optional: Backend URL for frontend (default: http://localhost:8080)
REACT_APP_API_URL=http://localhost:8080

Available Models

  1. Nova Premier (Default) - Best performance
  2. Nova Micro - Cost-effective
  3. Claude Sonnet 4 - Latest Claude
  4. Claude Opus 4.1 - Most capable Claude
  5. GPT-OSS 120B - Open source option

πŸ› οΈ Development

Running Services

# Backend only
python app.py

# Frontend only
cd bedrock-dining-agent/frontend && npm start

# Both (background)
python app.py & && cd bedrock-dining-agent/frontend && npm start &

API Testing

curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Find Italian restaurants in San Francisco"}'

Available Tools

  1. search_engine - Google search for restaurants
  2. scrape_as_markdown - Extract menu data from websites
  3. create_dining_plan - Generate dining plans with cost estimates

πŸš€ Cloud Deployment

Option 1: Automated (Recommended)

./deploy.sh

Option 2: Manual Steps

# Install AgentCore toolkit
pip install bedrock-agentcore strands-agents bedrock-agentcore-starter-toolkit

# Configure and deploy
agentcore configure -e app.py
agentcore launch

# CRITICAL: Set environment variables
aws bedrock-agentcore-control update-agent-runtime \
  --agent-runtime-id YOUR_AGENT_ID \
  --agent-runtime-artifact 'containerConfiguration={containerUri=YOUR_ECR_URI}' \
  --role-arn YOUR_EXECUTION_ROLE_ARN \
  --network-configuration 'networkMode=PUBLIC' \
  --protocol-configuration 'serverProtocol=HTTP' \
  --environment-variables 'BRIGHTDATA_API_TOKEN=your_token_here'

# Test deployed agent
agentcore invoke '{"prompt": "Find restaurants in Toronto"}'

Testing Cloud Deployment with Frontend

To test the deployed AgentCore runtime with your local frontend:

python cloud_proxy.py &

This starts a proxy server on port 8081 that connects your local frontend to the deployed AgentCore runtime, enabling seamless local-to-cloud testing.

⚠️ Critical Cloud Setup

Environment variables MUST be set at the AgentCore runtime level, NOT in YAML config:

❌ Wrong (doesn't work):

environment:
  BRIGHTDATA_API_TOKEN: "${BRIGHTDATA_API_TOKEN}"

βœ… Correct (required):

aws bedrock-agentcore-control update-agent-runtime --environment-variables 'BRIGHTDATA_API_TOKEN=token'

πŸ”„ Local vs Cloud Testing

The frontend includes a switcher to test both:

  • Local: Uses localhost:8080 backend
  • Cloud: Uses deployed AgentCore runtime via localhost:8081 proxy

Start cloud proxy for testing:

python cloud_proxy.py &

πŸ“ Project Structure

agentcore/
β”œβ”€β”€ app.py                    # Main AgentCore application
β”œβ”€β”€ cloud_proxy.py           # Cloud testing proxy
β”œβ”€β”€ .env                     # Environment variables
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ .bedrock_agentcore.yaml  # AgentCore config will be automatically generated by AgentCore
β”œβ”€β”€ deploy.sh               # Automated deployment
└── bedrock-dining-agent/
    └── frontend/           # React frontend
        β”œβ”€β”€ src/
        └── package.json

πŸ”’ Security

  • Environment variables stored in .env (never committed)
  • CORS configured for frontend URL only
  • No hardcoded API tokens in code
  • Production-ready error handling

🎯 Features

  • βœ… 5 Bedrock models with dynamic switching
  • βœ… Smart tool routing based on user intent
  • βœ… Local and cloud deployment ready
  • βœ… TypeScript frontend with model selector
  • βœ… CAPTCHA-protected web scraping via BrightData MCP Server tools

Deploy: ./deploy.sh | Test: http://localhost:3000 --agent-runtime-id YOUR_AGENT_ID
--agent-runtime-artifact 'containerConfiguration={containerUri=YOUR_ECR_URI}'
--role-arn YOUR_EXECUTION_ROLE_ARN
--network-configuration 'networkMode=PUBLIC'
--protocol-configuration 'serverProtocol=HTTP'
--environment-variables 'BRIGHTDATA_API_TOKEN=your_token_here'


#### Verification:
```bash
# Verify environment variables are set
aws bedrock-agentcore-control get-agent-runtime --agent-runtime-id YOUR_AGENT_ID
# Should show: "environmentVariables": {"BRIGHTDATA_API_TOKEN": "your_token"}

Why This Matters: AgentCore has separate deployment and runtime configuration layers. The YAML file handles deployment settings, but runtime environment variables require a separate AWS CLI call to the runtime API.

πŸš€ Running the Application

Prerequisites

# Copy environment template
cp .env.example .env
# Edit .env with your actual BrightData API token

# Install Python dependencies
source .venv/bin/activate
pip install -r requirements.txt

# Install frontend dependencies
cd bedrock-dining-agent/frontend
npm install

Backend

# Kill any existing backend
pkill -f "python app.py"

# Start local backend in background (port 8080)
cd bedrock-dining-agent
source .venv/bin/activate
python app.py &  # CRITICAL: Always use & for background

Cloud Proxy (Optional)

# Start cloud proxy in background (port 8081)
cd bedrock-dining-agent
source .venv/bin/activate
python cloud_proxy.py &  # CRITICAL: Always use & for background

Frontend

# Kill any existing frontend
pkill -f "npm start"

# Start frontend in background
cd bedrock-dining-agent/frontend
npm start > /dev/null 2>&1 &  # CRITICAL: Always use & for background

Quick Restart All Services

# One-liner to restart everything in background
pkill -f "python app.py" && pkill -f "python cloud_proxy.py" && pkill -f "npm start" && cd agentcore && source .venv/bin/activate && python app.py & && python cloud_proxy.py & && cd bedrock-dining-agent/frontend && npm start > /dev/null 2>&1 &

Access

πŸ”§ API Usage

Restaurant Search

curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Find Italian restaurants in San Francisco", "model_id": "us.amazon.nova-premier-v1:0"}'

Dining Plan Creation

curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Dining plan for Momo Chowmein", "model_id": "us.anthropic.claude-sonnet-4-20250514-v1:0"}'

Expected Response Format

{
  "role": "assistant",
  "content": [{
    "text": "🍝 **Italian Restaurants in San Francisco**\n\n1. **Restaurant Name** - Description\n   - Address: Full address\n   - Rating: X.X⭐\n   - Phone: (XXX) XXX-XXXX\n\n..."
  }]
}

πŸ› οΈ Tools Available using Strands Agent

MCP Tools (BrightData)

  1. search_engine: CAPTCHA-protected Google search for restaurant discovery
  2. scrape_as_markdown: Website content extraction for menu data
  3. create_dining_plan: Smart dining plan creation with auto-menu discovery

Tool Usage Flow

  1. "Find restaurants" β†’ search_engine β†’ Returns search results
  2. "Dining plan for [restaurant]" β†’ create_dining_plan β†’ Auto-finds menu URL β†’ Scrapes menu β†’ Creates plan

πŸ”„ ENDPOINT SWITCHING (PLUG & PLAY)

The frontend supports seamless switching between local and cloud endpoints:

Local Development (Default)

# Frontend .env file
REACT_APP_API_URL=http://localhost:8080

Cloud AgentCore Runtime

# Frontend .env file  
REACT_APP_AGENT_ARN=arn:aws:bedrock-agentcore:us-east-1:YOUR_ACCOUNT_ID:runtime/app-XXXXXXXXXX

Dual Server Architecture

  • Local Backend: localhost:8080 (AgentCore app with MCP integration)
  • Cloud Proxy: localhost:8081 (FastAPI proxy to deployed AgentCore)

UI Switcher

  • Endpoint Switcher Component: Toggle between local/cloud in the UI
  • Real-time switching: No restart required
  • Visual indicators: Shows current endpoint and ARN
  • Status display: Local vs Cloud mode clearly indicated

Usage

  1. Development: Use local endpoint (localhost:8080)
  2. Production: Switch to cloud AgentCore ARN
  3. Testing: Toggle between both for comparison
  4. Deployment: Set environment variables for target endpoint

Bedrock AgentCore Cloud Agent: arn:aws:bedrock-agentcore:us-east-1:YOUR_ACCOUNT_ID:runtime/app-XXXXXXXXXX

πŸ”’ Security Features

  • βœ… Environment Variables: All credentials stored in .env file
  • βœ… No Hardcoded Tokens: BrightData API token from environment
  • βœ… CORS Configuration: Configurable frontend URL
  • βœ… Input Validation: Proper error handling and validation
  • βœ… Production Ready: Clean codebase with no unused dependencies

🎯 Key Features

βœ… Real Data Only

  • Uses actual BrightData search results
  • Scrapes real restaurant menus
  • No mock or generated data

βœ… Smart Model Selection

  • 5 Bedrock models available via dropdown
  • Dynamic agent creation per request
  • Cross-region model support

βœ… Intelligent Tool Routing

  • Context-aware tool selection
  • Proper search β†’ dining plan workflow
  • Auto-menu URL discovery

βœ… Production Ready

  • Environment-based configuration
  • Clean, optimized codebase
  • Comprehensive error handling
  • Ready for AgentCore deployment

πŸ”§ Troubleshooting

Backend Not Available

  • Check if backend is running: ps aux | grep "python app.py"
  • Restart: pkill -f "python app.py" && cd agentcore && source .venv/bin/activate && python app.py &

Frontend Not Loading

  • Check port 3000: lsof -i :3000
  • Restart: pkill -f "npm start" && cd bedrock-dining-agent/frontend && npm start > /dev/null 2>&1 &

Environment Variables

  • Ensure .env file exists with BRIGHTDATA_API_TOKEN
  • Check environment loading: python -c "import os; from dotenv import load_dotenv; load_dotenv(); print(os.getenv('BRIGHTDATA_API_TOKEN'))"

Model Selection Issues

  • Verify model access in Amazon Bedrock console
  • Check model IDs match available models in us-east-1
  • Ensure cross-region inference is enabled

πŸ“Š Performance

  • Response Time: ~2-3 seconds for restaurant search
  • Model Switching: Dynamic per request
  • Real Data: 100% actual search results
  • Scalability: Ready for AgentCore cloud deployment