Skip to Content
ExamplesProtocol

Protocol

Code  · Template: Protocol agent · Runs on http://localhost:3006

A mock store. Placing an order creates the customer in Loops. Their page shows the order, their last check-in and a timeline of everything Loops remembered, next to a chat with the agent about fitting the products into their day.

A customer's chat, last order, check-in and timeline

Placing an orderCustomers
The order form with two products pickedEveryone Loops knows about

What it shows

  • Starting a workflow from your app. The store posts each order to protocol-order-welcome, which records it on the customer and sends a welcome SMS. See Triggering a run.
  • Telling the agent what they bought. The agent can’t read the customer, so the first message of each thread lists the products from their last order.
  • Memory as a timeline. Metadata keeps only the latest check-in, and label checks are saved only as memory. The page tags each memory line as an order, check-in, label check or interaction check.

The endpoints it uses

EndpointUsed for
POST / on protocol-order-welcomePlacing an order.
POST /chat on protocol-agentSending one message and getting the reply.
GET /usersThe customer list, 50 at a time with Load more.
GET /users/:userIdA customer’s order, last check-in and memory.

The order body:

{ "customerId": "thandi@example.com", "products": ["Magnesium Glycinate", "BPC-157"], "orderId": "ORD-1042" }

With a phone, the workflow sends a real SMS, so leave it out or use your own number.

Run it

  1. Deploy the Protocol agent template and tick the optional protocol-order-welcome workflow.
  2. Copy the organization id, the protocol-agent loop id and the protocol-order-welcome loop id.
  3. In Settings → API tokens, create a token for the whole organization with access set to Run and read. The app calls two loops, and a token for one loop only works on that loop.
  4. Copy apps/protocol/.env.example to .env and fill in LOOPS_API_URL, LOOPS_ORGANIZATION_ID, LOOPS_AGENT_LOOP_ID, LOOPS_ORDER_LOOP_ID and LOOPS_API_TOKEN.
  5. Run bun run dev --filter=protocol.

To put a chat link in the welcome SMS, set PROTOCOL_CHAT_URL under Variables and secrets on protocol-order-welcome.

Where to look in the code

FileWhat it does
src/lib/loops.tsServer functions for the Loops endpoints.
src/lib/customers.tsWhat Loops doesn’t store: names, thread ids and transcripts.
src/lib/products.tsThe store’s products, named as the brand’s catalogue names them.
src/routes/index.tsxThe order form.
src/routes/customers.$customerId.tsxA customer’s order, last check-in, timeline and the chat.
Last updated on