Skip to content

MAMA – Maternal Artificial Multi-step Assistant for malaria in pregnancy in Nigeria

License

Notifications You must be signed in to change notification settings

obooks29/mama-agent-hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAMA – Maternal Artificial Multi-agent Assistant

Clinical AI for Nigerian community health workers — powered by Elasticsearch

MAMA Banner

Built for the Elasticsearch Agent Builder Hackathon 2026


The Stakes

A misdiagnosis at 12 weeks gestation — prescribing Artemether-Lumefantrine instead of Quinine — can cause fetal harm. MAMA catches this. Every time.


Problem

  • Nigeria accounts for 27% of the global malaria burden
  • Pregnant women are the most vulnerable; fever could be malaria, UTI, or respiratory infection — symptoms overlap, treatments differ, and a wrong call harms two lives
  • Community health workers operate at a 1:10,000 ratio with no decision support
  • Supply chains are unreliable, with disruption rates as high as 50% in some regions (e.g., Yobe, North East)
  • Current diagnostic models exist in research papers — not in the hands of the people who need them

Solution – "Triangle of Reasoning" with Adversarial Internal Review

MAMA orchestrates four roles within a single agent (Gemini 1.5 Pro) using Elasticsearch Agent Builder:

Role Function Tool Used
Analyst Assesses regional malaria burden and supply disruption rate get_malaria_trends
Clinician Matches symptoms to disease using trimester-specific protocols Built-in knowledge
Logistician Verifies local drug availability and flags stock alerts check_pharmacy_inventory
Dr. Verify Adversarially reviews the draft — always raises at least one challenge Self-critique

The agent follows a 4-phase workflow:

  1. Analyze — call both tools to get regional epidemiological and pharmacy context
  2. Diagnose — apply trimester-specific clinical protocols
  3. Draft — form a preliminary recommendation
  4. Review — step into the Dr. Verify persona, find a flaw, challenge it, then respond with a final defended plan

The result is a fully transparent, self-auditing clinical agent that never lets a recommendation through unchallenged.


Why This Matters

Metric Value
Records analyzed 29,524 authentic malaria records (2015–2025)
Geopolitical zones covered 6 (all of Nigeria)
Diagnosis time Reduced from ~45 minutes to under 2 minutes
Safety checks 100% — every recommendation reviewed before output
Supply chain awareness Real-time disruption rate calculated per region

Live Example

Query:

Pregnant woman in Yobe, 14 weeks gestation, fever 38.5°C, chills, headache.

MAMA's Response:

🔍 Regional Risk Analysis

State: Yobe (North East)
Average malaria burden: 58.5 cases/month
Supply disruption rate: 50%
Risk level: CRITICAL (>30%)

⚠️ CRITICAL ALERT: Yobe is experiencing severe supply chain stress. Advise the patient to obtain the full treatment course immediately — restocking may be significantly delayed.

🏥 Primary Diagnosis

Malaria in Pregnancy (95% confidence)

Reasoning: Classic triad of fever (38.5°C), chills, and headache in a high-burden
region (58.5 cases/month) strongly indicates malaria. Yobe in the North East zone
has endemic malaria transmission.

Differential diagnoses considered:
- UTI (ruled out — no dysuria reported)
- Respiratory infection (ruled out — no cough or respiratory symptoms)
- Typhoid fever (possible but less likely given symptom pattern)

⚠️ Safety Review

Patient trimester: 2nd trimester (14 weeks gestation)
Contraindications checked: ✅ VERIFIED

Initial consideration: Patient just entered 2nd trimester at exactly 14 weeks
Final recommendation: Artemether-Lumefantrine (AL) — SAFE to use
Change reason: At 14 weeks, the 1st trimester contraindication no longer applies.
AL is the WHO-recommended first-line therapy for 2nd/3rd trimester.

💊 Recommended Treatment

Primary drug: Artemether-Lumefantrine (AL)
Dosage: 4 tablets initially, then 4 tablets at 8 hours, then 4 tablets twice
        daily (morning and evening) on days 2 and 3
Duration: 3 days (6-dose regimen)
Administration: Oral, with food or milk to enhance absorption

Secondary measures:
- Paracetamol 500–1000 mg every 6–8 hours for fever control
- Adequate hydration (at least 2–3 litres of fluids daily)
- Bed rest during acute phase
- IPTp-SP initiated at next antenatal visit — every 4 weeks thereafter

📦 Stock Status

Artemether-Lumefantrine (AL): 150 units — IN STOCK ✅
Quinine: 25 units — LOW STOCK ⚠️
Nitrofurantoin: 5 units — CRITICAL LOW ❌

Total drugs tracked: 3
Alert level: WARNING

Dispense the full 3-day course immediately. Do not split the prescription given the 50% supply disruption rate.

🔄 Review Notes (Dr. Verify)

Verdict: ✅ CONCUR — with challenge resolved

Challenge raised: "Given the 50% supply disruption rate in Yobe, why is AL
preferred over Quinine? What if AL stock depletes before the patient returns?"

MAMA's response: AL currently has 150 units in stock — sufficient for multiple
patients. Quinine at 25 units is the lower-stock drug. The recommendation to
dispense the complete course immediately directly addresses the restocking risk.
AL is also preferred for compliance (3-day vs 7-day course with Quinine),
which matters in a high-disruption environment.

What changed: Strengthened the dispensing urgency warning — patient must
receive all 6 doses before leaving the facility.

Final verdict: Recommendation withstood adversarial review.

📅 Follow-Up Plan

Next clinical check: 48–72 hours (Day 3–4 after treatment initiation)

Warning signs requiring URGENT return:
- Persistent high fever after 48 hours
- Severe headache, confusion, or seizures
- Difficulty breathing or chest pain
- Persistent vomiting (unable to keep medication down)
- Dark/cola-coloured urine
- Reduced fetal movements
- Vaginal bleeding

Expected improvement:
- Fever should subside within 24–48 hours
- Chills and headache should improve by Day 2–3

⚠️ CRITICAL: Patient MUST complete all 6 doses over 3 days even if feeling better.

Architecture

User Query (Health Worker)
         │
         ▼
   ┌─────────────┐
   │    MAMA     │  ← Elastic Agent Builder (Gemini 1.5 Pro)
   │   Agent     │
   └─────┬───────┘
         │
   ┌─────┴──────────────────────────┐
   │                                │
   ▼                                ▼
get_malaria_trends          check_pharmacy_inventory
(ES|QL Tool)                     (ES|QL Tool)
   │                                │
   ▼                                ▼
nigeria_malaria_pregnancy    pharmacy_inventory
(29,524 records)             (18 facilities)
         │
         ▼
   ┌─────────────┐
   │  Dr. Verify │  ← Adversarial internal review (prompt engineering)
   │  (Persona)  │
   └─────┬───────┘
         │
         ▼
  Final Verified Recommendation

Elasticsearch Features Used

  • ES|QL with TO_INTEGER, CASE, and STATS for conditional disruption calculations and dynamic stock alerts
  • Two custom ES|QL tools:
    • get_malaria_trends — time-series aggregation + disruption rate calculation across 10 years
    • check_pharmacy_inventory — stock levels with dynamic OK / WARNING / URGENT alert logic
  • 29,524 authentic records spanning 2015–2025 across 6 Nigerian states
  • Geo-aware querying — all 6 states mapped to geopolitical zones with regional context
  • Adversarial internal review — implemented via advanced prompt engineering, demonstrating multi-step reasoning within a single agent
  • Elastic Managed LLM — Gemini 1.5 Pro via pre-configured Vertex AI connector (zero setup)

Data Sources

Dataset Source Records
Malaria in Pregnancy Nigeria 2015–2025 Figshare DOI: 10.6084/m9.figshare.29145854 29,524
Clinical Guidelines Synthetic — based on WHO 2015 Malaria in Pregnancy guidelines and Nigeria's 2022 National Malaria Elimination Programme protocols 6 records
Pharmacy Inventory Synthetic stock data for 18 facilities across 6 states 18 records

All datasets are included in the /data folder of this repository.


Repository Structure

mama/
├── agent/
│   └── instructions.md          # Full MAMA agent instructions
├── data/
│   ├── nigeria_malaria_pregnancy.csv
│   ├── clinical_guidelines_updated.csv
│   └── pharmacy_inventory_updated.csv
├── queries/
│   ├── get_malaria_trends.esql
│   └── check_pharmacy_inventory.esql
├── docs/
│   └── mama_banner.png
├── README.md
└── LICENSE

Setup Instructions

Prerequisites

  • An Elastic Cloud Serverless account (Newton 9.3+)
  • Access to Elastic Agent Builder
  • Gemini 1.5 Pro connector configured in Kibana

Step 0 — Generate an API Key

In Kibana: Stack Management → API Keys → Create API key Select Unrestricted permissions. Store it securely — never share it publicly.

Step 1 — Upload the Data

Use Kibana Data Visualizer to upload the three CSV files from /data into these indices:

  • nigeria_malaria_pregnancy
  • clinical_guidelines
  • pharmacy_inventory

Step 2 — Create the ES|QL Tools

In Agent Builder, create two tools of type ES|QL:

  • get_malaria_trends — use the query from /queries/get_malaria_trends.esql
  • check_pharmacy_inventory — use the query from /queries/check_pharmacy_inventory.esql

Step 3 — Create the Agent

  • Create a new agent with the Gemini 1.5 Pro model
  • Assign both tools to the agent
  • Paste the full instructions from /agent/instructions.md into the Instructions field
  • Set the display name to: MAMA – Maternal AI Assistant
  • Set the description to the text provided in /agent/instructions.md

Step 4 — Test

Use these two critical test cases to verify the adversarial review works correctly:

"Pregnant woman in Yobe, 12 weeks gestation, fever 38.5°C, chills, headache."
→ Expected: Quinine recommended. AL contraindication caught and explained.

"Pregnant woman in Yobe, 14 weeks gestation, fever 38.5°C, chills, headache."
→ Expected: AL recommended. Dr. Verify raises supply chain challenge. MAMA defends.

Demo Video

[MAMA Demo

Click to watch the demo.


Social

Follow the build and share:


Built With


License

This project is licensed under the MIT License — see the LICENSE file for details.


Author

Built by [Bukola Jimoh] for the Elasticsearch Agent Builder Hackathon 2026.


Acknowledgments

  • Malaria data sourced from the Malaria in Pregnancy Nigeria 2015–2025 dataset (Figshare)
  • Clinical protocols based on WHO 2015 Malaria in Pregnancy Treatment Guidelines and Nigeria's 2022 National Malaria Elimination Programme

Made with ❤️ for Nigerian mothers and their babies.

About

MAMA – Maternal Artificial Multi-step Assistant for malaria in pregnancy in Nigeria

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published