How MediIQ Works

A 9-agent clinical decision-support pipeline that gathers evidence, prescribes intelligently, and catches safety issues before any medicine reaches a patient.

Pipeline Flow

GATHER

Agents 1, 2, 3, 4, 5

Collect patient data, transcript, similar cases, medical evidence, allergy context

PRESCRIBE

Agents 6

Generate a complete prescription from all gathered data

VERIFY

Agents 7, 8

Check drug interactions + allergy safety. Loop back if issues found

DETECT

Agents 9

Find new lifelong meds + allergies, propose to patient

Patient saves profileAgent 1 generates profile summary
Patient clicks LockAgents 3, 4, 5 fire in parallel
Video call endsAgent 2 structures transcript
Agent 2 completesAgent 6 prescribes (using 1+2+3+4+5)
Agent 6 completesAgent 7 checks drugs → Agent 8 checks allergies
Issues found?Loop back to Agent 6 → 7 → 8 (max 2 loops)
Doctor sends prescriptionAgent 9 detects new findings

Example: Diabetic Patient with Fever

Patient Profile

54yo Male, Type 2 Diabetes, Hypertension. Allergy: Penicillin (confirmed severe). Current meds: Metformin 500mg, Amlodipine 5mg.

Booking Symptoms

"Fever, body ache, sore throat" — Duration: 3 days — Severity: Moderate

Agent 3 finds

5 similar URTI cases — dominant treatment: Azithromycin + Paracetamol. NSAIDs consistently avoided in diabetic patients.

Agent 4 retrieves

MedlinePlus: "During infection, diabetic patients may have elevated blood sugar." Red flag: Avoid NSAIDs, avoid penicillin class.

Agent 5 expands

Penicillin → HARD BLOCK: Amoxicillin, Ampicillin, Piperacillin... Cross-reactivity: 1st-gen Cephalosporins.

Agent 6 prescribes

Azithromycin 500mgParacetamol 650mgCetirizine 10mg

Azithromycin chosen over Amoxicillin (penicillin allergy). Paracetamol chosen over Ibuprofen (diabetes + hypertension).

Agent 7 — PASS

0 interactions found. All dosages within approved range.

Agent 8 — PASS

No allergy violations. Azithromycin is NOT in the penicillin class.

What Happens When a Drug is Flagged

1

Agent 6 prescribes Amoxicillin (a penicillin) for a patient with penicillin allergy.

2

Agent 7 catches it: "Amoxicillin is a Penicillin-class drug. HARD BLOCK."

3

Pipeline loops back to Agent 6: "Replace Amoxicillin with a non-penicillin alternative."

4

Agent 6 revises: Azithromycin 500mg (macrolide, safe for penicillin allergy).

5

Doctor sees: Amoxicillin red-marked with the reason, Azithromycin in the clean prescription. Only clean drugs reach the patient.

The 9 Agents

Agent 1 — Patient Summary

Triggered: Profile save

Reads the patient's profile data — age, conditions, allergies, medications — and generates a clinical summary using Gemini. Also builds a running summary from all past consultations, giving the doctor instant context before each visit.

Data Sources

  • • Patient Profile (MongoDB)
  • • Past Appointments
  • • Past AI Consultations

Output

Profile Summary + Running Clinical Summary

Agent 2 — Transcribe

Triggered: Call ends

Takes the raw Agora call transcript and structures it: extracts who said what, identifies symptoms, duration, severity, and every medication mentioned. Each drug name is normalized through RxNorm — so 'Paracetamol' becomes 'acetaminophen' (the universal medical name), and misspellings like 'amoxacillin' get corrected to 'amoxicillin'.

Data Sources

  • • Agora Call Transcript
  • • RxNorm API (NIH)

Output

Structured transcript + RxNorm-normalized drugs

Agent 3 — Similar Cases

Triggered: Lock button

Searches through 100+ past patient cases using hybrid search: semantic vector search (finds cases with similar meaning) combined with keyword matching (exact symptom terms). Boosts cases from patients with matching conditions (e.g., diabetic patients rank higher for a diabetic patient). Then Gemini reranks the top 20 down to the 10 most relevant.

Data Sources

  • • Cases Collection (MongoDB Atlas Vector Search)
  • • Gemini embedding-001 (3072-dim)
  • • Gemini 2.5 Flash (reranking)

Output

Top 10 similar cases + pattern summary

Agent 4 — Medical Context

Triggered: Lock button

Resolves each of the patient's known conditions to an ICD-10 code (first checking a local lookup table of 2,132 conditions, then falling back to the NIH Clinical Tables API). Uses each code to fetch the official MedlinePlus page, then condenses it with Gemini. Also builds 5 targeted search queries and runs them against a knowledge library of 3,347 embedded medical chunks (MedlinePlus conditions + openFDA drug data) to produce an evidence summary.

Data Sources

  • • ConditionLookUp (2,132 ICD-10 codes)
  • • NIH Clinical Tables API
  • • MedlinePlus Connect API
  • • medicalcontexts (3,347 embedded chunks)
  • • Gemini 2.5 Flash

Output

Condition summaries + Evidence summary (findings, diagnoses, red flags)

Agent 5 — Allergy Context

Triggered: Lock button

Expands each of the patient's allergies into a full drug-class avoid list. 'Penicillin allergy' expands to the entire penicillin family — Amoxicillin, Ampicillin, Piperacillin — plus cross-reactivity warnings (1st-gen cephalosporins). Uses a severity/status system: confirmed+severe = absolute block, suspected+mild = monitor. Also queries the knowledge library for safe alternatives.

Data Sources

  • • RxClass API (NIH — drug class expansion)
  • • RxNorm API (drug normalization)
  • • openFDA contraindications (embedded)
  • • Patient Allergy List

Output

Expanded allergy blocks + cross-reactivity flags + safe alternatives

Agent 6 — Reasoning Agent

Triggered: After Agent 2

The prescriber. Takes ALL gathered data — patient summary, transcript, similar cases, medical evidence, allergy context — and generates a complete prescription: diagnosis, medicines (with dosage, timing, frequency, duration, SOS conditions, purpose), 5 advice points, a drug safety note explaining why specific drugs were chosen or avoided, and a history insight.

Data Sources

  • • All outputs from Agents 1-5
  • • Gemini 2.5 Flash / Ollama qwen3:8b (parallel race)

Output

Complete prescription draft

Agent 7 — Drug Medic

Triggered: After Agent 6

First safety gate. Checks every prescribed drug: (1) Is the drug indicated for the diagnosis? — verified against openFDA labels. (2) Is the dosage within approved range? — verified against openFDA dosing data. (3) Drug interactions — every pair of {prescribed drugs + existing medications} is checked against 175,000+ interaction pairs in the DDInter database. Flagged drugs get red-marked; the LLM suggests replacements in one batch call.

Data Sources

  • • DDInter Database (175,201 interaction pairs)
  • • openFDA Drug Label API (live)
  • • Gemini 2.5 Flash (batch verification)

Output

Per-drug verdicts + interaction flags + replacement suggestions

Agent 8 — Allergy Agent

Triggered: After Agent 7

Final safety gate — the most life-critical check. Deterministic, not LLM — pure set-membership lookup. Takes each prescribed drug, resolves its RxCUI via RxNorm, then checks if that RxCUI exists in any of the patient's expanded allergy class sets (from Agent 5). The LLM never decides allergy safety — it only writes the replacement prescription if a violation is found.

Data Sources

  • • RxNorm API (RxCUI resolution)
  • • RxClass API (class membership)
  • • Agent 5's expanded allergy blocks

Output

Allergy verdicts (PASS / HARD_BLOCK / STRONG_CAUTION) + revised prescription

Agent 9 — Finding Detector

Triggered: After prescription sent

The loop closer. Scans the completed consultation for two things: (1) New lifelong medications — drugs prescribed as 'ongoing' or 'daily' that aren't in the patient's record yet. (2) New allergies — drug reactions mentioned in the transcript or drug safety note. Findings are posted to a 'System Detected' box on the patient's profile page. The patient accepts or rejects; on accept, the field updates and Agent 1 refreshes the summary.

Data Sources

  • • Final Prescription
  • • Call Transcript
  • • Patient Profile

Output

Pending findings → patient confirmation → profile update

Datasets & APIs

RxNorm

900,000+ drug concepts

NIH (National Library of Medicine)

Drug name normalization — maps brand names, misspellings, and regional names to canonical identifiers. Free API, no key needed.

Used by: Agent 2 (drug name correction), Agent 5 & 8 (RxCUI lookup)

RxClass

ATC classification system

NIH (National Library of Medicine)

Drug class hierarchy — given a drug, returns its therapeutic class and all sibling drugs. 'Amoxicillin' → 'Penicillins' → [Ampicillin, Piperacillin, ...]

Used by: Agent 5 (allergy expansion), Agent 8 (class-membership check)

openFDA

194 common drugs → 923 chunks

U.S. Food and Drug Administration

Drug labels — indications, dosage, contraindications, warnings, interactions. 194 common drugs embedded with 3072-dim vectors for semantic search.

Used by: Agent 4 (knowledge library), Agent 7 (indication/dose verification)

MedlinePlus

1,016 topics → 2,426 chunks

NIH (National Library of Medicine)

Health condition encyclopedia — 1,016 conditions with symptoms, causes, treatments. Embedded with 3072-dim vectors. Long entries split at question headers.

Used by: Agent 4 (knowledge library), Agent 4 (MedlinePlus Connect for ICD-10 → page)

DDInter 2.0

175,201 interaction pairs

Drug-Drug Interaction Database

175,201 known drug-drug interaction pairs with severity levels (Major, Moderate, Minor). Loaded into MongoDB with compound indexes for sub-millisecond pair lookups.

Used by: Agent 7 (Phase 1 — instant interaction check)

ICD-10 Lookup

2,132 conditions

NIH Clinical Tables + Custom Seed

2,132 condition-to-ICD-10-code mappings. Normalized for exact-match lookup with word-sorted keys. NIH API fallback for misses with safety gate.

Used by: Agent 4 (condition code resolution → MedlinePlus Connect)

Cases (RAG)

100+ cases with embeddings

Seeded + Real Consultations

100 seeded realistic patient cases + every real consultation creates a new case. Each embedded with 3072-dim symptom-only vectors for unbiased retrieval.

Used by: Agent 3 (hybrid vector + keyword search)

MediIQ — AI-Powered Telemedicine Platform

Built with Next.js 16 · MongoDB Atlas · Gemini 2.5 Flash · 9-Agent Pipeline