Lab results
Code · Template: Lab results agent · Runs on http://localhost:3004
A mock patient portal. Add a test patient, pick or enter a set of lab results, and ask the agent what they mean. The page shows the reference pages Loops saved and whether anything was flagged. A clinician view lists every patient with results flagged for follow-up.

| Follow-up list | A flagged patient |
|---|---|
![]() | ![]() |
What it shows
- Sending structured data as text. The chat API takes text only, and Loops doesn’t store result values. So the first message of each thread lists the results with their units, ranges and flags.
- Reading reference pages from memory. After explaining, the agent’s lookup saves a “Reference for” memory line per test with a MedlinePlus page. The app drops repeated URLs, since every lookup saves them again.
- Follow-up the app has to track. The
labFollowUpflag never clears, and Loops can’t record a review. Mark reviewed keeps the reviewedflaggedAtin the app, so a later flag shows as new.
The endpoints it uses
| Endpoint | Used for |
|---|---|
POST /chat | Sending one message and getting the reply. |
GET /users | Finding every patient for the follow-up list. |
GET /users/:userId | A patient’s reference pages and flag. 404 means nothing yet. |
All paths start with /loop/:organizationId/:loopId, on the lab-results loop. The lab-education-lookup workflow is started by the agent’s tool.
Run it
- Deploy the Lab results agent template. Copy the organization id and the
lab-resultsloop id. - In Settings → API tokens, create a token for that loop with access set to Run and read.
- Copy
apps/lab-results/.env.exampleto.envand fill inLOOPS_API_URL,LOOPS_ORGANIZATION_ID,LOOPS_LOOP_IDandLOOPS_API_TOKEN. - Run
bun run dev --filter=lab-results.
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/samples.ts | The sample result sets, and how a result is written out for the agent. |
src/routes/patients.$patientId.tsx | The patient’s results, the chat, reference pages and follow-up. |
src/routes/clinician.index.tsx | Every patient flagged for follow-up. |
Last updated on

