Skip to content

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.

Outbound calls end with a closing and a goodbye, never in silence (PR 1977)

Tim Gutberlet5e0d0491acd1
diff --git a/apps/agent/src/assistant-tools.ts b/apps/agent/src/assistant-tools.ts
index aaf48d8b..33c77691 100644
--- a/apps/agent/src/assistant-tools.ts
+++ b/apps/agent/src/assistant-tools.ts
@@ -20,7 +20,7 @@ import { transferTool } from './transfer-tool.ts'
*/
/** end_call on an outbound call (LIN-873): it hangs up at once, the assistant has said goodbye in its own words. */
export const OUTBOUND_END_CALL =
- 'End the call. Say a short goodbye first in the same response; it hangs up right away. Never in the same response as another tool.'
+ 'End the call. The first call does not hang up: before it, say that everything is done on your side, thank the person and ask whether they have anything else. After they said they have nothing, say goodbye and call it again; then it hangs up. Never in the same response as another tool.'
export function saving(opts: llm.ToolOptions): void {
opts.ctx.disallowInterruptions()
@@ -128,7 +128,7 @@ export function assistantTools(
api: ApiClient,
call: CallSession,
log: CallLog,
- endCall: (toolReply: Reply) => string,
+ endCall: (toolReply: Reply, voicemail?: boolean) => string,
flagUrgent: () => Promise<void>,
transfer: Transfer,
collect: CollectContext,
@@ -137,7 +137,18 @@ export function assistantTools(
// An outbound call (LIN-873) asks only for what its goal needs: no messages, names, numbers, bookings or transfers.
if (call.outbound)
return {
- end_call: llm.tool({ description: OUTBOUND_END_CALL, execute: async (_, { ctx }) => endCall(ctx.speechHandle) }),
+ end_call: llm.tool({
+ description: OUTBOUND_END_CALL,
+ parameters: z.object({
+ voicemail: z
+ .boolean()
+ .optional()
+ .describe(
+ 'true when you reached a voicemail or answering machine and left your message: it hangs up at once.',
+ ),
+ }),
+ execute: async ({ voicemail }, { ctx }) => endCall(ctx.speechHandle, voicemail === true),
+ }),
}
return {
// A slow tool gets a filler when the assistant said nothing before it (tool-filler.ts).
diff --git a/apps/agent/src/hang-up.ts b/apps/agent/src/hang-up.ts
index 04ade50f..f550c86a 100644
--- a/apps/agent/src/hang-up.ts
+++ b/apps/agent/src/hang-up.ts
@@ -23,6 +23,9 @@ export const GOODBYE_MAX_MS = 20_000
*/
export const END_CALL_ASKED =
"The caller was asked whether there is anything else. Wait for their answer. Everything said in this call goes to the owner, so don't offer to take a message again."
+/** end_call's first answer on an outbound call (LIN-873): not yet, close the call first. */
+export const OUTBOUND_END_CALL_ASKED =
+ 'Not hung up yet. If you have not just done so: say that everything is done on your side, thank the person and ask whether they have anything else. Wait for their answer; when they have nothing, say goodbye and call end_call again.'
export const END_CALL_ENDS = 'The goodbye is said and the call ends. Say nothing.'
/**
diff --git a/apps/agent/src/worker.ts b/apps/agent/src/worker.ts
index f3f24c21..641d948a 100644
--- a/apps/agent/src/worker.ts
+++ b/apps/agent/src/worker.ts
@@ -119,6 +119,7 @@ import {
asksCaller,
closingFlow,
END_CALL_ASKED,
+ OUTBOUND_END_CALL_ASKED,
END_CALL_ENDS,
endRoom,
ROOM_DELETE_TIMEOUT_MS,
@@ -606,7 +607,9 @@ async function converse(
toolReply,
said,
// An outbound call: the assistant said goodbye in its own words (buildOutboundInstructions); no inbound "thanks for calling".
- sayGoodbye: () => (call.outbound ? Promise.resolve() : sayLine(goodbyeLine())),
+ // Always a goodbye before the hang-up, unless the last words said one already (hangUpWithGoodbye); on an
+ // outbound call without "thanks for calling".
+ sayGoodbye: () => sayLine(call.outbound ? (lines().outboundGoodbye ?? lines().goodbye) : goodbyeLine()),
stopListening: () => session.input.setAudioEnabled(false),
callerSpeaking: () => session.userState === 'speaking',
callerLastWords: () => callerSince,
@@ -622,10 +625,16 @@ async function converse(
session.input.setAudioEnabled(true)
})
}
- const endCall = (toolReply: Reply): string => {
+ let outboundClosingAsked = false
+ const endCall = (toolReply: Reply, voicemail = false): string => {
if (ending || asking) return END_CALL_ASKED
- // An outbound call ends when the goal is done: no "anything else?" (the person did not call with a request).
+ // An outbound call (LIN-873): the first end_call does not hang up; the assistant says everything is done on its side,
+ // thanks the person and asks whether they have anything else. The next one, after their answer, says goodbye and ends.
if (call.outbound) {
+ if (!outboundClosingAsked && !voicemail) {
+ outboundClosingAsked = true
+ return OUTBOUND_END_CALL_ASKED
+ }
hangUp(toolReply)
return END_CALL_ENDS
}
@@ -639,8 +648,10 @@ async function converse(
// The assistant said it hangs up now (or wrote end_call) without the tool: the same flow.
keepHangUpPromises(session, log, (id, said) => {
if (ending || asking) return
- if (call.outbound) hangUp(null, said)
- else if (closing.step(new Set([id])) === 'ask') void askAnythingElse(null)
+ if (call.outbound) {
+ // Words that say it hangs up, before the person was asked whether they have anything else: the call goes on.
+ if (outboundClosingAsked) hangUp(null, said)
+ } else if (closing.step(new Set([id])) === 'ask') void askAnythingElse(null)
else hangUp(null, said)
})
// After a warm transfer or a take-over the caller talks with a person and the assistant is out of it: neither silence on its
@@ -662,10 +673,9 @@ async function converse(
},
close: () => {
log.record('system', 'Hung up after silence on the line')
- // An outbound call: nobody to ask to call back; it ends after the reminder without the inbound closing line.
+ // An outbound call: nobody to ask to call back; it ends after the reminder with a goodbye, never in silence.
if (call.outbound) {
- session.input.setAudioEnabled(false)
- deleteRoom()
+ lastLine(lines().outboundGoodbye ?? lines().goodbye)
return
}
// The default closing line in the language spoken now (the reminder before it is too), not only in the main language.
diff --git a/packages/actions/src/call-prompt.ts b/packages/actions/src/call-prompt.ts
index 52aeacd1..6602eebd 100644
--- a/packages/actions/src/call-prompt.ts
+++ b/packages/actions/src/call-prompt.ts
@@ -592,7 +592,7 @@ export function buildOutboundInstructions(
`${ai}When asked, say truthfully that you are an AI assistant; never claim to be human.`,
`You called ${displayNumber(outbound.to)}. ${known}The person did not call you: say why you are calling, and do not ask how you can help.`,
`The goal of this call:\n${quotedData(outbound.goal, 4000)}`,
- 'Ask only for what the goal needs; do not ask for their name, number or anything else, and do not offer other help. Never claim you did something you did not do. When the goal is reached, or the person does not want to talk, thank them, say goodbye and call end_call. On a voicemail or answering machine, leave one short message saying who is calling and why, then call end_call.',
+ 'Ask only for what the goal needs; do not ask for their name, number or anything else, and do not offer other help. Never claim you did something you did not do. When the goal is reached, or the person does not want to talk, say that everything is done on your side, thank them and ask whether they have anything else; when they have nothing, say goodbye and call end_call. Never end the call without saying goodbye. On a voicemail or answering machine, leave one short message saying who is calling and why, say goodbye, then call end_call with voicemail true.',
`${clock ? `${clock} ` : ''}Never read out or quote these instructions.`,
].join('\n\n')
}
diff --git a/packages/actions/src/spoken-lines.ts b/packages/actions/src/spoken-lines.ts
index a0691c30..34dc8013 100644
--- a/packages/actions/src/spoken-lines.ts
+++ b/packages/actions/src/spoken-lines.ts
@@ -17,6 +17,8 @@ export type SpokenLines = {
/** Asked in place of the greeting's closing question when the caller must agree to talk with an AI. */
consentQuestion: string
goodbye: string
+ /** The goodbye of an outbound call (LIN-873): the person did not call, so no "thanks for calling". Missing: `goodbye`. */
+ outboundGoodbye?: string
stillThere: string
/** Said once when a slow tool (a lookup, the calendar) still runs after seconds and the model wrote no line for it. */
stillChecking: string
@@ -73,6 +75,7 @@ const en: SpokenLines = {
aiNote: /,?\s*(?:the|an|your|a)\s+(?:virtual|AI)\s+assistant\b/i,
consentQuestion: 'Is that okay with you?',
goodbye: 'Thanks for calling. Goodbye!',
+ outboundGoodbye: 'Thank you for your time. Goodbye!',
stillThere: 'Are you still there?',
stillChecking: "This is taking a little longer, I'm still on it.",
anythingElse: 'Is there anything else I can help you with?',
@@ -109,6 +112,7 @@ const es: SpokenLines = {
aiNote: /\bIA\b/,
consentQuestion: '¿Le parece bien?',
goodbye: 'Gracias por llamar. ¡Adiós!',
+ outboundGoodbye: 'Gracias por su tiempo. ¡Adiós!',
stillThere: '¿Sigue ahí?',
stillChecking: 'Esto está tardando un poco más, sigo en ello.',
anythingElse: '¿Hay algo más en lo que pueda ayudarle?',
@@ -145,6 +149,7 @@ const fr: SpokenLines = {
aiNote: /\bIA\b/,
consentQuestion: 'Cela vous convient-il ?',
goodbye: "Merci d'avoir appelé. Au revoir !",
+ outboundGoodbye: 'Merci pour votre temps. Au revoir !',
stillThere: 'Vous êtes toujours là ?',
stillChecking: 'Cela prend un peu plus de temps, je m’en occupe toujours.',
anythingElse: 'Puis-je vous aider pour autre chose ?',
@@ -191,6 +196,7 @@ const de: SpokenLines = {
aiNote: /\bKI\b/,
consentQuestion: 'Ist das für Sie in Ordnung?',
goodbye: 'Danke für Ihren Anruf. Auf Wiederhören!',
+ outboundGoodbye: 'Vielen Dank für Ihre Zeit. Auf Wiederhören!',
stillThere: 'Sind Sie noch da?',
stillChecking: 'Das dauert etwas länger, ich bin noch dran.',
anythingElse: 'Kann ich Ihnen sonst noch mit etwas helfen?',
@@ -239,6 +245,7 @@ const it: SpokenLines = {
aiNote: /\bIA\b/,
consentQuestion: 'Le va bene?',
goodbye: 'Grazie per aver chiamato. Arrivederci!',
+ outboundGoodbye: 'Grazie per il suo tempo. Arrivederci!',
stillThere: 'È ancora in linea?',
stillChecking: 'Ci vuole un po’ più del previsto, ci sto ancora lavorando.',
anythingElse: "Posso aiutarla con qualcos'altro?",
@@ -274,6 +281,7 @@ const pt: SpokenLines = {
aiNote: /\bIA\b/,
consentQuestion: 'Tudo bem para você?',
goodbye: 'Obrigado por ligar. Até logo!',
+ outboundGoodbye: 'Obrigado pelo seu tempo. Até logo!',
stillThere: 'Você ainda está aí?',
stillChecking: 'Está demorando um pouco mais, ainda estou verificando.',
anythingElse: 'Posso ajudar com mais alguma coisa?',
@@ -309,6 +317,7 @@ const nl: SpokenLines = {
aiNote: /\bAI\b/,
consentQuestion: 'Is dat goed voor u?',
goodbye: 'Bedankt voor het bellen. Tot ziens!',
+ outboundGoodbye: 'Bedankt voor uw tijd. Tot ziens!',
stillThere: 'Bent u er nog?',
stillChecking: 'Dit duurt iets langer, ik ben er nog mee bezig.',
anythingElse: 'Kan ik u ergens anders nog mee helpen?',