Keith Cox, PhDBehavioral Researcher & Conversational AI Designer
Back to Portfolio

Pharmacy Virtual Assistant

2025

A multi-agent virtual assistant for retail pharmacy, designed and prototyped as a proof of concept.

Figma · Voiceflow · Airtable REST API · SSML

Role

Wrote the system specification, wireframed the interaction flow in Figma, and authored the intent model with its training utterances. Built the prototype in Voiceflow across 27 nodes, including live API integration with a synthetic Airtable database and a RAG knowledge base covering FAQs (hours, address, etc.).

Summary

People contact a pharmacy with three kinds of questions: general ones, questions about their own prescriptions, and clinical ones. I designed a multi-agent virtual assistant for a fictional pharmacy that keeps the three apart.

Key decisions

  • Identity gate. Patient records sit behind a verification step that is the only route to them in the flow, so privacy does not depend on a model obeying a prompt.
  • Clinical escalation. The router is trained to send clinical questions to a human. Unlike the identity gate, this relies on a model, because the router has to recognize the question as clinical. That's why missed clinical questions are a key measure for a pilot.
  • Keypad fallback. A caller whose date of birth is misheard twice switches to keypad entry.

The result is a written specification and a 27-node Voiceflow prototype. In testing, the prototype verified a user against a live database and read back the status of each of their prescriptions in plain language. Other paths were only partly tested (see Outcome). In a pilot I would measure false verifications, clinical questions the router missed, and which callers end up on the keypad.

Problem

People contact a pharmacy for three kinds of help: general information ("How late are you open today?"), their own prescriptions ("Do I have any refills left on my inhaler?"), and professional advice ("Is it safe to take aspirin that expired last month?"). The first is routine. The second involves protected patient information. The third needs a pharmacist.

One agent handling all three has to remember, on every turn, not to read a record until it knows who it's talking to. If the only privacy control is a line in the prompt, privacy depends on the model following it every time. And an agent that prioritizes containment over compliance will eventually offer medical advice.

I designed and prototyped this assistant as a proof of concept. The goal was to deliver a specification that an engineering team could build from.

Architecture

Scroll diagramsideways for more →

Agent topology of the pharmacy virtual assistant, centered on the identity gateAn inbound request reaches a Triage Router Agent, which classifies it into one of three intents. FAQ questions go to an FAQ Agent backed by a RAG knowledge base covering hours, address, and drive-thru information, and clinical questions go to a Human Escalation Agent; both sit above a boundary line marked “no verification required” and neither touches a patient record. Patient-specific questions go down into an Identity Gate Agent, which is the only opening in that boundary: it collects first and last name and date of birth and matches them against the live database. A verified user passes below the boundary into the protected zone and reaches the Prescription Status Agent, which performs a live Airtable lookup and speaks a normalized status. Three failed verification attempts route back up and out to the Human Escalation Agent, above the boundary, carrying no patient data.NO VERIFICATION REQUIREDVERIFIED USERS ONLYInbound requestTriage Router Agentclassifies intent on the first turnFAQCLINICALPATIENT_SPECIFICFAQ AgentRAG over hours · address · drive-thruno patient record touchedHuman Escalation Agentclinical questions · user requestfailed verification3 failed attemptsIdentity Gate Agentfirst + last name, date of birthmatched against the live databaseverifiedPrescription Status Agentlive Airtable lookupnormalized spoken status
The dashed line has one opening and the Identity Gate stands in it: every path to a prescription record runs through verification. No other edge enters that zone, so sensitive data is protected by the architecture itself rather than relying on a model to enforce a rule in the prompt. The Human Escalation Agent sits above the line, which means an unverified user can always reach a person, and nothing protected travels with them. The built flow also includes an edge for escalating a clinical question raised mid-interaction from the Prescription Status Agent; that edge is left out here to keep the boundary easy to read.

The full interaction flow in Figma, organized around one axis: whether an intent requires patient verification. Everything on the right of the canvas is unreachable until the API call in the middle returns a match. The identity-repair loop is the branch that checks the values submitted on a retry against those already captured, rather than firing a duplicate API call. Click to zoom.

Interaction Decisions

Some interaction design choices and the concrete failures they prevent.

  1. A dedicated Identity Gate Agent checks name and date of birth against the live database before any other agent can reach patient data. It is the only path there in the graph, and it confirms "Thank you, your identity has been verified" before sharing anything protected.

    Prevents: A persistent or persuasive user talking a single agent into revealing someone else's prescriptions.

  2. The verification flow is only triggered when an intent requires access to protected data. A user asking about store hours is never asked who they are.

    Prevents: Making everyone authenticate to learn whether the pharmacy is open on Sunday, which teaches users to see verification as an obstacle.

  3. If speech-to-text fails to parse a date of birth twice, the agent switches to keypad entry and gives an example aloud: "for example, 0-5-1-2-1-9-8-0 for May twelfth, 1980."

    Prevents: A user stuck repeating themselves to a recognizer that can't understand them. Spoken dates are easy to mishear ("oh five twelve eighty" and "May twelfth nineteen eighty" are the same date), and recognition is least reliable for older users, non-native speakers, and accents underrepresented in training data, so that loop falls hardest on them.

  4. Verification retries are capped at three. A retry with the same name and date of birth isn't sent to the database again. At the cap, the agent explains why before transferring: "For your security and privacy, I cannot access patient records without verification."

    Prevents: Spending a user's attempts on a question the database already answered, and a gate that either stonewalls without a reason or quietly relaxes to end an awkward conversation.

  5. Clinical questions (side effects, dosage, interactions, "can I take this expired pill") are routed to a pharmacist, and no agent is designed to answer them, even with a hedge.

    Prevents: A plausible but unverified clinical answer given to a user who can't tell whether it's right.

  6. A user can ask for a person from the first turn. On a clinical question, the assistant says it can't answer and offers a transfer, which the user can turn down.

    Prevents: A user having to fail at something before they're allowed to reach a human.

  7. Each transfer records why it happened (CLINICAL_QUERY, AUTH_FAILED, USER_REQUESTED) before it executes.

    Prevents: A pharmacist picking up a conversation with no idea why it arrived, and an operations team reconstructing escalation causes from transcripts.

Content Design

The database stores prescription status the way a pharmacy technician needs it on screen. Several of those values are unsafe to show or say to the patient. "On Hold" sounds like the pharmacy is withholding the medication. "Refill Req Sent" is not a sentence. "No Refills Remaining" is accurate but doesn't say what to do next.

So each raw value maps to one of five categories, and each category to one authored sentence. A value nobody anticipated still lands in a category, so the user still gets a real answer.

Scroll tablesideways for more →

Raw database valueNormalized categoryWhat the user hears
Filled · Ready · Ready for PickupREADY…is filled and ready for pickup at our main pharmacy counter.
Pending Doctor · Refill Req SentAWAITING_PRESCRIBER…is awaiting prescriber authorization. We sent a request to your doctor.
Expired · No Refills RemainingEXPIRED…has expired with no remaining refills. We'll need a new prescription from your provider.
Prior Auth Required · Insurance HoldINSURANCE_DELAY…is currently delayed pending insurance prior authorization.
null · any unmapped valueOTHER…is actively being processed by our pharmacy staff.
Status normalization matrix, specification §5, Agent 3. Every response completes "Your {medication} …", so it works for one drug or a list.

Two of the sentences carry the next step. EXPIRED says the provider has to write a new prescription. AWAITING_PRESCRIBER says the pharmacy already asked the doctor, so the user doesn't call to ask again.

For voice, delivery is specified too. List items are separated by 200ms SSML breaks, with falling intonation only on the last, so the user can hear when the list ends. Dates and numbers are read as digits ("one nine four two," not "one thousand nine hundred forty-two"), because a user confirming their date of birth needs to hear the digits they said.

On the input side, training utterances come from how users actually ask ("is my script ready," "did my doctor call one in"). There are 22 across the patient-specific intents, plus a 34-value entity model for medication names, dosage forms and units, task types, and insurance carriers.

Outcome

The result is a 27-node Voiceflow prototype and a specification, including a state schema and API contract, written for an engineer to build from. In the prototype I confirmed that FAQ questions reached the FAQ agent and got answers, that a correct name and date of birth returned the matching record from the live database, and that the assistant then read back the status of each of that patient's prescriptions. Matching a medication the user named was built but not confirmed working. Voiceflow's trial credits ran out while I was still debugging, so the keypad fallback and clinical escalation were never tested, and there is no public demo. The specification predates the build and differs from it in two places, noted in the appendix.

Recommended Evaluation Protocol

None of this has been measured. I was the prototype's only user, testing against a synthetic database, and only some paths ran (see Outcome). This is the plan for a pilot.

Containment (the share of conversations that end without a human) is the usual headline metric, and the wrong one here. Every clinical question is a planned transfer, so chasing containment would push the system to answer the questions it exists to refuse.

  1. False-verification rate

    Proposed: not measured

    How often the gate opens for the wrong person. Target: zero.

    Why this one: Name plus date of birth is imperfect, and two patients can share both. This measures whether the system does its main job.

  2. Gate failures, split by cause

    Proposed: not measured

    Of users never verified, how many were the wrong person correctly refused, and how many were the right person the recognizer couldn't hear.

    Why this one: These are opposite failures with opposite fixes, and a single failure rate hides which one is happening.

  3. Keypad fallback rate, by group

    Proposed: not measured

    How often the keypad fallback fires, segmented by age band, region, and time of day.

    Why this one: This is the accessibility measure. If one group hits the fallback far more often, the primary path is failing them, and an overall success rate won't show it.

  4. Escalation precision, both directions

    Proposed: not measured

    Of conversations transferred as clinical, how many a pharmacist agrees were clinical. Also, how many clinical questions the router missed and the assistant answered.

    Why this one: Over-escalation shows up in the transfer log. Under-escalation, the failure the design exists to prevent, can only be found by sampling conversations that weren't transferred.

  5. Status comprehension

    Proposed: not measured

    Whether a user can say what happens next after hearing or reading a status.

    Why this one: It's cheap to test: five users and one question, "so what do you do now?" If EXPIRED doesn't produce "call my doctor," the sentence is wrong.

What Transfers

Little here is specific to pharmacy. The design rests on three structures found in any regulated service, such as claims, insurance, banking, and benefits.

  1. A record class that has to stay behind an identity check

    Prescriptions here; claim files and account balances elsewhere. The question is where the check lives: as a prompt instruction the model must follow every turn, or as a boundary in the flow with no path around it. The two behave the same until a user pushes.

  2. A question class that belongs to a licensed human

    Dosage here; coverage decisions and financial or legal advice elsewhere. The failure is the same in each: a fluent answer that turns out to be wrong, and a user who acts on it. A hedge at the start doesn't change what they do.

  3. A user who doesn't know which class they're in

    Users don't sort their own questions, and the one with the most urgent question is the least likely to phrase it in the system's terms. That's why the clinical branch can interrupt at any point.

Appendix

Explorations
  • Selected: A Figma wireframe of the full interaction flow, walked end to end before any agent logic existed.

    Rejected: Building directly in Voiceflow first was rejected. The identity-gate branching and the escalation paths needed to be legible on a canvas (where an unhandled branch or an escalation with no trigger is visible at a glance) before being committed to a tool that makes structural changes expensive.

  • Selected: Organizing the entire wireframe around a single axis: whether a given intent requires patient verification. The canvas is split into a "Verification: NOT Required" half and a "Verification: REQUIRED" half, and every intent is placed on one side or the other before anything else about it is designed.

    Rejected: Verifying every user at the top of the interaction was rejected, even though it is simpler to build and simpler to reason about. It would mean asking a user to prove their identity to find out whether the pharmacy is open on Sunday.

  • Selected: Routing clinical questions to a human as a hard interrupt, from any point in the interaction.

    Rejected: A hedged clinical answer ("I'm not a pharmacist, but generally...") was rejected. It is the most tempting option in the design, because it feels helpful and it is what a fluent model will do by default.

  • Selected: A synthetic Airtable database populated with real prescription shapes: eleven fields per record including sig directions, prescriber, date written, refills remaining, and fill history.

    Rejected: A flat mock lookup returning a canned status string was rejected. The disambiguation flow, the status-normalization matrix, and the multi-prescription readout are only designable against records that have the messiness of real ones: multiple scripts per patient, the same medication at different strengths, statuses that do not map cleanly onto anything a user would recognize.

Guardrails & Human Oversight

Each card pairs a design concern with what the assistant does about it and where the specification says so.

  • User control

    A user can ask for a person at any point. The Human Escalation Agent sits alongside the router, so a user can reach it with their first message. On a clinical question, the assistant explains that it can't answer and offers a transfer, which the user can accept or decline.

    Figma wireframe, clinical branch ("Explain cannot answer" → "Offer transfer" → Yes/No); specification §5, Agent 5, trigger 3

  • Error recovery

    After two failed attempts to recognize a spoken date of birth, the agent switches to keypad entry and gives an example: "enter your 8-digit date of birth, for example 0-5-1-2-1-9-8-0 for May twelfth, 1980." Without the example, "8-digit date of birth" is ambiguous.

    specification §5, Agent 2, step 2 (DOB capture and fallback mechanics)

  • Repair

    If a second attempt repeats the same name and date of birth, the flow doesn't query the database again. It checks the new input against the values already captured and, when they match, tells the user no record was found.

    Figma wireframe, identity-repair branch ("Match existing variables?" → Yes → "Inform user no record found")

  • Transparency

    At the retry cap, the user is told why and what happens next: "For your security and privacy, I cannot access patient records without verification. I will transfer you to a pharmacy team member who can help." The gate stays closed, and the user gets an explanation.

    specification §5, Agent 2, step 3 (retries ≥ 3)

  • Human oversight

    Each escalation trigger (clinical question, failed authentication, user request) writes an audit reason to shared state before the transfer: CLINICAL_QUERY, AUTH_FAILED, or USER_REQUESTED. Why a conversation left the assistant is recorded as it happens, so nobody has to work it out from transcripts later.

    specification §3, v_transfer_reason; §5, Agent 5 triggers

  • Feedback

    The assistant confirms verification ("Thank you, your identity has been verified") before sharing anything protected. The user knows the gate has opened and isn't left wondering whether the system is looking something up or still checking who they are.

    specification §5, Agent 2, step 3 (1 record returned)

Iteration
  1. Wireframe → prototype: six transactions specified, one built

    Shipped: The Figma flow mapped six patient-specific transactions sitting behind the identity gate (status, history, billing, refill, hold, and billing change), each with its own API call and its own report-back to the user.

    Broke: Building all six would have produced six shallow branches and no evidence that the hard parts worked: the gate in front of all of them and the spoken readout after it.

    Fixed: The prototype builds one transaction (prescription status): routing, verification, the Airtable lookup, disambiguation across multiple prescriptions, and a normalized spoken answer. Routing, verification, and reading back each prescription's status ran in testing; matching a medication the user named was not confirmed. The other five remain specified in the wireframe and were not built.

  2. Multi-prescription readout: hardcoded slots → indexed loop

    Shipped: The first version of the readout handled a patient's medications as three named slots (med_1_name, med_2_name, med_3_name, each with its own index variable) because every patient in the synthetic database has two or three prescriptions.

    Broke: Three slots covered every record that happened to exist and would have failed on the fourth. The readout logic also had to be written once per slot, which is three places for the phrasing to drift apart, on a channel where the phrasing is all the user gets.

    Fixed: Replaced with a single indexed loop over the returned array: current_index, current_medication_name, has_more_medications, medication_count. One authored sentence is designed to serve a patient with two prescriptions or twelve. Both generations are still visible in the exported project's variable registry: the abandoned med_1/med_2/med_3 slots sit alongside the loop variables that replaced them.

  3. Debugging the Airtable response shape

    Shipped: The identity lookup was written expecting the patient record to carry the prescriptions themselves.

    Broke: It does not. Airtable returns the patient record plus an array of linked prescription record IDs (the prescriptions are a second hop away), so the readout was reaching for medication names that were not in the payload it had.

    Fixed: A debug node was dropped into the canvas to print the captured fields (patient ID, record ID, and the prescription ID array), so the actual response shape was visible on the canvas. The lookup was then restructured around the two-hop reality. That node is still in the exported project.

Specification hand-off

I built this solo and wrote the specification as a hand-off document: a system overview and developer prompt that someone who did not design the system could build from.

The specification covers the details an engineer would otherwise have to decide alone: every state variable's name, type, and default; the exact filterByFormula the identity lookup sends and the field IDs it uses; the full mapping from raw database status to spoken sentence; and the retry cap as the number 3. Anything left unspecified gets decided during implementation by whoever reaches it first.

The built prototype and the specification differ in two places. The spec describes a Prescription Status Agent with three disambiguation branches; the build resolves status through six inquiry-type outcomes. The wireframe scopes six patient-specific transactions; the prototype builds one. The specification is unchanged from before the build, so both differences can be seen in the artifacts.

Two artifacts from the specification, reproduced as written. The first is the shared state every agent reads and writes; the second is the request the identity gate sends.

Scroll tablesideways for more →

VariableTypeDefaultRole
v_first_nameString""Spoken or transcribed first name of the caller
v_last_nameString""Spoken or transcribed last name of the caller
v_dobString (ISO)""Date of birth, normalized to YYYY-MM-DD
v_dob_dtmfString""Digits captured via the keypad fallback, MMDDYYYY
v_is_authenticatedBooleanfalseThe gate. Must be true before any PHI node is reachable
v_auth_retriesNumber0Verification failure counter; cap is 3
v_airtable_record_idString""Airtable recordId, populated only on a positive match
v_patient_idString""Internal patient ID retrieved from the matched record
v_rx_raw_dataArray[]Raw prescription records returned from the Airtable payload
v_target_drug_nameString""Medication named by the caller during disambiguation
v_rx_status_categoryString""Normalized status: READY · AWAITING_PRESCRIBER · EXPIRED · INSURANCE_DELAY · OTHER
v_intent_categoryString""Router output: FAQ · PATIENT_SPECIFIC · CLINICAL
v_transfer_reasonString""Audit reason written before escalation: CLINICAL_QUERY · AUTH_FAILED · USER_REQUESTED
Global state registry, specification §3. Every agent in the topology operates on this one shared state object, which is what makes v_is_authenticated a gate for the whole system.

Scroll codesideways for more →

GET https://api.airtable.com/v0/{baseId}/{tableId}
Authorization: Bearer {AIRTABLE_API_KEY}
Content-Type: application/json

filterByFormula = AND(
    {First Name}    = '{v_first_name}',
    {Last Name}     = '{v_last_name}',
    {Date of Birth} = '{v_dob}'
  )

→ 1 record   set v_is_authenticated = true, store recordId + patient ID,
             load prescriptions into v_rx_raw_data
→ 0 records  increment v_auth_retries; at 3, set v_transfer_reason
             = AUTH_FAILED and route to Human Escalation
Identity lookup, specification §4

The specification puts all three verification parameters in one query. A staged check (confirm the surname, then ask for the date of birth) would leak information: a user would learn from the second prompt that the first value matched somebody. One query returns one record or zero, and zero is the only thing an unverified user is ever told.