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: wait for the greeting, short words do not interrupt, summary roles (PR 2000)

Tim Gutberlet29531d03a646
diff --git a/apps/agent/src/call-log.ts b/apps/agent/src/call-log.ts
index 301023d7..7bb94404 100644
--- a/apps/agent/src/call-log.ts
+++ b/apps/agent/src/call-log.ts
@@ -7,6 +7,8 @@ import {
type CollectedDetail,
type CompleteJson,
mergeToolResults,
+ type NotReachedReason,
+ notReachedResult,
summarizeCall,
type TranscriptLine,
unsummarizedResult,
@@ -66,6 +68,8 @@ export class CallLog {
timing: Omit<CallTimings, 'replies'> | null = null
/** The first stage of the voice pipeline that failed on this call ("tts"); null while it works. */
voiceFailed: VoiceStage | null = null
+ /** An outbound call that never connected (busy, not answered): why; null when the person picked up or on any other call. */
+ notReached: NotReachedReason | null = null
private pending: Promise<unknown>[] = []
private call: CallSession
@@ -125,12 +129,14 @@ export async function finishCall(
country: call.country,
})
const summary =
- silent && log.voiceFailed
- ? voiceFailedResult(log.voiceFailed, call.teamLanguage)
- : await summarizeWithRetry(call, log.lines, log, complete, callbackKnown, retry).catch(e => {
- console.error(`could not summarize call ${call.callId}, finishing it without a summary: ${message(e)}`)
- return unsummarizedResult(log.lines, log.messages, call.teamLanguage, log.details)
- })
+ silent && log.notReached
+ ? notReachedResult(log.notReached, call.teamLanguage)
+ : silent && log.voiceFailed
+ ? voiceFailedResult(log.voiceFailed, call.teamLanguage)
+ : await summarizeWithRetry(call, log.lines, log, complete, callbackKnown, retry).catch(e => {
+ console.error(`could not summarize call ${call.callId}, finishing it without a summary: ${message(e)}`)
+ return unsummarizedResult(log.lines, log.messages, call.teamLanguage, log.details)
+ })
const result = mergeToolResults(summary, log, callbackKnown, call.teamLanguage)
// A silent call has no caller line to correct.
const done = await withRetry(
diff --git a/apps/agent/src/outbound-call.test.ts b/apps/agent/src/outbound-call.test.ts
index c0e8487c..a734f950 100644
--- a/apps/agent/src/outbound-call.test.ts
+++ b/apps/agent/src/outbound-call.test.ts
@@ -51,12 +51,55 @@ test('outbound instructions: the goal, no inbound receptionist parts (messages,
test('the summary of an outbound call is told the goal and what the outcomes mean there', async () => {
const { summarySystem } = await import('./summary.ts')
- expect(summarySystem('en', 'Confirm the appointment.')).toMatch(
- /^This was an outbound call: .*"Confirm the appointment\."/,
- )
+ const system = summarySystem('en', 'Confirm the appointment.')
+ expect(system).toMatch(/^You summarize an outbound phone call.*"Confirm the appointment\."/)
+ expect(system).toContain('"outcome": one of answered, callback, hangup')
expect(summarySystem('en')).toMatch(/^You summarize a phone call/)
})
+test('the summary of an outbound call never calls the person phoned "the caller" (LIN-873)', async () => {
+ const { summarizeCall, summarySystem } = await import('./summary.ts')
+ // The assistant placed the call: the inbound text's "caller" would name the person phoned (production, 2026-11-28).
+ expect(summarySystem('de', 'Reserviere einen Tisch.')).not.toMatch(/caller(?!_name)/i)
+ expect(summarySystem('de', 'Reserviere einen Tisch.')).toContain('write "the person called"')
+ let request = ''
+ await summarizeCall(
+ [
+ { speaker: 'caller', text: 'Restaurant Kant, guten Tag.' },
+ { speaker: 'agent', text: 'Servus, ich würde gern einen Tisch reservieren.' },
+ ],
+ async (_system, user) => {
+ request = user
+ return JSON.stringify({ title: 't', summary: 's', outcome: 'answered', urgency: 'low' })
+ },
+ [],
+ 'de',
+ { outboundGoal: 'Reserviere einen Tisch.' },
+ )
+ expect(request).toBe(
+ 'Transcript:\nperson called: Restaurant Kant, guten Tag.\nassistant: Servus, ich würde gern einen Tisch reservieren.',
+ )
+})
+
+test('an outbound call that never connected says why it was not reached (LIN-873)', async () => {
+ const { notReachedReason, notReachedResult } = await import('./summary.ts')
+ expect(notReachedReason('SIP call failed: 486 Busy Here (unavailable)')).toBe('busy')
+ expect(notReachedReason('SIP call failed: 600 Busy Everywhere')).toBe('busy')
+ expect(notReachedReason('SIP call failed: 603 Decline')).toBe('declined')
+ expect(notReachedReason('SIP call failed: 480 Temporarily Unavailable')).toBe('noAnswer')
+ expect(notReachedReason('SIP call failed: 487 Request Terminated')).toBe('noAnswer')
+ expect(notReachedReason('twirp error deadline_exceeded')).toBe('noAnswer')
+ expect(notReachedReason('SIP call failed: 404 Not Found')).toBe('failed')
+ expect(notReachedReason('no outbound trunk: run setup-sip --outbound')).toBe('failed')
+ expect(notReachedResult('busy')).toEqual({
+ outcome: 'hangup',
+ urgency: 'low',
+ title: 'Not reached',
+ summary: 'Not reached: the line was busy.',
+ })
+ expect(notReachedResult('noAnswer').summary).toBe('Not reached: nobody answered.')
+})
+
test("outbound instructions follow the assistant's AI disclosure: no AI in role or call for Don't mention", () => {
const goal = { to: '+15035550123', goal: 'Book a table for two at eight.' }
const asAi = buildOutboundInstructions({ name: 'Maya', ai_disclosure: 'at_start' } as never, goal)
diff --git a/apps/agent/src/outbound-opening.test.ts b/apps/agent/src/outbound-opening.test.ts
new file mode 100644
index 00000000..22f56d37
--- /dev/null
+++ b/apps/agent/src/outbound-opening.test.ts
@@ -0,0 +1,93 @@
+import { afterEach, beforeEach, expect, test, vi } from 'vitest'
+import {
+ OPENING_MAX_MS,
+ OPENING_PAUSE_MS,
+ OPENING_SILENCE_MS,
+ type OpeningReason,
+ openingGate,
+} from './outbound-opening.ts'
+
+beforeEach(() => vi.useFakeTimers())
+afterEach(() => vi.useRealTimers())
+
+/** The gate and what it resolved with so far (null while it waits). */
+function gate() {
+ const g = openingGate()
+ const state: { reason: OpeningReason | null } = { reason: null }
+ void g.ready.then(reason => (state.reason = reason))
+ return { g, state }
+}
+const advance = async (ms: number) => vi.advanceTimersByTimeAsync(ms)
+
+test('nobody speaks after the pickup: the first sentence starts after the silence wait', async () => {
+ const { state } = gate()
+ await advance(OPENING_SILENCE_MS - 1)
+ expect(state.reason).toBeNull()
+ await advance(1)
+ expect(state.reason).toBe('silence')
+})
+
+test('the person greets: the first sentence waits for the end of their turn, which gets no reply of its own', async () => {
+ const { g, state } = gate()
+ await advance(300)
+ g.speaking(true)
+ g.heard()
+ await advance(OPENING_SILENCE_MS) // still talking past the silence wait
+ expect(state.reason).toBeNull()
+ expect(g.takeTurn()).toBe(true)
+ await advance(0)
+ expect(state.reason).toBe('turn')
+ // Later turns are answered as usual.
+ expect(g.takeTurn()).toBe(false)
+})
+
+test('the person greets and goes quiet without an end of turn: the first sentence starts after the pause', async () => {
+ const { g, state } = gate()
+ g.speaking(true)
+ await advance(1500)
+ g.speaking(false)
+ await advance(OPENING_PAUSE_MS - 1)
+ expect(state.reason).toBeNull()
+ // A late transcript of the same words starts the pause again.
+ g.heard()
+ await advance(OPENING_PAUSE_MS - 1)
+ expect(state.reason).toBeNull()
+ await advance(1)
+ expect(state.reason).toBe('pause')
+ expect(g.takeTurn()).toBe(false)
+})
+
+test('speaking again within the pause keeps the first sentence waiting', async () => {
+ const { g, state } = gate()
+ g.speaking(true)
+ g.speaking(false)
+ await advance(OPENING_PAUSE_MS - 100)
+ g.speaking(true)
+ await advance(OPENING_PAUSE_MS)
+ expect(state.reason).toBeNull()
+})
+
+test('a transcript without a speaking state counts as speech too', async () => {
+ const { g, state } = gate()
+ await advance(500)
+ g.heard()
+ await advance(OPENING_SILENCE_MS)
+ expect(state.reason).toBe('pause')
+})
+
+test('the person keeps talking: the first sentence starts at the longest wait', async () => {
+ const { g, state } = gate()
+ g.speaking(true)
+ await advance(OPENING_MAX_MS - 1)
+ expect(state.reason).toBeNull()
+ await advance(1)
+ expect(state.reason).toBe('longest')
+})
+
+test('closed (the call ended): nothing starts, and no turn is held', async () => {
+ const { g, state } = gate()
+ g.close()
+ await advance(OPENING_MAX_MS)
+ expect(state.reason).toBeNull()
+ expect(g.takeTurn()).toBe(false)
+})
diff --git a/apps/agent/src/outbound-opening.ts b/apps/agent/src/outbound-opening.ts
new file mode 100644
index 00000000..2dd97472
--- /dev/null
+++ b/apps/agent/src/outbound-opening.ts
@@ -0,0 +1,81 @@
+// When an outbound call's first sentence starts (LIN-873). The person who picks up usually greets first ("Restaurant
+// Kant, guten Tag"): the assistant waits for the end of that greeting instead of talking over it, and starts by itself
+// when nobody says anything. The person's greeting is kept in the conversation, but gets no reply of its own: the first
+// sentence is the answer to it.
+
+/** Nobody spoke this long after the pickup: the assistant starts. */
+export const OPENING_SILENCE_MS = 2_000
+/** Quiet this long after the person spoke, without an end of their turn: their greeting is over. */
+export const OPENING_PAUSE_MS = 1_000
+/** Longest the first sentence waits, also while the person keeps talking. */
+export const OPENING_MAX_MS = 8_000
+
+/** Why the first sentence started: nobody spoke, their turn ended, they went quiet, or the wait was at its longest. */
+export type OpeningReason = 'silence' | 'turn' | 'pause' | 'longest'
+
+export type OpeningGate = {
+ /** The person started (true) or stopped (false) speaking. */
+ speaking(on: boolean): void
+ /** A transcript of the person's words came in. */
+ heard(): void
+ /**
+ * The person's turn ended. True while the first sentence is still waiting: that turn (their greeting) starts no reply,
+ * and the first sentence starts now. False afterwards: the turn is answered as usual.
+ */
+ takeTurn(): boolean
+ /** Resolves once the first sentence may start. */
+ ready: Promise<OpeningReason>
+ /** Stops the timers: the call ended before the first sentence (`ready` then never resolves). */
+ close(): void
+}
+
+/** The wait for the first sentence; its timers start now (at the pickup). */
+export function openingGate(): OpeningGate {
+ let done = false
+ let spoke = false
+ let speakingNow = false
+ let pause: ReturnType<typeof setTimeout> | undefined
+ let resolveReady: (reason: OpeningReason) => void = () => {}
+ const ready = new Promise<OpeningReason>(resolve => (resolveReady = resolve))
+ const finish = (reason: OpeningReason) => {
+ if (done) return
+ done = true
+ clearTimeout(silence)
+ clearTimeout(longest)
+ clearTimeout(pause)
+ resolveReady(reason)
+ }
+ const silence = setTimeout(() => !spoke && finish('silence'), OPENING_SILENCE_MS)
+ const longest = setTimeout(() => finish('longest'), OPENING_MAX_MS)
+ const restartPause = () => {
+ clearTimeout(pause)
+ pause = setTimeout(() => finish('pause'), OPENING_PAUSE_MS)
+ }
+ return {
+ speaking(on) {
+ if (done) return
+ speakingNow = on
+ if (on) {
+ spoke = true
+ clearTimeout(pause)
+ } else if (spoke) restartPause()
+ },
+ heard() {
+ if (done) return
+ spoke = true
+ if (!speakingNow) restartPause()
+ },
+ takeTurn() {
+ if (done) return false
+ finish('turn')
+ return true
+ },
+ ready,
+ close() {
+ done = true
+ clearTimeout(silence)
+ clearTimeout(longest)
+ clearTimeout(pause)
+ },
+ }
+}
diff --git a/apps/agent/src/pipeline.test.ts b/apps/agent/src/pipeline.test.ts
index dfc8e3a8..b1d53f5e 100644
--- a/apps/agent/src/pipeline.test.ts
+++ b/apps/agent/src/pipeline.test.ts
@@ -13,6 +13,7 @@ import {
withCallLanguages,
chatJson,
createPipeline,
+ OUTBOUND_MIN_INTERRUPTION_WORDS,
deepgramChoice,
NOVA_MULTI_ENDPOINTING_MS,
createRealtimePipeline,
@@ -688,3 +689,16 @@ test("AssemblyAI with Deepgram set up: a call in a language AssemblyAI can't und
callLanguagesOf({ main: 'en', mode: 'allowed', allowed: ['ko', 'pl'] }, elevenlabs, withDeepgram).others,
).toEqual(['ko', 'pl'])
})
+
+test("on an outbound call one word does not interrupt the assistant; inbound keeps LiveKit's default (LIN-873)", async () => {
+ const stages = await configFromEnv({
+ DEEPGRAM_API_KEY: 'dg',
+ LLM_PROVIDER: 'openrouter',
+ OPENROUTER_API_KEY: 'or',
+ ELEVENLABS_API_KEY: 'el',
+ })
+ expect(OUTBOUND_MIN_INTERRUPTION_WORDS).toBe(2)
+ const outbound = createPipeline(stages, null, undefined, undefined, undefined, true)
+ expect(outbound.turnHandling?.interruption).toEqual({ minWords: OUTBOUND_MIN_INTERRUPTION_WORDS })
+ expect(createPipeline(stages).turnHandling?.interruption).toBeUndefined()
+})
diff --git a/apps/agent/src/pipeline.ts b/apps/agent/src/pipeline.ts
index 9e727e8c..0d09bdb8 100644
--- a/apps/agent/src/pipeline.ts
+++ b/apps/agent/src/pipeline.ts
@@ -532,12 +532,21 @@ export const TTS_TEXT_TRANSFORMS: NonNullable<voice.AgentSessionOptions['ttsText
spellCodesTransform,
]
+/**
+ * On an outbound call (LIN-873), a word or two the person says while the assistant speaks ("ja", "danke", "genau") is
+ * a sign of listening, not a turn: it takes this many words to interrupt the assistant. A shorter turn is not lost: it
+ * stays in the transcript and goes to the assistant with the person's next words. LiveKit counts the words of the
+ * turn so far (minWords); its false-interruption resume (on by default) only covers sound without words.
+ */
+export const OUTBOUND_MIN_INTERRUPTION_WORDS = 2
+
export function createPipeline(
config: AgentConfig,
assistantVoice?: AssistantVoice | null,
silenceFirstGapS = SILENCE_FIRST_GAP_DEFAULT_S,
languages: CallLanguages = ENGLISH_CALL,
speedPct = TALKING_SPEED_PCT_DEFAULT,
+ outbound = false,
): voice.AgentSessionOptions & { tts: CallVoice } {
const sttTurns = sttDetectsTurns(config.stt, languages)
return {
@@ -549,6 +558,7 @@ export function createPipeline(
turnDetection: sttTurns ? 'stt' : undefined,
endpointing: ENDPOINTING,
preemptiveGeneration: { enabled: true },
+ ...(outbound ? { interruption: { minWords: OUTBOUND_MIN_INTERRUPTION_WORDS } } : {}),
},
// The caller counts as away after this much silence on both sides; the worker then asks whether they are still
// there, and in the end says goodbye and hangs up (remindOnSilence in hang-up.ts).
diff --git a/apps/agent/src/summary.ts b/apps/agent/src/summary.ts
index 8a8a34cd..2e18373e 100644
--- a/apps/agent/src/summary.ts
+++ b/apps/agent/src/summary.ts
@@ -42,7 +42,8 @@ const summarySchema = z.object({
* summary and items are written in.
*/
export function summarySystem(language = 'en', outboundGoal?: string | null): string {
- return `${outboundGoal ? `${outboundSummaryNote(outboundGoal)}\n` : ''}You summarize a phone call between an AI assistant and a caller, for the owner's inbox.
+ if (outboundGoal) return outboundSummarySystem(language, outboundGoal)
+ return `You summarize a phone call between an AI assistant and a caller, for the owner's inbox.
Answer with one JSON object and nothing else:
{
"title": short headline of what the call is about, at most 8 words, no caller name,
@@ -59,11 +60,29 @@ The details the caller gave when the assistant asked for them (name, phone numbe
}
/**
- * An outbound call (call.dial, LIN-873): the assistant phoned the person with a goal from the business; the summary
- * says whether it was reached. The goal is the business's own text, quoted.
+ * An outbound call (call.dial, LIN-873): the assistant placed the call, with a goal from the business (its own text,
+ * quoted); the summary says whether it was reached. Its own text: the inbound one speaks of "the caller", which here
+ * is the assistant, and the summary then called the person phoned "der Anrufer" (production, 2026-11-28).
*/
-export const outboundSummaryNote = (goal: string) =>
- `This was an outbound call: the assistant phoned the person with this goal: ${JSON.stringify(goal.slice(0, 4000))}. "Caller" below means the person it phoned. The summary says whether the goal was reached and what the person said; outcome "answered" when the goal was reached, "callback" when a follow-up is still needed, "hangup" when the person said nothing or hung up right away.`
+export function outboundSummarySystem(language: string, goal: string): string {
+ return `You summarize an outbound phone call for the owner's inbox. The owner's AI assistant placed the call, with this goal: ${JSON.stringify(goal.slice(0, 4000))}
+In the transcript, "assistant" is the AI assistant and "${CALLED}" is the person or business it phoned. Name them by their name or business when the goal or the transcript gives it, else write "the person called" (in the summary's language).
+Answer with one JSON object and nothing else:
+{
+ "title": short headline of what the call is about, at most 8 words,
+ "summary": one or two sentences: whether the goal was reached, and what the person called said,
+ "outcome": one of answered, callback, hangup,
+ "urgency": one of ${urgency.options.join(', ')},
+ "action_items": things the owner still has to do, each a short imperative sentence, [] if none,
+ "caller_name": the name of the person called if they gave it, else null
+}
+Outcomes: "answered" when the goal was reached, "callback" when a follow-up is still needed, "hangup" when the person called said nothing or hung up right away. Use "urgent" only for emergencies.
+${languageRule(language)}
+Lines starting with "system:" are tools the assistant used.`
+}
+
+/** How the transcript names the person an outbound call phoned (outboundSummarySystem). */
+const CALLED = 'person called'
/** In English as before; in another team language, the summary says in that language when the call was in another one. */
function languageRule(language: string): string {
@@ -73,7 +92,11 @@ function languageRule(language: string): string {
return `Write the title, summary and action items in ${name} (language code "${language}"), also when the call was in another language. When it was not in ${name}, begin the summary with a short sentence in ${name} naming the language of the call. Keep names, phone numbers, email addresses and street addresses exactly as they were said.`
}
-const formatTranscript = (lines: TranscriptLine[]) => lines.map(l => `${l.speaker}: ${l.text}`).join('\n')
+/** Outbound: the AI assistant placed the call, so the transcript names the sides "assistant" and CALLED. */
+const OUTBOUND_SPEAKERS: Partial<Record<Speaker, string>> = { agent: 'assistant', caller: CALLED }
+
+const formatTranscript = (lines: TranscriptLine[], outbound = false) =>
+ lines.map(l => `${(outbound && OUTBOUND_SPEAKERS[l.speaker]) || l.speaker}: ${l.text}`).join('\n')
/**
* What the summary is told when there is no number to call back on (no caller ID, none given): no item asks the owner
@@ -127,6 +150,32 @@ export function hangupResult(language = 'en'): CallResult {
}
}
+/** Why an outbound call never connected (LIN-873): the line was busy, nobody answered, the call was declined, or it failed. */
+export type NotReachedReason = 'busy' | 'noAnswer' | 'declined' | 'failed'
+
+/**
+ * The reason in the dialer's error: LiveKit SIP names the SIP status ("SIP call failed: 486 Busy Here"); a ring that ran
+ * out ends with 408/480/487 or a timeout.
+ */
+export function notReachedReason(error: string): NotReachedReason {
+ if (/\b(486|600)\b|busy/i.test(error)) return 'busy'
+ if (/\b603\b|declin/i.test(error)) return 'declined'
+ if (/\b(408|480|487)\b|timeout|timed out|deadline|no answer|not answered|rang out/i.test(error)) return 'noAnswer'
+ return 'failed'
+}
+
+// i18n-dynamic: call.autoSummary.notReached.*
+/** An outbound call that never connected: nobody to summarize, the reason says why. In the team's language. */
+export function notReachedResult(reason: NotReachedReason, language = 'en'): CallResult {
+ const t = teamT(language)
+ return {
+ outcome: 'hangup',
+ urgency: 'low',
+ title: t('call.autoSummary.notReached.title'),
+ summary: t(`call.autoSummary.notReached.${reason}`),
+ }
+}
+
/**
* The caller said nothing because a stage of the voice pipeline failed (the voice, speech to text): not a hang-up but a
* caller the assistant could not help, so it reaches the owner as a call back, with the stage that failed.
@@ -256,7 +305,10 @@ export async function summarizeCall(
JSON.parse(
await complete(
summarySystem(teamLanguage, outboundGoal),
- summaryRequest(lines, savedMessages, callbackKnown, details),
+ // Outbound: only the transcript; the assistant takes no messages and asks for no details there.
+ outboundGoal
+ ? `Transcript:\n${formatTranscript(lines, true)}`
+ : summaryRequest(lines, savedMessages, callbackKnown, details),
),
),
)
diff --git a/apps/agent/src/worker.ts b/apps/agent/src/worker.ts
index d8f6e48f..e606bcd5 100644
--- a/apps/agent/src/worker.ts
+++ b/apps/agent/src/worker.ts
@@ -55,6 +55,8 @@ import {
type CallSession,
} from './call-session.ts'
import { dialOutbound } from './outbound-dial.ts'
+import { type OpeningGate, openingGate } from './outbound-opening.ts'
+import { notReachedReason } from './summary.ts'
import { ensurePaces, PACE_WAIT_MS } from './voice-pace.ts'
import { earlyOrigin, livekitParticipants } from './early-origin.ts'
import {
@@ -289,7 +291,10 @@ function reportVoiceFailure(room: Room, call: CallSession, log: CallLog, failure
// No reason on the transcript: the first one may still be refined (below); the call's failure keeps the cause.
const stage = voiceStageName(failure.stage, log.words)
const stageName = `${stage[0]!.toLocaleUpperCase()}${stage.slice(1)}`
- log.record('system', log.words.t('call.event.voiceFailed', { stage: stageName, provider: voiceProviderLabel(failure.provider) }))
+ log.record(
+ 'system',
+ log.words.t('call.event.voiceFailed', { stage: stageName, provider: voiceProviderLabel(failure.provider) }),
+ )
const show = (shown: VoiceFailure) =>
void room.localParticipant?.setAttributes({ [VOICE_FAILURE_ATTRIBUTE]: JSON.stringify(shown) }).catch(() => {})
show(failure)
@@ -426,7 +431,11 @@ async function converse(
stages?.stt,
)
const speed = talkingSpeedOf(call.assistant)
- const pipeline = stages && createPipeline(stages, call.assistant?.voice, silence.firstGapS, languages, speed)
+ const pipeline =
+ stages && createPipeline(stages, call.assistant?.voice, silence.firstGapS, languages, speed, !!call.outbound)
+ // An outbound call's first sentence waits for the end of the person's greeting (outbound-opening.ts); it starts
+ // counting at the pickup, which came before this. A realtime model answers their greeting itself.
+ const opening: OpeningGate | null = stages && call.outbound ? openingGate() : null
// The realtime session (again after a reconnect), and the caller's finished turns in it, for the fixed lines.
let realtimeSession: RealtimeEvents | null = null
let callerTurns = 0
@@ -540,6 +549,13 @@ async function converse(
}
session.on(voice.AgentSessionEventTypes.AgentStateChanged, onSpeaking)
recordConversation(session, log)
+ if (opening) {
+ session.on(voice.AgentSessionEventTypes.UserStateChanged, ({ newState }) =>
+ opening.speaking(newState === 'speaking'),
+ )
+ session.on(voice.AgentSessionEventTypes.UserInputTranscribed, () => opening.heard())
+ session.on(voice.AgentSessionEventTypes.Close, () => opening.close())
+ }
const flagUrgent = callFlagger(api, call, log)
keepUrgentPromises(session, flagUrgent, call.callId)
logTurnMetrics(session, call.callId)
@@ -776,9 +792,10 @@ async function converse(
}),
}
const filler = toolFiller(session, line => speak(line), { stillLine: () => lines().stillChecking })
+ // The person's greeting on an outbound call gets no reply of its own: the first sentence answers it (openingGate).
const agent = new CallAgent(
{ instructions, tools: assistantTools(api, call, log, endCall, flagUrgent, transfer, collect, filler) },
- filler.busy,
+ () => filler.busy() || opening?.takeTurn() === true,
)
switched.to = () => {
const failed = (e: unknown) =>
@@ -923,7 +940,12 @@ async function converse(
key,
personalGreeting ? callerDetails : null,
() => setup.mark('greeting queued'),
- heard,
+ opening
+ ? async () => {
+ const [, reason] = await Promise.all([heard(), opening.ready])
+ setup.mark(`first sentence after ${reason}`)
+ }
+ : heard,
),
)
}
@@ -1187,7 +1209,9 @@ async function entry(ctx: JobContext) {
ctx.addShutdownCallback(finishOnce)
// Nobody answered the outbound call (no answer, busy, refused): it is filed with the reason, and the room closes.
answered?.catch(async e => {
- log.record('system', log.words.t('call.event.outboundNotAnswered', { reason: e instanceof Error ? e.message : String(e) }))
+ const reason = e instanceof Error ? e.message : String(e)
+ log.notReached = notReachedReason(reason)
+ log.record('system', log.words.t('call.event.outboundNotAnswered', { reason }))
await finishOnce()
await ctx.deleteRoom()
ctx.shutdown('outbound call not answered')
diff --git a/packages/i18n/locales/en/call.json b/packages/i18n/locales/en/call.json
index c627ba34..46bd53a5 100644
--- a/packages/i18n/locales/en/call.json
+++ b/packages/i18n/locales/en/call.json
@@ -18,6 +18,11 @@
"autoSummary.missed.notReady": "Nobody answered this call: the assistant was not taking calls yet. Call the caller back.",
"autoSummary.missed.overCap": "Nobody answered this call: the workspace reached its monthly spending cap. Call the caller back.",
"autoSummary.missed.title": "Missed call",
+ "autoSummary.notReached.busy": "Not reached: the line was busy.",
+ "autoSummary.notReached.declined": "Not reached: the call was declined.",
+ "autoSummary.notReached.failed": "Not reached: the call could not be connected.",
+ "autoSummary.notReached.noAnswer": "Not reached: nobody answered.",
+ "autoSummary.notReached.title": "Not reached",
"autoSummary.unavailable.title": "Call (summary unavailable)",
"autoSummary.voiceFailed.item": "Call the caller back: the assistant's {stage, select, stt {speech to text} llm {language model} tts {voice} other {realtime model}} failed on this call.",
"autoSummary.voiceFailed.summary": "The assistant's {stage, select, stt {speech to text} llm {language model} tts {voice} other {realtime model}} failed on this call, so the caller got no help and hung up.",