Skip to Content
ExamplesProduct advisor

Product advisor

Code  · Template: Product advisor agent · Runs on http://localhost:3000

A microsite for trying the Product advisor agent as different shoppers. The home page lists the organization’s shoppers from Loops and lets you add new ones. Opening a shopper shows their last saved quiz and lets you chat with the agent as them.

A shopper's page, with their saved quiz above the conversation

ShoppersStarting a conversation
The shopper list, with drafts marked "No quiz yet"An empty chat with suggested starters

What it shows

  • Chatting with an agent from your own app. One message per request on a thread, with Loops keeping the history. See Calling an agent.
  • Reading what a workflow saved. After the agent recommends, the product-advisor-save workflow writes the quiz onto the shopper, and the page reads it back.
  • Draft shoppers. Loops creates a shopper only when their first quiz is saved, so the app keeps new shoppers as drafts marked No quiz yet until then.

The endpoints it uses

EndpointUsed for
POST /chatSending one message and getting the agent’s reply.
GET /usersThe shopper list, 50 at a time with Load more.
GET /users/:userIdA shopper’s saved quiz in metadata.quiz. 404 means none yet.

All paths start with /loop/:organizationId/:loopId, on the product-advisor loop.

Run it

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

Port 3000 is also the Loops dashboard’s port when you run Loops locally. Stop one of them, or change the port in the app’s package.json.

Where to look in the code

FileWhat it does
src/lib/loops.tsServer functions for the three Loops endpoints.
src/lib/shoppers.tsWhat Loops doesn’t store: names, thread ids and transcripts.
src/routes/index.tsxThe shopper list.
src/routes/users.$userId.tsxA shopper’s last quiz and the chat.
Last updated on