This commit is contained in:
hcl 2026-01-30 13:29:49 +01:00 committed by GitHub
commit 52f14db051
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 3 deletions

View File

@ -144,6 +144,9 @@ export class CallManager {
processedEventIds: [], processedEventIds: [],
metadata: { metadata: {
...(initialMessage && { initialMessage }), ...(initialMessage && { initialMessage }),
// Store callPurpose immediately so it's available for AI context
// before speakInitialMessage runs (avoids race with early user speech)
...(initialMessage && { callPurpose: initialMessage }),
mode, mode,
}, },
}; };

View File

@ -22,6 +22,8 @@ export type VoiceResponseParams = {
transcript: Array<{ speaker: "user" | "bot"; text: string }>; transcript: Array<{ speaker: "user" | "bot"; text: string }>;
/** Latest user message */ /** Latest user message */
userMessage: string; userMessage: string;
/** Optional: Purpose of this call (from intro message for outbound calls) */
callPurpose?: string;
}; };
export type VoiceResponseResult = { export type VoiceResponseResult = {
@ -41,8 +43,15 @@ type SessionEntry = {
export async function generateVoiceResponse( export async function generateVoiceResponse(
params: VoiceResponseParams, params: VoiceResponseParams,
): Promise<VoiceResponseResult> { ): Promise<VoiceResponseResult> {
const { voiceConfig, callId, from, transcript, userMessage, coreConfig } = const {
params; voiceConfig,
callId,
from,
transcript,
userMessage,
coreConfig,
callPurpose,
} = params;
if (!coreConfig) { if (!coreConfig) {
return { text: null, error: "Core config unavailable for voice response" }; return { text: null, error: "Core config unavailable for voice response" };
@ -116,6 +125,14 @@ export async function generateVoiceResponse(
`You are ${agentName}, a helpful voice assistant on a phone call. Keep responses brief and conversational (1-2 sentences max). Be natural and friendly. The caller's phone number is ${from}. You have access to tools - use them when helpful.`; `You are ${agentName}, a helpful voice assistant on a phone call. Keep responses brief and conversational (1-2 sentences max). Be natural and friendly. The caller's phone number is ${from}. You have access to tools - use them when helpful.`;
let extraSystemPrompt = basePrompt; let extraSystemPrompt = basePrompt;
// If we have an explicit call purpose (from outbound intro message),
// include it so the AI knows the objective of this call
if (callPurpose) {
extraSystemPrompt += `\n\nPurpose of this call: ${callPurpose}`;
extraSystemPrompt += `\nYou started the call with this message. Stay focused on this topic.`;
}
if (transcript.length > 0) { if (transcript.length > 0) {
const history = transcript const history = transcript
.map( .map(
@ -123,7 +140,7 @@ export async function generateVoiceResponse(
`${entry.speaker === "bot" ? "You" : "Caller"}: ${entry.text}`, `${entry.speaker === "bot" ? "You" : "Caller"}: ${entry.text}`,
) )
.join("\n"); .join("\n");
extraSystemPrompt = `${basePrompt}\n\nConversation so far:\n${history}`; extraSystemPrompt += `\n\nConversation so far:\n${history}`;
} }
// Resolve timeout // Resolve timeout

View File

@ -341,6 +341,7 @@ export class VoiceCallWebhookServer {
from: call.from, from: call.from,
transcript: call.transcript, transcript: call.transcript,
userMessage, userMessage,
callPurpose: call.metadata?.callPurpose as string | undefined,
}); });
if (result.error) { if (result.error) {