miniature-nail-35141
11/07/2025, 5:58 PMtall-airline-16756
11/07/2025, 5:58 PMtall-airline-16756
11/07/2025, 5:59 PMuser_input_transcribed event, which captures the user’s audio transcriptions. It’s best to log the transcription when the isFinal flag is true, so you’re capturing the complete input.
• Log Agent Output: Watch the conversation_item_added event to catch agent responses. This event fires whenever a message is added to the chat history, including the TTS outputs.
• Access Full History: You can use session.history to pull all user and agent messages together. Saving this log at the end of the session with a shutdown callback can be really handy.
• Customize Pipelines: If you want more control, try overriding methods like stt_node() and tts_node() to add your own logging logic before or after processing.
• Enable Synchronized Transcripts: For really precise logging of what was spoken, turn on use_tts_aligned_transcript=True in your configuration. This helps ensure your log matches the actual spoken output.
These steps should give you a solid and thorough way to log both user and agent interactions. If you’d like, I’m here to walk you through any part or provide examples—just let me know!
Sources: Pipeline nodes and hooks | LiveKit docs | Text and transcriptions | LiveKit docs | agents/src/voice/agent_activity.ts | Session recording and transcripts | LiveKit Docs | livekit-plugins/livekit-plugins-sarvam/livekit/plugins/sarvam/stt.pyminiature-nail-35141
11/07/2025, 5:59 PMtall-airline-16756
11/07/2025, 6:00 PMfrom datetime import datetime
from livekit.agents import AgentSession, ChatMessage
from livekit.plugins import deepgram, openai
async def main():
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(),
tts=openai.TTS(voice="alloy"),
use_tts_aligned_transcript=True
)
# Log user input after STT
@session.on("user_input_transcribed")
def log_user_input(transcript):
if transcript.is_final:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("user_input_log.txt", "a") as log_file:
log_file.write(f"[{timestamp}] User Input: {transcript.transcript}\n")
# Log agent output after TTS
@session.on("conversation_item_added")
def log_agent_output(msg: ChatMessage):
if msg.role == "assistant" and msg.text_content:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("agent_output_log.txt", "a") as log_file:
log_file.write(f"[{timestamp}] Agent Output: {msg.text_content}\n")
await session.start()
# Run the session
import asyncio
asyncio.run(main())
This snippet listens for the user_input_transcribed event to carefully log what the user says after STT, and the conversation_item_added event to capture the agent's responses after TTS. If you have any questions or want to explore this further, please don’t hesitate to ask—I’m here to help!
Sources: Text and transcriptions | LiveKit docs | metrics/metrics_tts.py