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.

| Booking requests | A patient |
|---|---|
![]() | ![]() |
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 /usersreturns ids only, so the booking requests page reads each patient and lists those withmetadata.lastIntake, newest first. Patients with symptom checks but no request show under Unfinished intakes. - Receiving the booking webhook.
clinic-intake-recordposts 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
| Endpoint | Used for |
|---|---|
POST /chat | Sending one message and getting the reply. |
GET /users | The booking requests list, 50 at a time with Load more. |
GET /users/:userId | A 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
- Deploy the Clinic intake agent template. Copy the organization id and the
clinic-intakeloop id. - In Settings → API tokens, create a token for that loop with access set to Run and read.
- Copy
apps/clinic-intake/.env.exampleto.envand fill inLOOPS_API_URL,LOOPS_ORGANIZATION_ID,LOOPS_LOOP_IDandLOOPS_API_TOKEN. - 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
| File | What it does |
|---|---|
src/lib/loops.ts | Server functions for the Loops endpoints, and helpers to read memory. |
src/lib/patients.ts | What Loops doesn’t store: names, areas, thread ids and transcripts. |
src/routes/intake.$patientId.tsx | The intake chat. |
src/routes/clinic.index.tsx | The clinic’s booking requests. |
src/routes/api/booking-requests.$token.ts | The webhook receiver. |

