Skip to content

HamzaNab-Dev/rxagent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

130 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Š RxAgent β€” AI Medication Safety Agent

Your intelligent pharmacist, available 24/7

Live Demo Hackathon Track


Next.js .NET 10 Gemini MongoDB Atlas Tailwind CSS Vercel Railway


🩺 What is RxAgent?

RxAgent is a full-stack AI agent that acts as a personal medication safety assistant. It uses a 5-step reasoning pipeline powered by Google Gemini 2.5 Flash to detect dangerous drug interactions, manage medication schedules, send smart email reminders, and track side effects β€” all through a natural conversational interface.

Built for the Google Cloud Rapid Agent Hackathon on the MongoDB track, RxAgent uses MongoDB Atlas Vector Search, Atlas Search, and aggregation pipelines as core infrastructure for its AI reasoning engine β€” not just as a passive data store.


✨ Features

πŸ’¬ Conversational AI Chat

  • Natural language interface β€” talk to RxAgent like a real pharmacist
  • Multi-turn conversation memory with MongoDB-persisted session history
  • Smart intent detection: interaction check, schedule management, symptom analysis, Q&A
  • Handles typos, brand names ("Panadol"), vague descriptions ("my blood thinner"), and casual phrasing ("my tummy hurts after my pill")

βš—οΈ Drug Interaction Checker

  • 5-step AI agent reasoning pipeline with a transparent thinking panel
  • Severity scoring: Safe β†’ Mild β†’ Moderate β†’ Severe β†’ Critical
  • 150+ brand-to-generic name mappings (Panadol β†’ Acetaminophen, Levar β†’ Levetiracetam, etc.)
  • Checks every pairwise combination for 3+ medications simultaneously
  • Powered by MongoDB Atlas Vector Search across 256 curated drug interaction records (antibiotics, cardiac, diabetes, mental health, pain, immunosuppressants & more)
  • Same-drug deduplication: Panadol + Acetaminophen = one drug, not a flagged interaction

πŸ“… Medication Schedule Manager

  • AI-generated optimal daily schedule using standard pharmacological guidelines
  • Add, edit, and remove medications via natural conversation
  • Per-medication dosage, timing, and instruction management

πŸ“§ Smart Email Reminder System

  • 3-email flow: advance notice β†’ dose-time alert β†’ final reminder
  • Mark as Taken directly from the email β€” no app login required
  • Dashboard syncs instantly when a dose is confirmed via email
  • Per-medication reminder settings (enable or disable individually)
  • Timezone-aware β€” works correctly for users worldwide

πŸ“Š Due Today Dashboard

  • Real-time dose tracking for the current day
  • Status tracking: βœ… Taken / ⚠️ Missed / πŸ”” Due Now / πŸ• Upcoming / ⏭️ Skipped
  • Grouped by time slot for an at-a-glance overview

🩻 Side Effect Tracker

  • Log symptoms naturally from the chat ("I feel dizzy after Metformin")
  • Agent recognises symptom mentions and prompts logging contextually
  • AI-powered assessment links symptoms to suspected medications
  • Full history with severity flags and monitoring status

πŸ‘¨β€πŸ‘©β€πŸ‘§ Caregiver Mode

  • Manage medications for multiple family members from one account
  • Switch between profiles instantly
  • Each profile has independent medication schedule, side effects, and chat history
  • Perfect for elderly parents, children, or anyone who needs medication oversight

πŸƒ MongoDB Integration

MongoDB Atlas is used as a core part of the AI agent's reasoning pipeline β€” not just as a data store.

Feature MongoDB Capability
Drug interaction lookup Atlas Vector Search β€” semantic similarity across interaction database
Medication name autocomplete Atlas Search β€” real-time prefix search across 10,000+ drug names
Usage analytics & stats Aggregation Pipelines β€” per-user totals across medications, sessions, side effects
Dose status tracking Embedded documents β€” taken/missed/skipped state stored per day per entry
AI agent tooling MongoDB MCP Server β€” agent introspects live database state during reasoning
All user data Collections β€” schedules, sideEffectLogs, chatSessions, users, interactions

Collections

rxagent/
β”œβ”€β”€ interactions       β€” 256 curated drug interaction pairs (vector-indexed)
β”œβ”€β”€ schedules          β€” medication entries with dose times and reminder settings
β”œβ”€β”€ sideEffectLogs     β€” logged symptoms with AI assessment and suspected medications
β”œβ”€β”€ chatSessions       β€” persistent conversation history per user
β”œβ”€β”€ users              β€” authentication, profile, timezone
└── doseTracking       β€” daily taken/missed/skipped status per medication

256 curated drug interaction records:

  • 12 Critical
  • 84 Severe
  • 119 Moderate
  • 15 Mild
  • 26 Safe combinations

Vector Search

Drug interactions are stored with semantic embeddings. When the agent checks "Is Warfarin safe with Aspirin?", it uses $vectorSearch to retrieve the most semantically relevant interaction records β€” enabling fuzzy, meaning-aware matching rather than brittle exact-string lookup.

MCP Server

RxAgent integrates the MongoDB MCP Server, giving the AI agent direct read access to live database state during reasoning. This enables context-aware responses grounded in the patient's actual current schedule.

Why MongoDB β€” Not Just Storage

Most apps use MongoDB as a dumb key-value store. RxAgent uses it as an active part of the AI pipeline:

  • Vector Search drives the interaction lookup
  • MCP Server lets the agent query live patient data
  • Aggregations power the analytics dashboard
  • Embedded documents track daily dose history

πŸ€– How the Agent Works

RxAgent uses a deterministic 5-step reasoning pipeline for drug interaction analysis:

User: "I take Warfarin, Aspirin, and Metformin β€” are these safe together?"

Step 1 β†’ PARSE      Resolve brand names Β· deduplicate Β· extract known drugs
Step 2 β†’ SEARCH     Vector search MongoDB interactions database for each drug pair
Step 3 β†’ REASON     Gemini 2.5 Flash analyses every combination with patient context
Step 4 β†’ ASSESS     Severity scoring: Safe / Mild / Moderate / Severe / Critical
Step 5 β†’ RESPOND    Structured response with severity badge + per-pair breakdown

For general questions and symptom queries, a separate prompt pipeline routes between:

  • TYPE A β€” symptom/conversational β†’ empathetic 2-3 sentence response with a follow-up question
  • TYPE B β€” factual/informational β†’ structured bullet-point format

Intent is classified in C# before reaching the AI β€” minimising unnecessary Gemini calls and keeping latency low.


πŸ–ΌοΈ Screenshots

Chat + Interaction Check Email Reminder Due Today Dashboard
Chat Email Due Today
Schedule Manager Side Effect Tracker Agent Thinking Panel
Schedule Side Effects Agent Thinking

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Next.js 14      β”‚         β”‚  ASP.NET Core 10 Web API                β”‚
β”‚  Tailwind CSS    β”‚ ◄─────► β”‚                                        β”‚
β”‚  Vercel          β”‚         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚  β”‚MedicationAgentβ”‚  β”‚ GeminiService  β”‚  β”‚
                              β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                              β”‚         β”‚                   β”‚           β”‚
                              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”  β”‚
                              β”‚  β”‚          MongoDB Atlas            β”‚  β”‚
                              β”‚  β”‚  Vector Search Β· Atlas Search    β”‚  β”‚
                              β”‚  β”‚  Aggregations Β· MCP Server       β”‚  β”‚
                              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                              β”‚                                        β”‚
                              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
                              β”‚  β”‚      Gmail SMTP (Reminders)    β”‚   β”‚
                              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

1. Clone the repository

git clone https://github.com/HamzaNab-Dev/rxagent.git
cd rxagent

2. Configure the API

cd RxAgent.Api

Create appsettings.Development.json (gitignored β€” never commit this file):

{
  "MongoDB": {
    "ConnectionString": "mongodb+srv://<user>:<password>@<cluster>.mongodb.net",
    "DatabaseName": "rxagent"
  },
  "Gemini": {
    "ApiKey": "your-gemini-api-key",
    "Model": "gemini-2.5-flash"
  },
  "Jwt": {
    "Secret": "your-jwt-secret-minimum-32-characters",
    "Issuer": "RxAgent",
    "Audience": "RxAgent"
  },
  "Email": {
    "SmtpHost": "smtp.gmail.com",
    "SmtpPort": 587,
    "From": "your-email@gmail.com",
    "Password": "your-gmail-app-password"
  },
  "AllowedOrigin": "http://localhost:3000"
}

3. Run the API

dotnet run --project RxAgent.Api
# API available at http://localhost:5122

4. Seed the drug interaction database

# Seed interactions (includes vector embeddings β€” takes ~2 min on first run)
curl -X POST http://localhost:5122/api/dataseed/interactions

5. Configure the frontend

cd rxagent-web

Create .env.local:

NEXT_PUBLIC_API_URL=http://localhost:5122

6. Run the frontend

npm install
npm run dev
# App available at http://localhost:3000

πŸ” Environment Variables

API β€” RxAgent.Api/appsettings.Development.json

Key Description
MongoDB:ConnectionString MongoDB Atlas connection string
MongoDB:DatabaseName Database name (default: rxagent)
Gemini:ApiKey Google Gemini API key
Gemini:Model Model ID (e.g. gemini-2.5-flash)
Jwt:Secret JWT signing secret (minimum 32 characters)
Jwt:Issuer JWT issuer (default: RxAgent)
Jwt:Audience JWT audience (default: RxAgent)
Email:SmtpHost SMTP host (e.g. smtp.gmail.com)
Email:SmtpPort SMTP port (e.g. 587)
Email:From Sender email address
Email:Password Gmail App Password
AllowedOrigin Frontend URL for CORS

Frontend β€” rxagent-web/.env.local

Key Description
NEXT_PUBLIC_API_URL Backend API base URL

⚠️ Disclaimer

RxAgent is a hackathon project for informational and educational purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment. Always consult your doctor or pharmacist before making any medication decisions.


πŸ“„ License

MIT License β€” see LICENSE for details.


Built with ❀️ for the Google Cloud Rapid Agent Hackathon · MongoDB Track

Hamza Maher Nabelsi

🌐 Live Demo Β· πŸ“ GitHub

About

AI-powered medication management agent built with Gemini, MongoDB, and Google Cloud Agent Builder

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages