← All work
3rd placeAI Engineer & Team Lead · August 2026

Wifaqوِفاق

A medication safety engine answering one hard question. Given everything already active in your body, is this safe right now, and if not, when?

The problem

A patient on several medications has a timing problem, not just an interaction problem. Iron has to stay four hours clear of levothyroxine. Calcium has to stay two hours clear of alendronate. Some drugs collide with breakfast rather than with each other. Existing checkers answer whether two drugs interact. The real question is what to take, and when, today, given that one dose was already taken late.

Approach

  1. A LangGraph state machine: an orchestrator plus five specialists for interaction, scheduling, food context, recovery, and safety.
  2. The scheduler builds a day where the prescribed regimen is a hard constraint, interaction windows are blocks, and meals are events the day is planned around.
  3. Live rebuild. History before now is never rewritten. A dose whose time passed unlogged becomes missed, a late dose pushes the next one out to honour the minimum gap, and if the remainder cannot be made feasible the recovery agent takes over automatically.
  4. Constraint passes run to convergence. Moving a dose clear of breakfast can push it onto another drug's window, so the meal, food, and drug passes repeat until the timetable stops changing.

How it fits together

STARTfood_contextLLMprospectivealready happenedinteractionrule enginerecoverydeterministicschedulerno LLMsafetyapprove / blockrespondone answerhalts the run
One node calls a model, and it only identifies foods. Every node that decides whether something is safe is deterministic, which is why the system still works with no API key.

Key decisions

  • 01

    LangGraph over CrewAI

    CrewAI models a team, where a Researcher hands off to a Critic. Wifaq is a state machine: one owner of patient state, conditional routing on intent, and a safety gate that can halt the run outright. The topology had to match the problem rather than the fashion.

  • 02

    The verdict comes from a rule engine, not the model

    The system runs with no API key at all. Interaction verdicts are deterministic; the LLM writes the plain language explanation and identifies foods. Without a key you lose the prose, not the safety logic. A medication safety answer that varies with sampling temperature is not a safety answer.

  • 03

    A dose's identity is its slot, not its time

    Times move. Rescheduling and late logging both change them. Matching on time alone lost track of exactly the doses this engine exists to move: a 07:00 levothyroxine shifted to 12:00 came back as a second dose on the next rebuild. Anchoring to the prescribed slot removed a whole class of duplication bugs.

  • 04

    The patient supplies the time, not the clock

    Defaulting a log to now recorded zero drift for every late dose, and drift is the only signal the recovery flow has to work with. The API takes when the dose was actually swallowed.

Results

  • 3rd place at the Saudi Digital Academy and atomcamp Agentic AI Bootcamp hackathon.
  • 114 guardrail tests covering safety veto, schema validation, iteration limits, and fail-closed behaviour.
  • Runs entirely offline of any LLM provider with the safety logic intact.
Next project

Enan

Read it

Want the detail behind any of this? Get in touch.