Skip to content

codelights/chat_mcp1

Repository files navigation

Obsessive AI Assistant

A full-stack, serverless web application featuring an AI agent obsessed with weather, calculations, and synonyms. The agent uses AWS Strands to automatically orchestrate between multiple tools, demonstrating spontaneous tool selection and creative conversation flow.

Project Structure

.
├── backend/
│   ├── src/
│   │   ├── app.py          # Lambda function implementation
│   │   └── requirements.txt # Python dependencies
│   └── template.yaml       # SAM template for deployment
├── frontend/
│   └── index.html         # Web interface
└── tests/
    └── test_app.py        # Unit tests

Backend

The backend is implemented as an AWS Lambda function using:

  • Python 3.11
  • AWS Strands Agents SDK (tool orchestration)
  • Amazon Bedrock (Claude 3 Sonnet)
  • Three integrated tools:
    • Thesaurus Tool: Datamuse API for synonyms
    • Calculator Tool: Built-in Strands mathematical calculations
    • Weather Tool: OpenWeatherMap API with authentication
  • AWS SAM for deployment

Deployment

  1. Install AWS SAM CLI
  2. Configure AWS credentials
  3. Get an OpenWeatherMap API key from https://openweathermap.org/api
  4. Build and deploy:
cd backend
sam build
sam deploy --guided --parameter-overrides OpenWeatherApiKey=YOUR_API_KEY

Environment Variables

The following environment variables must be configured:

  • BEDROCK_MODEL_ID: The Bedrock model identifier
  • OPENWEATHER_API_KEY: API key for OpenWeatherMap service

Frontend

A single-page web application built with:

  • HTML5
  • Tailwind CSS
  • Vanilla JavaScript

Setup

  1. Update the API_ENDPOINT variable in index.html with your deployed API Gateway URL
  2. Host the frontend files on your preferred static hosting service (e.g., S3, CloudFront)

Agent Behavior

The obsessive agent demonstrates:

  • Automatic tool selection: Chooses tools based on conversational context
  • Creative connections: Relates any topic to weather, math, or word choices
  • Tool chaining: Combines multiple tools in single responses
  • Personality-driven interactions: Enthusiastic and obsessive responses

Example Interactions

Input: "My cat seems sad today"
Output: "You know, cats can sense barometric pressure! [uses weather tool] It's currently 29.8 inches and falling - that's a 3.2% drop [uses calculator] since yesterday which might explain your cat's mood! Speaking of moods, let me find some synonyms... [uses thesaurus] melancholy, dejected, downcast!"

Input: "I need help with my budget"
Output: "Budget calculations! [uses calculator] But speaking of budgets, did you know it's 23°F outside? [uses weather tool] That's quite frigid - or should I say glacial, icy, arctic! [uses thesaurus] Budgeting for heating costs is crucial!"

Testing

Run the unit tests:

pytest tests/

Test the Datamuse API functionality directly:

python tests/test_datamuse.py

Security

  • CORS-enabled API endpoint
  • Input validation and error handling

API

The backend exposes a single endpoint that accepts POST requests:

POST /query
Content-Type: application/json

{
    "query": "user's natural language text"
}

Response format:

{
    "response": "Obsessive AI response with automatic tool usage"
}

Tool Integration Patterns

1. Thesaurus Tool (Custom API)

Uses the Datamuse API for synonym lookup:

  • /words?ml={word} - Find words with similar meaning
  • /words?rel_syn={word} - Find synonyms
  • Free to use, no authentication required

2. Calculator Tool (Built-in Strands)

Leverages the built-in Strands calculator tool for mathematical operations.

3. Weather Tool (External API with Auth)

Integrates with OpenWeatherMap API:

  • Current weather conditions
  • Temperature, humidity, pressure
  • Requires API key authentication
  • Demonstrates error handling and location parsing

Reconstruction / Installation Process

git clone

chmod +x scripts/setup.sh && ./scripts/setup.sh

Copy real credentials to local/.aws/credentials

export AWS_SHARED_CREDENTIALS_FILE=./local/.aws/credentials

Everything stays in the project folder.

About

Step 2: AWS Strands agents with MCP server integration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published