agents-js v1.0.5 - trying to work out a Warm Trans...
# ask-ai
f
agents-js v1.0.5 - trying to work out a Warm Transfer process. https://docs.livekit.io/sip/transfer-warm/ seems incomplete and out of order when compared it to the Python example https://github.com/livekit/agents/blob/main/examples/warm-transfer/warm_transfer.py - but as I don't understand Python, I'm not sure. Can you clarify the processing needed for a warm SIP transfer using the Agents JS framework?
t
Thanks for reaching out, Steve. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you with performing a warm SIP transfer using the Agents JS framework. Here’s a friendly step-by-step guide to make it easier: 1. Place the caller on hold: You can gently disable the audio input/output for the caller and, if you like, play some hold music using the
@livekit/rtc-node
library to keep things smooth. 2. Create a consultation room: Next, generate a token for the supervisor so they can join a private consultation room and connect seamlessly. 3. Dial the supervisor: Use the
SipClient
to call the supervisor into this consultation room. 4. Brief the supervisor: It’s helpful to share the conversation history with the supervisor through a
TransferAgent
session, so they’re up to speed. 5. Move the supervisor to the caller's room: Then, smoothly transfer the supervisor into the customer’s room using the
MoveParticipant
API. 6. Complete the transfer: Finally, stop the hold music, introduce the supervisor to the caller, and disconnect the agent sessions to wrap things up nicely. If you’d like to dive deeper, the warm transfer documentation and the Node.js voice agent starter project in the LiveKit resources have some fantastic detailed code examples and extra context. Feel free to explore those anytime! Sources: Agent-assisted warm transfer | LiveKit Docs | LiveKit Docs | SIP overview | LiveKit Docs
f
Please expand on [4], the use of TransferAgent. In particular, how is initialised and placed into the consultation room. [ This is missing in the documentation as far as I can tell. ]
t
Let’s take a closer look at how you can use TransferAgent in a warm SIP transfer. I’ll guide you through how it’s initialized and placed into the consultation room, step by step: 1. Initialize the TransferAgent: Start by creating a class that inherits from
Agent
. It’s important to pass the conversation history from the original agent session to the supervisor so they’re fully up to speed. Here’s a simple example to illustrate this:
Copy code
class TransferAgent extends Agent {
  constructor(prevCtx) {
    let prevConvo = "";
    const contextCopy = prevCtx.copy({
      excludeEmptyMessage: true,
      excludeInstructions: true,
      excludeFunctionCall: true,
    });

    for (const msg of contextCopy.items) {
      if (msg.role === "user") {
        prevConvo += `Customer: ${msg.text_content}\n`;
      } else {
        prevConvo += `Assistant: ${msg.text_content}\n`;
      }
    }

    super({
      instructions: `You are a supervisor receiving a warm transfer. Here is the conversation history: ${prevConvo}`,
    });
  }
}
1. Create a consultation room: Next, generate a unique room name (something like
customerRoomName + "-supervisor"
) and create a new room instance. Then, create an authentication token for the
TransferAgent
with the right permissions to join this consultation room. Finally, connect the agent to the room using this token. 2. Dial the supervisor: Use the
SipClient
to call the supervisor into the consultation room. Once they’re connected, the
TransferAgent
will brief them on the conversation history, so they’re ready to assist. 3. Move the supervisor: When everything is set, you can use the
MoveParticipant
API to transfer the supervisor from the consultation room over to the caller’s room. If you’d like to see a full implementation, I highly recommend checking out the warm transfer documentation along with the LiveKit examples repository—they have detailed code samples that can really help clarify things. Sources: examples/README.md | Agent-assisted warm transfer | LiveKit Docs
f
we've already created the consultation room.... this is what I mean - the docs seems ... missing, or mis-ordered.
t
I'd be happy to guide you through placing the TransferAgent into an already created consultation room. Here’s how you can do it step-by-step: 1. Generate an authentication token: Start by creating a token that grants the
TransferAgent
permission to join the consultation room. Make sure this token includes permissions for room join, publishing, subscribing, and updating metadata. Don’t forget to specify the consultation room name and the agent identity (for example, "transfer-agent"). 2. Connect the TransferAgent: Next, use the token you generated along with the LiveKit server URL to connect the
TransferAgent
to the consultation room by using the
connect()
method. 3. Dial the supervisor: Then, use the
CreateSIPParticipant
API to call the supervisor into the consultation room. You’ll need to provide the outbound trunk ID, the supervisor’s contact number, and the consultation room name so they join the same room as the
TransferAgent
. Once both the
TransferAgent
and supervisor are in the consultation room, the agent can take a moment to summarize the call. When everything is set, you can use the
MoveParticipant
API to transfer the supervisor to the original caller’s room, completing the warm transfer smoothly. If you’d like, there’s a complete example of this warm transfer process available in the LiveKit resources that you might find really helpful. Sources: Agent-assisted warm transfer | LiveKit Docs
f
1. done already - as mentioned 2. how? 3. but this is already been done!
t
Let me guide you through connecting the TransferAgent to an existing consultation room step-by-step: 1. Generate an access token: You'll want to create a token that gives the
TransferAgent
the right permissions to join the consultation room. This includes permissions for room join, publishing, subscribing, and updating metadata. Don’t forget to specify the consultation room name and the agent identity (like "transfer-agent"). 2. Connect the TransferAgent: With the token ready, use it along with the LiveKit server URL to connect the
TransferAgent
to the consultation room using the
connect()
method. 3. Pass conversation context: It’s important to initialize the
TransferAgent
with the conversation history from the original agent session. This helps the agent to effectively summarize the call for the supervisor. Once everything’s set up and connected, the
TransferAgent
can communicate with the supervisor in the consultation room. When you're ready, simply use the
MoveParticipant
API to transfer the supervisor to the original caller’s room, completing the warm transfer smoothly. If you'd like more details or examples, feel free to check out the warm transfer example available in the LiveKit resources. We're here to help if you have any questions along the way! Sources: Agent-assisted warm transfer | LiveKit Docs | examples/warm-transfer/warm_transfer.py | Web and mobile frontends | LiveKit Docs
f
You're not really helping. The docs seem incomplete and potentially wrong. The Python code is ... well, gibberish. Gonna take a walk.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
f