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 close in the assistant's own words, never in silence (PR 1984)

Tim Gutberletd5602ff100a6
diff --git a/apps/agent/src/assistant-tools.ts b/apps/agent/src/assistant-tools.ts
index 33c77691..e6c3adaa 100644
--- a/apps/agent/src/assistant-tools.ts
+++ b/apps/agent/src/assistant-tools.ts
@@ -18,9 +18,9 @@ import { transferTool } from './transfer-tool.ts'
* A tool that saves something (a booking, the urgent flag): from its start the caller can't interrupt the
* turn, so an interruption never cancels the tool after the API saved and the assistant always hears the result.
*/
-/** end_call on an outbound call (LIN-873): it hangs up at once, the assistant has said goodbye in its own words. */
+/** end_call on an outbound call (LIN-873): the closing flow (closingFlow) with the outbound closing question. */
export const OUTBOUND_END_CALL =
- '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.'
+ 'End the call, once you closed in your own words, asked whether they have anything else and they have nothing; it says goodbye if you did not and hangs up. Called before that, it first asks them whether there is anything else. Never in the same response as another tool.'
export function saving(opts: llm.ToolOptions): void {
opts.ctx.disallowInterruptions()
diff --git a/apps/agent/src/hang-up.ts b/apps/agent/src/hang-up.ts
index f550c86a..ae9b3148 100644
--- a/apps/agent/src/hang-up.ts
+++ b/apps/agent/src/hang-up.ts
@@ -23,9 +23,8 @@ 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.'
+/** end_call's answer on an outbound call when it asked the closing question first (LIN-873). */
+export const OUTBOUND_END_CALL_ASKED = 'The person was asked whether there is anything else. Wait for their answer.'
export const END_CALL_ENDS = 'The goodbye is said and the call ends. Say nothing.'
/**
diff --git a/apps/agent/src/outbound-call.test.ts b/apps/agent/src/outbound-call.test.ts
index 3440e55b..f1850dbd 100644
--- a/apps/agent/src/outbound-call.test.ts
+++ b/apps/agent/src/outbound-call.test.ts
@@ -74,3 +74,21 @@ test("outbound instructions follow the assistant's AI disclosure: no AI in role
expect(open).not.toContain('say truthfully')
expect(open).toContain('never claim to be human')
})
+
+test('outbound closing: the assistant\'s own "anything else?" counts, so the next end_call hangs up (no silent turn)', async () => {
+ const { closingFlow, asksAnythingElse } = await import('./hang-up.ts')
+ const { spokenLines, languageCodes } = await import('@linedesk/actions')
+ // Production call_5d5865d25bd84158aa1f: the model asked it in its own words, then called end_call without words.
+ const flow = closingFlow()
+ flow.assistantSaid('a1', 'Für zwei Personen. Geht das?')
+ flow.assistantSaid('a2', 'Super, vielen Dank, dann bis 20 Uhr! Haben Sie sonst noch etwas?')
+ expect(flow.step(new Set(['a3']))).toBe('hang_up')
+ // Not asked yet: end_call asks first.
+ const early = closingFlow()
+ early.assistantSaid('a1', 'Ich rufe an, um einen Tisch zu reservieren. Ist das möglich?')
+ expect(early.step()).toBe('ask')
+ for (const code of languageCodes) {
+ const line = spokenLines(code).outboundAnythingElse
+ if (line) expect(asksAnythingElse(line), code).toBe(true)
+ }
+})
diff --git a/apps/agent/src/worker.ts b/apps/agent/src/worker.ts
index 641d948a..b6da2582 100644
--- a/apps/agent/src/worker.ts
+++ b/apps/agent/src/worker.ts
@@ -588,7 +588,7 @@ async function converse(
})
let ending = false
let asking = false
- const askAnythingElse = async (toolReply: Reply | null) => {
+ const askAnythingElse = async (toolReply: Reply | null, line = lines().anythingElse) => {
asking = true
try {
if (toolReply) await playedOut(toolReply)
@@ -596,7 +596,7 @@ async function converse(
// The model asked it itself, or asked something else the caller answers first (LIN-341): no second question.
if (words && (asksAnythingElse(words) || asksCaller(words))) return
closing.questionComing(idsOf(toolReply))
- await speak(lines().anythingElse)
+ await speak(line)
} finally {
asking = false
}
@@ -625,22 +625,20 @@ async function converse(
session.input.setAudioEnabled(true)
})
}
- let outboundClosingAsked = false
+ // An outbound call's closing question (LIN-873): everything is done on its side, thanks, anything else?
+ const outboundAnythingElse = () => lines().outboundAnythingElse ?? lines().anythingElse
const endCall = (toolReply: Reply, voicemail = false): string => {
if (ending || asking) return END_CALL_ASKED
- // 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
- }
+ // An outbound call (LIN-873): the same closing flow as inbound calls, with its own question. end_call hangs up only
+ // right after that question was asked and answered (the model's own words count); else it says the question first,
+ // so the call never goes silent. A voicemail hangs up at once.
+ if (call.outbound && voicemail) {
hangUp(toolReply)
return END_CALL_ENDS
}
if (closing.step(idsOf(toolReply)) === 'ask') {
- void askAnythingElse(toolReply)
- return END_CALL_ASKED
+ void askAnythingElse(toolReply, call.outbound ? outboundAnythingElse() : undefined)
+ return call.outbound ? OUTBOUND_END_CALL_ASKED : END_CALL_ASKED
}
hangUp(toolReply)
return END_CALL_ENDS
@@ -648,10 +646,8 @@ 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) {
- // 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)
+ if (closing.step(new Set([id])) === 'ask')
+ void askAnythingElse(null, call.outbound ? outboundAnythingElse() : undefined)
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
diff --git a/packages/actions/src/call-prompt.ts b/packages/actions/src/call-prompt.ts
index 5f1a29fa..dd1f9c1a 100644
--- a/packages/actions/src/call-prompt.ts
+++ b/packages/actions/src/call-prompt.ts
@@ -597,7 +597,7 @@ export function buildOutboundInstructions(
honesty,
`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, 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.',
+ '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, close in your own words as fits the call (for example, confirm what was agreed and 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 34dc8013..d8e533b8 100644
--- a/packages/actions/src/spoken-lines.ts
+++ b/packages/actions/src/spoken-lines.ts
@@ -19,6 +19,8 @@ export type SpokenLines = {
goodbye: string
/** The goodbye of an outbound call (LIN-873): the person did not call, so no "thanks for calling". Missing: `goodbye`. */
outboundGoodbye?: string
+ /** An outbound call's closing question (LIN-873): everything is done, thanks, anything else? Said when end_call came first without it. */
+ outboundAnythingElse?: 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
@@ -76,6 +78,7 @@ const en: SpokenLines = {
consentQuestion: 'Is that okay with you?',
goodbye: 'Thanks for calling. Goodbye!',
outboundGoodbye: 'Thank you for your time. Goodbye!',
+ outboundAnythingElse: 'Thank you! Is there anything else?',
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?',
@@ -113,6 +116,7 @@ const es: SpokenLines = {
consentQuestion: '¿Le parece bien?',
goodbye: 'Gracias por llamar. ¡Adiós!',
outboundGoodbye: 'Gracias por su tiempo. ¡Adiós!',
+ outboundAnythingElse: '¡Muchas gracias! ¿Hay algo má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?',
@@ -150,6 +154,7 @@ const fr: SpokenLines = {
consentQuestion: 'Cela vous convient-il ?',
goodbye: "Merci d'avoir appelé. Au revoir !",
outboundGoodbye: 'Merci pour votre temps. Au revoir !',
+ outboundAnythingElse: 'Merci beaucoup ! Y a-t-il autre chose ?',
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 ?',
@@ -197,6 +202,7 @@ const de: SpokenLines = {
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!',
+ outboundAnythingElse: 'Vielen Dank! Gibt es sonst noch etwas?',
stillThere: 'Sind Sie noch da?',
stillChecking: 'Das dauert etwas länger, ich bin noch dran.',
anythingElse: 'Kann ich Ihnen sonst noch mit etwas helfen?',
@@ -246,6 +252,7 @@ const it: SpokenLines = {
consentQuestion: 'Le va bene?',
goodbye: 'Grazie per aver chiamato. Arrivederci!',
outboundGoodbye: 'Grazie per il suo tempo. Arrivederci!',
+ outboundAnythingElse: "Grazie mille! C'è qualcos'altro?",
stillThere: 'È ancora in linea?',
stillChecking: 'Ci vuole un po’ più del previsto, ci sto ancora lavorando.',
anythingElse: "Posso aiutarla con qualcos'altro?",
@@ -282,6 +289,7 @@ const pt: SpokenLines = {
consentQuestion: 'Tudo bem para você?',
goodbye: 'Obrigado por ligar. Até logo!',
outboundGoodbye: 'Obrigado pelo seu tempo. Até logo!',
+ outboundAnythingElse: 'Muito obrigado! Há mais alguma coisa?',
stillThere: 'Você ainda está aí?',
stillChecking: 'Está demorando um pouco mais, ainda estou verificando.',
anythingElse: 'Posso ajudar com mais alguma coisa?',
@@ -318,6 +326,7 @@ const nl: SpokenLines = {
consentQuestion: 'Is dat goed voor u?',
goodbye: 'Bedankt voor het bellen. Tot ziens!',
outboundGoodbye: 'Bedankt voor uw tijd. Tot ziens!',
+ outboundAnythingElse: 'Hartelijk bedankt! Is er nog iets anders?',
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?',