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 new request | A customer’s returns log |
|---|---|
![]() | ![]() |
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_approvalis 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
| Endpoint | Used for |
|---|---|
POST /chat | Describing a request, answering the agent, and agreeing. |
GET /users | The customer list, 50 at a time with Load more. |
GET /users/:userId | A 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
- Deploy the Returns agent template. It has no optional workflows. Copy the organization id and the
returns-deskloop id. - In Settings → API tokens, create a token for that loop with access set to Run and read.
- Copy
apps/returns/.env.exampleto.envand fill inLOOPS_API_URL,LOOPS_ORGANIZATION_ID,LOOPS_LOOP_IDandLOOPS_API_TOKEN. - Run
bun run dev --filter=returns.
Where to look in the code
| File | What it does |
|---|---|
src/lib/loops.ts | Server functions for the Loops endpoints. |
src/lib/desk.ts | What Loops doesn’t store: the policy, requests, transcripts and names. |
src/routes/requests.$requestId.tsx | One request’s conversation, its recorded decision and the draft. |
src/routes/policy.tsx | The store’s return policy. |
src/routes/customers.$customerId.tsx | A customer’s returns log. |
Last updated on

