Clinical AI for Nigerian community health workers — powered by Elasticsearch
Built for the Elasticsearch Agent Builder Hackathon 2026
A misdiagnosis at 12 weeks gestation — prescribing Artemether-Lumefantrine instead of Quinine — can cause fetal harm. MAMA catches this. Every time.
- 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
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:
- Analyze — call both tools to get regional epidemiological and pharmacy context
- Diagnose — apply trimester-specific clinical protocols
- Draft — form a preliminary recommendation
- 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.
| 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 |
Query:
Pregnant woman in Yobe, 14 weeks gestation, fever 38.5°C, chills, headache.
MAMA's Response:
State: Yobe (North East)
Average malaria burden: 58.5 cases/month
Supply disruption rate: 50%
Risk level: CRITICAL (>30%)
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)
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.
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
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.
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.
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.
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
- ES|QL with
TO_INTEGER,CASE, andSTATSfor conditional disruption calculations and dynamic stock alerts - Two custom ES|QL tools:
get_malaria_trends— time-series aggregation + disruption rate calculation across 10 yearscheck_pharmacy_inventory— stock levels with dynamicOK / WARNING / URGENTalert 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)
| 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.
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
- An Elastic Cloud Serverless account (Newton 9.3+)
- Access to Elastic Agent Builder
- Gemini 1.5 Pro connector configured in Kibana
In Kibana: Stack Management → API Keys → Create API key Select Unrestricted permissions. Store it securely — never share it publicly.
Use Kibana Data Visualizer to upload the three CSV files from /data into these indices:
nigeria_malaria_pregnancyclinical_guidelinespharmacy_inventory
In Agent Builder, create two tools of type ES|QL:
get_malaria_trends— use the query from/queries/get_malaria_trends.esqlcheck_pharmacy_inventory— use the query from/queries/check_pharmacy_inventory.esql
- Create a new agent with the Gemini 1.5 Pro model
- Assign both tools to the agent
- Paste the full instructions from
/agent/instructions.mdinto the Instructions field - Set the display name to:
MAMA – Maternal AI Assistant - Set the description to the text provided in
/agent/instructions.md
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.
Click to watch the demo.
Follow the build and share:
- 🐦 Post link: (https://x.com/_EuroBridge/status/2026433126117904728?s=20)
- Tag: @elastic_devs
- Elasticsearch Serverless
- Elastic Agent Builder
- ES|QL
- Gemini 1.5 Pro via Vertex AI connector
This project is licensed under the MIT License — see the LICENSE file for details.
Built by [Bukola Jimoh] for the Elasticsearch Agent Builder Hackathon 2026.
- 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.
