Skip to Content
ExamplesClinic intake

Clinic intake

Code  · Template: Clinic intake agent · Runs on http://localhost:3002

Patients fill in a short form and chat with the agent, which takes their intake and files a booking request. The clinic side lists those requests from Loops, with red flags marked, and receives the clinic webhook.

An intake where the symptom check found a red flag

Booking requestsA patient
Booking requests with urgency badges and a red flagA patient's last request and history

What it shows

  • Surfacing what the agent can’t see. The symptom check runs after the reply, and the agent never sees its result. The app watches for a “Symptom check for” memory line, and shows any red flag in a banner with the emergency number and nearby hospitals.
  • A clinic view built from users. GET /users returns ids only, so the booking requests page reads each patient and lists those with metadata.lastIntake, newest first. Patients with symptom checks but no request show under Unfinished intakes.
  • Receiving the booking webhook. clinic-intake-record posts each confirmed request to the app. The request isn’t signed, so the receiver sits behind a hard-to-guess path.

The endpoints it uses

EndpointUsed for
POST /chatSending one message and getting the reply.
GET /usersThe booking requests list, 50 at a time with Load more.
GET /users/:userIdA patient’s last request and memory. 404 means nothing yet.

All paths start with /loop/:organizationId/:loopId, on the clinic-intake loop. Its two workflows are started by the agent’s tools.

Run it

  1. Deploy the Clinic intake agent template. Copy the organization id and the clinic-intake loop id.
  2. In Settings → API tokens, create a token for that loop with access set to Run and read.
  3. Copy apps/clinic-intake/.env.example to .env and fill in LOOPS_API_URL, LOOPS_ORGANIZATION_ID, LOOPS_LOOP_ID and LOOPS_API_TOKEN.
  4. Run bun run dev --filter=clinic-intake.

Port 3002 is also this docs site’s port when you run Loops locally. Stop one of them, or change the port in the app’s package.json.

Optionally, set CLINIC_COUNTRY, for example South Africa, on clinic-symptom-check so red flags come with the right emergency number.

To receive the webhook, set BOOKING_WEBHOOK_TOKEN in .env to a long random string. Then set BOOKING_WEBHOOK_URL on clinic-intake-record to https://<your app>/api/booking-requests/<BOOKING_WEBHOOK_TOKEN>, and add the app’s host to that loop’s allowed hosts.

Where to look in the code

FileWhat it does
src/lib/loops.tsServer functions for the Loops endpoints, and helpers to read memory.
src/lib/patients.tsWhat Loops doesn’t store: names, areas, thread ids and transcripts.
src/routes/intake.$patientId.tsxThe intake chat.
src/routes/clinic.index.tsxThe clinic’s booking requests.
src/routes/api/booking-requests.$token.tsThe webhook receiver.
Last updated on