how to log messages transcripts as they arrive in ...
# ask-ai
a
how to log messages transcripts as they arrive in agent?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to log message transcripts as they arrive in an agent — here are the practical ways to capture them in real time. 1) Log user speech as it's transcribed • Listen for the user_input_transcribed event. It delivers interim and final transcripts. ◦ Python:
Copy code
@session.on("user_input_transcribed")
    def on_user_input_transcribed(event: UserInputTranscribedEvent):
        logger.info(f"User: {event.transcript} (final={event.is_final})")
• Node:
Copy code
session.on(voice.AgentSessionEventTypes.UserInputTranscribed, (event) => {
      console.log(`User transcript: ${event.transcript}, final: ${event.isFinal}`);
    });
2) Log completed messages committed to chat history • Listen for conversation_item_added to capture full messages (user or agent) when they’re saved to the conversation. ◦ Python:
Copy code
@session.on("conversation_item_added")
    def on_conversation_item_added(event: ConversationItemAddedEvent):
        logger.info(f"{event.item.role}: {event.item.text_content}")
• Node:
Copy code
session.on(voice.AgentSessionEventTypes.ConversationItemAdded, (event) => {
      console.log(`${event.item.role}: ${event.item.textContent}`);
    });
3) (Advanced) Capture streaming/word-level transcripts from the agent • Implement a transcription_node in your agent to receive timed chunks or word-level transcripts as they’re generated. Useful for fine-grained logging or aligning audio with text. ◦ Python example:
Copy code
async def transcription_node(self, text: AsyncIterable[str | TimedString], model_settings: ModelSettings) -> AsyncGenerator[str | TimedString, None]:
        async for chunk in text:
            if isinstance(chunk, TimedString):
                logger.info(f"Transcribed (timed): '{chunk}' at {chunk.start_time}s")
            else:
                logger.info(f"Transcribed: {chunk}")
            yield chunk
Notes • Use
user_input_transcribed
for real-time user speech,
conversation_item_added
for finalized messages, and
transcription_node
when you need timed/word-level streaming from the agent. • Ensure your SDK version supports these events/features and that observability is enabled for your project. Would you like sample code for your specific SDK (Python or Node) or guidance on where to write these logs (console, file, external logger)? Sources: Text and transcriptions | LiveKit docs | How to capture real-time agent transcriptions during conversations | Agent insights in LiveKit Cloud | LiveKit docs
a
i want to log all messages but only final, not intermediate transcripts
t
You want only final (completed) transcripts. Two reliable options: 1) Log when messages are committed — use conversation_item_added • This captures finalized chat items (user or agent) when they’re saved. ◦ Python:
Copy code
@session.on("conversation_item_added")
    def on_conversation_item_added(event: ConversationItemAddedEvent):
        logger.info(f"{event.item.role}: {event.item.text_content}")
• Node:
Copy code
session.on(voice.AgentSessionEventTypes.ConversationItemAdded, (event) => {
      console.log(`${event.item.role}: ${event.item.textContent}`);
    });
2) If you must use transcription events, filter for final transcripts only • Listen to user_input_transcribed and check
is_final
before logging. ◦ Python:
Copy code
@session.on("user_input_transcribed")
    def on_user_input_transcribed(event: UserInputTranscribedEvent):
        if event.is_final:
            logger.info(f"User: {event.transcript}")
• Node:
Copy code
session.on(voice.AgentSessionEventTypes.UserInputTranscribed, (event) => {
      if (event.isFinal) console.log(`User: ${event.transcript}`);
    });
Recommendation: prefer conversation_item_added for a single source of truth (final messages). Which SDK are you using (Python or Node)? I can give a full example integrated with your logger.