The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
Shopify on calls: the order search uses the caller's confirmed name; the order's state comes before general shipping text (PR 2035)
Tim Gutberlet0a04ffa20fb6
diff --git a/apps/agent/src/llm-test/cases.ts b/apps/agent/src/llm-test/cases.tsindex ff2b0bdd..3bba379b 100644--- a/apps/agent/src/llm-test/cases.ts+++ b/apps/agent/src/llm-test/cases.ts@@ -1555,6 +1555,73 @@ export const CASES: Case[] = [},severity: 'must',},+ {+ id: 'shop-status-name-said',+ category: 'shop',+ title: 'Order status: the caller said only their name, in the first turn',+ why: 'shopifyInstructions: looking up orders needs no check; the name the caller said is enough to search',+ setup: setup({ shopify: true }),+ turns: english(['Hi, this is Dana Ruiz. Where is my order, has it shipped yet?']),+ checks: [+ { type: 'tool', tool: 'find_orders', byTurn: 1 },+ { type: 'toolResult', tool: 'find_orders', pattern: /Order #1042/ },+ ],+ judge: {+ must: [+ 'answer about the orders the store has under that name (two: #1042 not shipped yet, #1038 delivered; naming one or both is fine), or ask which of them is meant',+ ],+ mustNot: [+ 'ask for the name again, the postcode or another detail without having found the orders',+ 'say no order was found',+ ],+ },+ severity: 'must',+ },+ {+ id: 'shop-status-name-said-withheld',+ category: 'shop',+ title: 'Order status by the name alone, caller number withheld',+ why: 'shopifyInstructions: looking up orders needs no check; the name the caller said is enough to search',+ setup: setup({ shopify: true, caller: 'withheld' }),+ turns: english(['Hi, this is Dana Ruiz. Where is my order, has it shipped yet?']),+ checks: [+ { type: 'tool', tool: 'find_orders', byTurn: 1 },+ { type: 'toolResult', tool: 'find_orders', pattern: /Order #1042/ },+ ],+ judge: {+ must: [+ 'answer about the orders the store has under that name (two: #1042 not shipped yet, #1038 delivered; naming one or both is fine), or ask which of them is meant',+ ],+ mustNot: [+ 'ask for the name again, the postcode or another detail without having found the orders',+ 'say no order was found',+ ],+ },+ severity: 'must',+ },+ {+ id: 'shop-status-name-said-german',+ category: 'shop',+ title: 'Order status by the name alone, in German',+ why: 'shopifyInstructions: looking up orders needs no check; the name the caller said is enough to search',+ setup: setup({ shopify: true, assistant: { languages: { main: 'en', mode: 'any', allowed: [] } } }),+ turns: [{ say: 'Hallo, hier ist Dana Ruiz. Wo ist meine Bestellung, ist sie schon verschickt?', lang: 'de' }],+ checks: [+ { type: 'tool', tool: 'find_orders', byTurn: 1 },+ { type: 'toolResult', tool: 'find_orders', pattern: /Order #1042/ },+ { type: 'language', lang: 'de' },+ ],+ judge: {+ must: [+ 'answer about the orders the store has under that name (two: #1042 not shipped yet, #1038 delivered; naming one or both is fine), or ask which of them is meant',+ ],+ mustNot: [+ 'ask for the name again, the postcode or another detail without having found the orders',+ 'say no order was found',+ ],+ },+ severity: 'must',+ },{id: 'shop-not-found-searches-first',category: 'shop',diff --git a/apps/agent/src/shopify-tools.test.ts b/apps/agent/src/shopify-tools.test.tsindex 5fe24cdb..e33b4a22 100644--- a/apps/agent/src/shopify-tools.test.ts+++ b/apps/agent/src/shopify-tools.test.ts@@ -1,9 +1,10 @@import { describe, expect, it } from 'vitest'import {callerSaid,- readBack,changeReply,findOrdersReply,+ orderSearch,+ readBack,shopifyInstructions,storeOrderCall,} from './shopify-tools.ts'@@ -52,6 +53,23 @@ describe('store instructions', () => {})})+describe('order search', () => {+ it('adds the name confirmed in the call to a search without one', () => {+ expect(orderSearch({ caller_number: true }, 'Dana Ruiz')).toEqual({ name: 'Dana Ruiz', callerNumber: true })+ expect(orderSearch({ phone: '+15035550142', name: '' }, 'Dana Ruiz')).toEqual({+ phone: '+15035550142',+ name: 'Dana Ruiz',+ })+ })+ it('keeps the name the model gave (an order under another name) and adds none when none is confirmed', () => {+ expect(orderSearch({ order_number: '1001', name: 'Mike Brennan' }, 'Dana Ruiz')).toEqual({+ orderNumber: '1001',+ name: 'Mike Brennan',+ })+ expect(orderSearch({ order_number: '1001', status: null }, undefined)).toEqual({ orderNumber: '1001' })+ })+})+describe('tool replies', () => {it('ask which order when several fit', () => {expect(findOrdersReply({ orders: [order, { ...order, number: '#1002' }], problem: null })).toContain(diff --git a/apps/agent/src/shopify-tools.ts b/apps/agent/src/shopify-tools.tsindex d82b5811..78f266dd 100644--- a/apps/agent/src/shopify-tools.ts+++ b/apps/agent/src/shopify-tools.ts@@ -147,6 +147,35 @@ export function storeOrderCall(log: Pick<CallLog, 'storeOrder' | 'lines'>): boolreturn log.storeOrder || log.lines.some(line => line.speaker === 'caller' && STORE_ORDER_WORDS.test(line.text))}+type OrderSearchArgs = {+ order_number?: string | null+ email?: string | null+ name?: string | null+ postcode?: string | null+ phone?: string | null+ caller_number?: boolean | null+ status?: string | null+}++/**+ * What find_orders sends to the store. A search the model made without a name also gets the name the caller+ * confirmed in this call (get_name): models often search by the phone number alone and then ask for the name again.+ * The store searches everything together first and each detail alone after that, so the name never hides an order.+ */+export function orderSearch(args: OrderSearchArgs, confirmedName: string | undefined) {+ return {+ ...unset({+ orderNumber: args.order_number,+ email: args.email,+ name: args.name || confirmedName,+ postcode: args.postcode,+ phone: args.phone,+ status: args.status,+ }),+ ...(args.caller_number ? { callerNumber: true } : {}),+ }+}+export function shopifyTools(api: ApiClient, call: CallSession, log: CallLog): Tools {const setup = call.shopifyif (!setup) return {}@@ -167,17 +196,12 @@ export function shopifyTools(api: ApiClient, call: CallSession, log: CallLog): T}),execute: async (args, opts) => {log.storeOrder = true- const data = await run<ShopifyFindOrdersData>(api, call, shopifyFindOrders, {- ...unset({- orderNumber: args.order_number,- email: args.email,- name: args.name,- postcode: args.postcode,- phone: args.phone,- status: args.status,- }),- ...(args.caller_number ? { callerNumber: true } : {}),- })+ const data = await run<ShopifyFindOrdersData>(+ api,+ call,+ shopifyFindOrders,+ orderSearch(args, log.confirmedName),+ )log.record('system',log.words.t(data?.orders.length ? 'call.event.shopify.orders' : 'call.event.shopify.noOrder'),diff --git a/packages/actions/src/shopify-call-text.ts b/packages/actions/src/shopify-call-text.tsindex d8ecff18..d4ce4d93 100644--- a/packages/actions/src/shopify-call-text.ts+++ b/packages/actions/src/shopify-call-text.ts@@ -108,8 +108,8 @@ export function findOrdersReply(data: ShopifyFindOrdersData | null): string {return [fenced(data.orders.map(orderText).join('\n')),data.orders.length > 1- ? 'If more than one order fits, answer about the one the caller already named (by number, date or items); ask which one they mean only when that does not settle it.'- : 'Tell the caller what it means for them, in your own words.',+ ? 'If more than one order fits, tell the caller the state of the one they already named (by number, date or items); ask which one they mean only when that does not settle it. What the owner wrote about shipping in general does not replace it.'+ : 'Tell the caller the state of this order, in your own words. What the owner wrote about shipping in general does not replace it.',].join('\n')}