i have built a voice agent using agents.js with gp...
# ask-ai
b
i have built a voice agent using agents.js with gpt-realtime which connects users 1 on 1 with an agent via sip/telephony. gpt-realtime does a bad job of transcribing what the user says into text. Id like to have the full conversation logged so it can later be read and analysed like a text message chat (similar to how it is laid out on retell for example). is there an option to use a seperate stt node for logging purposes while still having the interactions via the realtime llm node? or is there an alternative way of achieving this in agents.js?
t
Thanks for reaching out, David. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're looking to log the full conversation while keeping those real-time interactions smooth in agents.js! You can definitely achieve this by customizing the
sttNode
method. This way, you can use a separate speech-to-text (STT) node just for logging, without interrupting the real-time LLM interactions. Here’s a friendly overview of how you might approach it: • Override the
sttNode
method in your agent class so you can catch and log the transcription data as it comes in. • Make sure to pass that transcription data along to the real-time LLM node, so your conversation keeps flowing naturally. • Add your own custom logging logic inside the overridden
sttNode
to save those transcriptions for later review. If you’d like, I’m here to help with more details or even some code examples to get you started—just let me know! Sources: Pipeline nodes and hooks | LiveKit docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | agents/src/voice/io.ts | complex-agents/nutrition-assistant/README.md | Session recording and transcripts | LiveKit docs
b
please scope your suggestions and examples to agents.js. note your examples are all python.
t
Thank you so much for bringing this up! I’d love to walk you through a focused example for agents.js to help clarify things. In agents.js, you have the option to override the
sttNode
method to log transcription data while still keeping those real-time interactions smooth and seamless. Here’s a simple example to illustrate:
Copy code
class LoggingAgent extends Agent {
  async sttNode(audio, modelSettings) {
    // Get the default STT stream
    const defaultStream = await Agent.default.sttNode(this, audio, modelSettings);

    if (!defaultStream) {
      return null;
    }

    // Create a custom stream that logs events while passing them through
    return new ReadableStream({
      async start(controller) {
        const reader = defaultStream.getReader();

        try {
          while (true) {
            const { done, value } = await reader.read();

            if (done) {
              break;
            }

            // Log the speech event or transcript
            if (typeof value === 'object' && 'type' in value) {
              console.log('Speech event logged:', value);
            } else if (typeof value === 'string') {
              console.log('Transcript logged:', value);
            }

            // Pass the event through to maintain real-time flow
            controller.enqueue(value);
          }
        } finally {
          reader.releaseLock();
          controller.close();
        }
      }
    });
  }
}
This approach makes sure that: • All your transcription data is safely logged for any future review. • The real-time interaction with the LLM node continues without any hiccups. If anything feels unclear or if you'd like me to share more examples, please don’t hesitate to reach out. I’m here to help!
b
great, please provide a complete, minimal, single file example I can test using gpt-realtime as the realtime llm node
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!