How do I log what llm response in a voice agent ?
# ask-ai
b
How do I log what llm response in a voice agent ?
t
Thanks for reaching out, Abdullah. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To log LLM responses in a voice agent using LiveKit's framework, you can follow the example provided in the
save_chatctx.py
script. Here's a summary of the process: 1. Create a voice pipeline agent with components like VAD (Voice Activity Detection), STT (Speech-to-Text), LLM, and TTS (Text-to-Speech). 2. Set up event handlers to capture both user speech and agent responses. For example:
Copy code
@agent.on("user_speech_committed")
def on_user_speech_committed(msg: llm.ChatMessage):
    log_queue.put_nowait(f"[{datetime.now()}] USER:\n{msg.content}\n\n")

@agent.on("agent_speech_committed")
def on_agent_speech_committed(msg: llm.ChatMessage):
    log_queue.put_nowait(f"[{datetime.now()}] AGENT:\n{msg.content}\n\n")
3. Use an asynchronous queue and a separate task to write the logs to a file, such as `transcriptions.log`: 4. Ensure proper cleanup when the application shuts down: This method will log both user inputs and agent responses with timestamps to a file for later review. Sources: Tree View: | dse-workbench