Skip to Content
ExamplesReturns

Returns

Code  · Template: Returns agent · Runs on http://localhost:3008

A returns desk for store staff. Keep the store’s return policy, describe a customer’s return request, agree a decision with the agent, and look up each customer’s returns log.

A request that needed approval, then was approved by a manager

A new requestA customer’s returns log
The request form, filled from an exampleLatest decision and history

What it shows

  • Staff talking about a customer. The person chatting isn’t the customer. The decision is saved on the customer, under the id the staff member gives, so the first message says everything: the policy, the customer, the order, the items and their past returns.
  • A policy kept in the app. Loops has nowhere to store a policy, so the app keeps it and sends it with each new request. Without one, the agent uses its default policy.
  • Agreeing before recording. The agent records only once staff agree. needs_approval is just a recorded value, so Manager approved tells the agent the outcome in the same thread, and it records a second decision.

The endpoints it uses

EndpointUsed for
POST /chatDescribing a request, answering the agent, and agreeing.
GET /usersThe customer list, 50 at a time with Load more.
GET /users/:userIdA customer’s past returns, and checking whether a decision was recorded.

All paths start with /loop/:organizationId/:loopId, on the returns-desk loop. The return-decision workflow is started by the agent’s tool.

Run it

  1. Deploy the Returns agent template. It has no optional workflows. Copy the organization id and the returns-desk loop id.
  2. In Settings → API tokens, create a token for that loop with access set to Run and read.
  3. Copy apps/returns/.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=returns.

Where to look in the code

FileWhat it does
src/lib/loops.tsServer functions for the Loops endpoints.
src/lib/desk.tsWhat Loops doesn’t store: the policy, requests, transcripts and names.
src/routes/requests.$requestId.tsxOne request’s conversation, its recorded decision and the draft.
src/routes/policy.tsxThe store’s return policy.
src/routes/customers.$customerId.tsxA customer’s returns log.
Last updated on