little-cat-27217
11/01/2025, 2:09 PMtall-airline-16756
11/01/2025, 2:09 PMtall-airline-16756
11/01/2025, 2:09 PMwarm_transfer.py available in LiveKit's repositories or documentation just yet. The example we have for agent-assisted warm transfers is written in Python, and it beautifully shows how to manage a warm transfer workflow using two agent sessions.
That said, you absolutely can create a similar workflow in JavaScript or TypeScript by using LiveKit's Node.js SDKs. Here’s a friendly overview of how you might approach it:
• Utilize the @livekit/rtc-node package to set up and manage rooms, connect your agents, and handle media workflows smoothly.
• Make use of the CreateSIPParticipantRequest API to dial the supervisor when needed.
• Implement hold music by publishing local audio files during the hold phase, keeping the experience seamless.
• Pass conversation history between sessions, just like the Python example demonstrates, to maintain context.
If you'd like, I’m more than happy to guide you through this or even provide a code outline to get you started with TypeScript. Just let me know if you want help with any particular step—whether it’s creating agent sessions, managing conversation history, or working with the APIs. I’m here to support you every step of the way!
Sources: examples/warm-transfer/hold_music.mp3 | Agent-assisted warm transfer | LiveKit Docs | docs/index.yamllittle-cat-27217
11/01/2025, 2:11 PMtall-airline-16756
11/01/2025, 2:12 PMimport { LiveKitAPI, AccessToken, VideoGrants } from '@livekit/server-sdk';
import { Room } from '@livekit/rtc-node';
// Initialize LiveKit API client
const livekitApi = new LiveKitAPI(
process.env.LIVEKIT_URL!,
process.env.LIVEKIT_API_KEY!,
process.env.LIVEKIT_API_SECRET!
);
interface WarmTransferService {
startTransfer(callerRoomName: string, supervisorContact: string, conversationHistory: string): Promise<void>;
}
class SessionManager implements WarmTransferService {
private callerRoom: Room;
private consultationRoom: Room | null = null;
private callerStatus: 'active' | 'escalated' | 'inactive' = 'active';
private supervisorStatus: 'inactive' | 'summarizing' | 'merged' | 'failed' = 'inactive';
constructor(private callerRoomName: string, private supervisorContact: string, private conversationHistory: string) {
this.callerRoom = new Room();
}
async startTransfer(): Promise<void> {
if (this.callerStatus !== 'active') return;
this.callerStatus = 'escalated';
await this.placeCallerOnHold();
try {
// Step 1: Create consultation room for supervisor
const consultationRoomName = `${this.callerRoomName}-supervisor`;
this.consultationRoom = new Room();
// Generate token for transfer agent
const token = new AccessToken(this.supervisorContact, 'summary-agent');
token.addGrant({
roomJoin: true,
room: consultationRoomName,
canUpdateOwnMetadata: true,
canPublish: true,
canSubscribe: true,
} as VideoGrants);
// Connect transfer agent to consultation room
await this.consultationRoom.connect(process.env.LIVEKIT_URL!, token.toJwt());
// Dial supervisor using SIP
await livekitApi.sip.createSIPParticipant({
sipTrunkId: process.env.LIVEKIT_SIP_OUTBOUND_TRUNK!,
sipCallTo: this.supervisorContact,
roomName: consultationRoomName,
participantIdentity: 'supervisor-sip',
waitUntilAnswered: true,
});
this.supervisorStatus = 'summarizing';
// Here you would implement logic for the summary agent to brief the supervisor
await this.briefSupervisor();
} catch (error) {
console.error('Could not start transfer:', error);
this.callerStatus = 'active';
await this.handleSupervisorFailure();
}
}
private async placeCallerOnHold(): Promise<void> {
console.log('Placing caller on hold');
}
private async briefSupervisor(): Promise<void> {
console.log('Briefing supervisor with conversation history:', this.conversationHistory);
}
async mergeCalls(): Promise<void> {
if (this.supervisorStatus !== 'summarizing' || !this.consultationRoom) return;
try {
await livekitApi.room.moveParticipant({
room: this.consultationRoom.name,
identity: 'supervisor-sip',
destinationRoom: this.callerRoomName,
});
this.resumeCallerAudio();
console.log('Calls merged successfully');
if (this.consultationRoom) {
await this.consultationRoom.disconnect();
}
} catch (error) {
console.error('Could not merge calls:', error);
await this.handleSupervisorFailure();
}
}
private resumeCallerAudio(): void {
console.log('Resuming caller audio');
}
private async handleSupervisorFailure(): Promise<void> {
this.supervisorStatus = 'failed';
console.log('Transfer failed, informing caller');
}
}
This implementation thoughtfully includes:
• Placing the caller on hold to ensure a smooth transition
• Creating a dedicated consultation room for the supervisor
• Dialing the supervisor using SIP for seamless connection
• Providing a clear conversation summary to keep everyone on the same page
• Merging the supervisor into the caller's room to complete the transfer
If you'd like, I’m here to help walk you through any specific parts of this setup—whether it's configuring environment variables or managing audio for hold music. Just let me know how I can support you!
Sources: Agent-assisted warm transfer | LiveKit Docs | examples/README.mdlittle-cat-27217
11/01/2025, 2:14 PMtall-airline-16756
11/01/2025, 2:14 PMlittle-cat-27217
11/01/2025, 2:21 PMtall-airline-16756
11/01/2025, 2:22 PM