microscopic-airport-67304
02/25/2025, 4:10 PMgray-monkey-83525
02/25/2025, 4:10 PMstartRoomCompositeEgress
method from the Egress API.
Would you like more detailed information on setting up the SIP trunk or using the egress service?
Sources:
- SIP Overview
- Egress Overview
- Egress API 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.microscopic-airport-67304
02/25/2025, 4:12 PMgray-monkey-83525
02/25/2025, 4:12 PMuser_speech_committed
and agent_speech_committed
events to capture and save the chat context. This allows you to store the conversation history in a database or file, which can be reloaded when the user reconnects.
Additionally, the ChatContext class provides methods to manage chat messages, which can be used to save and restore the chat context. You can use the append
method to add messages to the context and the copy
method to create a structured clone of the context for storage.
Would you like more detailed guidance on implementing this in your application?
Sources:
- ChatContext class 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.microscopic-airport-67304
02/25/2025, 4:19 PMgray-monkey-83525
02/25/2025, 4:19 PMVoicePipelineAgent
, you can listen to the user_speech_committed
and agent_speech_committed
events to capture the conversation. Here's an example in Python:
import asyncio
from datetime import datetime
from livekit import rtc
from livekit.agents import llm
from livekit.agents.voice_assistant import VoicePipelineAgent
from livekit.plugins import deepgram, openai, silero
# Initialize the VoicePipelineAgent
agent = VoicePipelineAgent(
vad=silero.VAD.load(),
stt=deepgram.STT(),
llm=openai.LLM(),
tts=openai.TTS(),
chat_ctx=llm.ChatContext(),
)
# Queue to store log messages
log_queue = asyncio.Queue()
# Event handler for user speech committed
@agent.on("user_speech_committed")
def on_user_speech_committed(msg: llm.ChatMessage):
log_queue.put_nowait(f"[{datetime.now()}] USER: {msg.content}\n")
# Event handler for agent speech committed
@agent.on("agent_speech_committed")
def on_agent_speech_committed(msg: llm.ChatMessage):
log_queue.put_nowait(f"[{datetime.now()}] AGENT: {msg.content}\n")
# Function to write transcriptions to a file
async def write_transcription():
async with open("transcriptions.log", "w") as f:
while True:
msg = await log_queue.get()
if msg is None:
break
await f.write(msg)
# Start the transcription writing task
write_task = asyncio.create_task(write_transcription())
# Function to save the chat context
def save_chat_context(chat_ctx):
# Convert chat context to a serializable format and save it
with open("chat_context.json", "w") as f:
json.dump([msg.to_dict() for msg in chat_ctx.messages], f)
# Function to load the chat context
def load_chat_context():
with open("chat_context.json", "r") as f:
messages = json.load(f)
chat_ctx = llm.ChatContext()
for msg in messages:
chat_ctx.append(**msg)
return chat_ctx
# Example of saving and loading chat context
save_chat_context(agent.chat_ctx)
agent.chat_ctx = load_chat_context()
This example demonstrates how to capture and store the chat context in a file, which can be reloaded later to resume the conversation. Would you like more details on any specific part of this implementation?
Sources:
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1730811222.681569
- https://docs.livekit.io/agents/voice-agent/voice-pipeline/#Interruption-handling 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.microscopic-airport-67304
02/25/2025, 9:06 PMgray-monkey-83525
02/25/2025, 9:06 PM