Skip to Content
ExamplesLab results

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.

A patient's results, the agent's explanation, and the saved reference pages

Follow-up listA flagged patient
Patients flagged for follow-up, marked newA patient's flag, results and timeline

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 labFollowUp flag never clears, and Loops can’t record a review. Mark reviewed keeps the reviewed flaggedAt in the app, so a later flag shows as new.

The endpoints it uses

EndpointUsed for
POST /chatSending one message and getting the reply.
GET /usersFinding every patient for the follow-up list.
GET /users/:userIdA 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

  1. Deploy the Lab results agent template. Copy the organization id and the lab-results loop id.
  2. In Settings → API tokens, create a token for that loop with access set to Run and read.
  3. Copy apps/lab-results/.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=lab-results.

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/samples.tsThe sample result sets, and how a result is written out for the agent.
src/routes/patients.$patientId.tsxThe patient’s results, the chat, reference pages and follow-up.
src/routes/clinician.index.tsxEvery patient flagged for follow-up.
Last updated on