Skip to content

About

A support and enquiry-routing agent for a Shopify store: grounded answers, human hand-off, per-store memory, consent-gated lead capture into Zoho CRM. Built and tested against fakes and a development store.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shop-support-agent

CI

The support console on a development store with sample customers: the dashboard, the inbox and one handled conversation

The console on a development store with sample customers. The full three minute walkthrough regenerates from docs/demo-video.md.

A customer-support agent for a Shopify store. It looks up orders and products through the Admin GraphQL API. It answers from the store's own policy file. It hands anything it should not decide to a person. Built as a working proof of the first of the five agents in an e-commerce AI-agent brief: support.

Register: built, tested and run live against a Shopify development store with sample customers. It runs locally, on one platform (Shopify). The human handoff produces a ticket-shaped payload. Wiring it to a helpdesk is the next step. Enquiry routing, the chat widget, the Zoho MCP server, the Zia client and the Claude API, watsonx.ai and xAI Grok providers are built and tested against stand-in servers. The servers are written from the vendors' saved documentation pages.

What it does

SupportAgent.handle(message, email) runs in a fixed order, and the order is the design:

  1. Escalation floor first. A legal threat, a chargeback, a safety report or a request for a person is matched in code before the model sees the message. The model also gets a vote (angry, wants a human). It can only add escalations, never remove one.
  2. Triage (the model): intent, order number, product query. It never sees order data.
  3. Facts come from Shopify and policy.md, never from the model's memory. Orders are identity-checked. The email on the message must match the email on the order.
  4. The model writes the wording only. A grounding guard refuses a reply that contains a figure not in the facts (digits and numbers written as words). It refuses a commitment the agent has no authority to make (refund, discount, replacement). It refuses an outcome the facts do not state ("the tracking details were emailed to you").
  5. Anything that fails ends in a person. That covers a store outage, a model outage and a reply that fails the guard twice. A failed lookup is never reported as "no such order".
  6. Every turn is logged (logs/audit.jsonl): intent, order, decision, escalation reason, steps. Emails are masked.

Proof

./.venv/Scripts/python.exe -m pytest tests -q              # 1620 tests, offline (scripted model, stand-in shop, Zoho, Discord, WhatsApp, Notion, Google Calendar, Claude API, IBM watsonx.ai and xAI; the widget tests drive Chromium and skip without it)
./.venv/Scripts/python.exe tests/mutation_check.py         # 587 mutants: each guard broken on purpose
./.venv/Scripts/python.exe demo.py                         # nine messages, live store + live model
./.venv/Scripts/python.exe demo_memory.py                  # five turns with memory, live store + model + Postgres
./.venv/Scripts/python.exe demo_enquiry.py                 # five enquiries, scripted model + fake Zoho
./.venv/Scripts/python.exe demo_mcp.py                      # the MCP server over stdio against the fake Zoho
  • Mutation harness: each of 587 guards (the per-feature counts are in docs/mutation-groups.md) is deleted from the real source. The suite is run. The file is restored byte-exact. All 587 mutants are caught.
  • Live transcript: demo_transcript.md. Nine messages including three hostile ones (a refund demand, a prompt injection asking for a 50% discount code, a legal threat). 7 answered and 2 escalated. No promise, invented figure or foreign order detail reached a customer. Details: docs/live-runs.md.
  • Through n8n: n8n/workflow.json (webhook, agent, "needs a person?" branch, handoff ticket, reply) was imported into a real n8n 2.41.6 server. It was called over its webhook with an answered message, a wrong-email message and a legal threat.

Customer memory

The agent remembers returning customers, and the design is about what memory is not allowed to do. It never supplies a fact: orders, prices and tracking are read live every turn. Isolation is forced row level security per store. The rules, the proof commands and the live run are in docs/customer-memory.md.

Enquiry routing and Zoho CRM lead capture (tested against a stand-in Zoho)

It works for a sales site as well as a shop. The agent sorts each enquiry and routes it to an owner queue. With the visitor's explicit yes, it puts the enquiry in Zoho CRM as a Lead, a follow-up Task and a Note. Details and the vendor citations are in docs/enquiry-routing.md; the Zoho pages are saved in docs/vendor-contract/.

  • Same order as above. The escalation floor runs first. The model only proposes an intent from a fixed list of seven, code checks it, and anything unlisted becomes human_needed. A routing table in code gives the owner queue and the follow-up.
  • Consent is code, not the model. The agent asks once whether it may pass the visitor's details to the team. Only an explicit yes in the visitor's own message, after the question, counts ("yes but don't share my phone" does not).
  • A lead is only what the visitor wrote, once a day. Fields are validated, card-like numbers are dropped, and a stable idempotency key stops a retry from creating twice. The reply is final before Zoho is called, and the audit log holds counts and kinds, never the visitor's words or email. Retries, token refresh and the Australian region (ZOHO_REGION=au) are in docs/enquiry-routing.md.
./.venv/Scripts/python.exe -m pytest tests -q       # tests/test_enquiry.py, test_zoho_crm.py and test_leads_property.py (seeded random worlds with faults)
./.venv/Scripts/python.exe demo_enquiry.py          # transcript in demo_enquiry_transcript.md

Scope and next steps. Built and tested against a stand-in that follows the saved Zoho pages. The limits and the next step are in docs/enquiry-routing.md.

One chat widget for two websites, a Zoho MCP server and a Zia client (tested against stand-ins)

  • Widget. One script tag (data-site) and vanilla JavaScript in a Shadow DOM, served by serve.py for several websites. Each site is a tenant with its own theme, origins, routing table and Zoho settings. Guards (per-origin CORS, signed conversation ids, rate limits, text-only rendering) and the Chromium tests at 1280 and 360 pixels are in docs/chat-widget.md
  • MCP server. Five tools over the lead desk and the Zoho client, on the official mcp SDK over stdio. Schemas are strict. Credentials come from the environment only. Every write takes confirm and an idempotency key. Answers are small. CRM text is returned as data. Zoho hosts its own MCP servers. This one adds tenant routing and consent. docs/zoho-mcp.md
  • Zia Agents client. The Agent API is documented enough (endpoint, headers, body, answer, OAuth). So a small client with a fake is built from the saved pages. Nothing else is guessed. There are no retries and no error shapes.
./.venv/Scripts/python.exe -m pytest tests/test_widget_browser.py tests/test_mcp_stdio.py -q   # Chromium and a child process
./.venv/Scripts/python.exe demo_widget.py                                                      # the two demo sites on :8101 and :8102

Scope and next steps. Tested against stand-in Zoho and Zia servers and the two demo sites. The limits are in docs/chat-widget.md.

WhatsApp, Discord and Notion lanes: a customer message in, a staff ticket out (tested against stand-ins)

A WhatsApp message reaches the agent and the reply goes back. An escalated turn posts one staff message in Discord with Take and Resolve buttons and one row in a Notion ticket log, and a click moves the row's status. Each answers a retried delivery once and keeps customer words and contact details out of logs and the staff channel. WhatsApp, Discord, Notion

./.venv/Scripts/python.exe -m pytest tests/test_whatsapp_lane.py tests/test_discord_handoff.py tests/test_notion_log.py -q   # 223 tests, 120 seeded random worlds
./.venv/Scripts/python.exe tests/mutation_check.py Notion                                                                   # 14 mutants (WhatsApp 17, Discord 19), all caught

Scope and next steps. Tested against stand-ins written from the saved vendor pages. Next: a live run of each. Not wired into serve.py.

Appointment booking on Google Calendar (tested against a stand-in, run once for real)

A visitor asks for an appointment, the agent offers the next three free times, takes a pick and a name, and books one event. It reads free/busy again right before the write, looks an event up after a lost answer instead of sending it twice, and never treats a calendar Google could not read as free. Every reply is written in code from the calendar's own times. Details

./.venv/Scripts/python.exe -m pytest tests/test_gcal_booking.py -q   # 124 tests, 40 seeded random worlds
./.venv/Scripts/python.exe tests/mutation_check.py GCal               # 54 mutants, all caught

Scope and next steps. Tested against a stand-in, and run once for real on a temporary calendar that was deleted afterwards (record). The OAuth exchange is the caller's. Not wired into serve.py.

Claude API, watsonx.ai and xAI Grok providers (tested against stand-ins)

LLM_PROVIDER=anthropic answers with Anthropic's Claude API (claude-sonnet-5-5), watsonx with IBM watsonx.ai and xai with xAI's Grok (grok-4.7) instead of Groq, which stays the default. One switch moves every path, so the grounding guard and the escalation floor judge any provider's reply as they judge a Groq one.

All three are plain HTTP clients with no vendor SDK. Each failure is a named error that ends in a person, and the key is kept out of every message. Written from each vendor's documentation and tested against stand-in servers I wrote from the saved pages. The watsonx.ai and xAI providers take a live key in WATSONX_API_KEY and XAI_API_KEY. Status tables and open items: Claude, watsonx, xAI Grok. The last also covers agent/xai_imagine.py, a small Grok Imagine client for images and image to video, a library not wired into the agent.

LLM_PROVIDER=xai XAI_API_KEY=... ./.venv/Scripts/python.exe -m uvicorn serve:app --port 8008   # or anthropic with ANTHROPIC_API_KEY, or watsonx with WATSONX_API_KEY and WATSONX_PROJECT_ID
./.venv/Scripts/python.exe -m pytest tests/test_anthropic_llm.py tests/test_anthropic_chat_path.py -q   # 142 tests against the Claude stand-in
./.venv/Scripts/python.exe -m pytest tests/test_watsonx_llm.py tests/test_watsonx_chat_path.py -q      # 211 tests against the IBM stand-in
./.venv/Scripts/python.exe -m pytest tests/test_xai_llm.py tests/test_xai_chat_path.py tests/test_xai_imagine.py -q   # 437 tests against the xAI stand-in
./.venv/Scripts/python.exe tests/mutation_check.py "Claude API"                                         # 74 mutants for the Claude provider
./.venv/Scripts/python.exe tests/mutation_check.py "watsonx"                                            # 120 mutants for the watsonx provider
./.venv/Scripts/python.exe tests/mutation_check.py xAI                                                  # 158 mutants for the xAI code

The support console (login, roles, many stores)

A web console around the same engine. A team can use it, and a new store is a new row rather than a new build. console_api/ (FastAPI) holds the rules. console_web/ (Next.js) is the screen.

Sign in with email and password as an admin (everything for a store, the audit log, the policy editor) or an agent (inbox, handoffs, live chat, lookup). One person can belong to several stores. Tenant isolation is Postgres row level security, enabled and forced. The API connects as a role that cannot bypass it. Roles, pages, login rules, the demo logins and how to point it at another store are in docs/support-console.md.

docker run -d --name support-console-pg -e POSTGRES_PASSWORD=localsuper -e POSTGRES_DB=console -p 54931:5432 postgres:17
./.venv/Scripts/python.exe -m console_api.migrate --reset        # schema, roles, forced RLS
./.venv/Scripts/python.exe -m console_api.seed                   # demo stores, two logins, a week of conversations
CONSOLE_ALLOWED_ORIGINS=http://localhost:3100 ./.venv/Scripts/python.exe -m uvicorn console_api.main:app --port 8010
cd console_web && npm install && npx next dev --port 3100        # then open http://localhost:3100
./.venv/Scripts/python.exe -m pytest tests_console -q             # 63 tests: isolation, roles, login, the API, customer memory
./.venv/Scripts/python.exe tests_console/mutation_check.py        # 22 mutants: each database rule broken on purpose
cd console_web && node tests/e2e.js                               # 37 browser checks at 1280 and 390, both roles

Run the engine and console suites as two commands, not one. Two conftest.py files collide. The mutation harness rebuilds the local console database. Reseed afterwards and run it only against that local database.

Scope and next steps

  • The console runs locally, and its session lockout counters are in memory (one process).
  • The guard checks figures, a list of commitment phrases and unsupported outcomes, so other wording claims rely on the prompt and on human review of escalations. Policy retrieval is word overlap over a handful of sections, and out-of-scope messages are escalated, which costs more human work than a looser agent would.
  • Zoho CRM is the one CRM, tested against a stand-in server. Klaviyo, Gorgias, Zendesk, HubSpot, Salesforce and the ad platforms are possible next connectors.
  • Memory. API and agent only; a console screen is next. It costs one extra model call per answered turn (docs/customer-memory.md).

Run it

python -m venv .venv && ./.venv/Scripts/python.exe -m pip install -r requirements.txt
# keys: GROQ_API_KEY, SHOPIFY_SHOP, SHOPIFY_ACCESS_TOKEN in the environment (or the saved secret files, see agent/config.py)
# for Claude, watsonx.ai or xAI Grok instead of Groq: LLM_PROVIDER and that provider's key, see the providers section
./.venv/Scripts/python.exe seed_fulfillment.py              # marks one dev-store order shipped with tracking
SUPPORT_AGENT_KEY=demo-key ./.venv/Scripts/python.exe -m uvicorn serve:app --port 8008

About

A support and enquiry-routing agent for a Shopify store: grounded answers, human hand-off, per-store memory, consent-gated lead capture into Zoho CRM. Built and tested against fakes and a development store.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages