The js code sample here appears to be wrong <https...
# telephony
t
The js code sample here appears to be wrong https://docs.livekit.io/frontends/telephony/agents/#voicemail-detection.
waitForPlayout
cannot be called from within a tool
Copy code
/**
   * Waits for the entire assistant turn to complete playback.
   *
   * This method waits until the assistant has fully finished speaking,
   * including any finalization steps beyond initial response generation.
   * This is appropriate to call when you want to ensure the speech output
   * has entirely played out, including any tool calls and response follow-ups.
   */
  async waitForPlayout(): Promise<void> {
    const store = asyncLocalStorage.getStore();
    if (store && store?.functionCall) {
      throw new Error(
        `Cannot call 'SpeechHandle.waitForPlayout()' from inside the function tool '${store.functionCall.name}'. ` +
          'This creates a circular wait: the speech handle is waiting for the function tool to complete, ' +
          'while the function tool is simultaneously waiting for the speech handle.\n' +
          "To wait for the assistant's spoken response prior to running this tool, use RunContext.wait_for_playout() instead.",
      );
    }
    await this.doneFut.await;
  }
l
Good point, I would suggest something like this:
Copy code
leaveVoicemail: llm.tool({
          description: 'Call this tool if you detect a voicemail system, AFTER your hear the voicemail greeting',
          execute: async (_, { ctx }: llm.ToolOptions) => {
            const handle = ctx.session.generateReply({
              instructions:
                "Leave a brief voicemail message for the user telling them you are sorry you missed them, but you will call back later. You don't need to mention you're going to leave a voicemail, just say the message.",
            });

            handle.addDoneCallback(() => {
              setTimeout(async () => {
                await hangUpCall();
              }, 500);
            });
          },
        }),