wonderful-account-72949
08/27/2025, 10:45 AMsession = AgentSession(
llm=google.beta.realtime.RealtimeModel(
model=model,
voice=voice,
temperature=temperature,
instructions=instructions,
),
)tall-airline-16756
08/27/2025, 10:45 AMtall-airline-16756
08/27/2025, 10:46 AMAgentSession and listen for transcription events. Here’s a quick example to get you started:
from livekit.agents import AgentSession
from livekit.plugins import deepgram # or other STT providers
async def entrypoint(ctx):
session = AgentSession(
stt=deepgram.STT(), # Initialize STT provider
)
@session.on("user_input_transcribed")
def on_transcript(transcript):
if transcript.is_final:
print(f"Final transcript: {transcript.transcript}")
else:
print(f"Interim transcript: {transcript.transcript}")
await session.start(agent=MyAgent(), room=ctx.room)
This setup listens to the user_input_transcribed event so you can catch both interim and final transcriptions as they happen.
If you want to dive deeper or have a specific scenario in mind, just give me a shout—I’m here to help!
Sources: Transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | examples/voice_agents/timed_agent_transcript.py | Session recording and transcripts | LiveKit Docs | Transcriptions | LiveKit Docswonderful-account-72949
08/27/2025, 10:49 AMtall-airline-16756
08/27/2025, 10:49 AMsession.history property. It holds the entire conversation history, including messages from both sides. Here's a quick example:
# Access current history
history = session.history
# Iterate through the history
for item in history:
print(f"{item.role}: {item.text}")
Also, if you'd like to save the history once the session wraps up, you can do that with a shutdown callback like this:
# Save after session ends
ctx.add_shutdown_callback(lambda: save_history(session.history))
If you have any questions or a particular scenario you want help with, just give me a shout!
Sources: complex-agents/teleprompter/cartesia-ink.py | Session recording and transcripts | LiveKit Docs | main.py | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docswonderful-account-72949
08/27/2025, 10:55 AMtall-airline-16756
08/27/2025, 10:55 AMTypeError: 'ChatContext' object is not iterable pops up because the ChatContext object itself can’t be looped over directly. Instead, you want to use its items property, which holds the list of chat messages. Here’s a simple way to go through the conversation history:
from livekit.agents.llm import ChatContext, ChatMessage
# Assuming chat_ctx is your ChatContext instance
for item in chat_ctx.items: # Use .items to access the list
if isinstance(item, ChatMessage):
print(f"{item.role}: {item.text_content}")
If anything’s still unclear or you want a hand with this, just give me a shout—I’m here to help!
Sources: tests/test_chat_ctx.pywonderful-account-72949
08/27/2025, 10:59 AMconversation_item_added event do ??tall-airline-16756
08/27/2025, 11:00 AMconversation_item_added event pops up whenever something new gets added to the chat history during an agent session. This covers all the finalized messages from both the user and the agent—whether it’s text, audio, images, or even function call results.
When this event happens, you’ll get a ConversationItemAddedEvent object that includes a super important property:
• item: This is a ChatMessage instance that holds all the juicy details like who sent it (say, "user" or "assistant"), the text, any media attached, and if the message got interrupted.
It’s pretty handy if you want to keep an eye on things in real-time, log conversations, or send messages straight to the frontend as they get officially saved in the session history.
Sources: Events and error handling | LiveKit Docs | Events and error handling | LiveKit Docs | Session recording and transcripts | LiveKit Docs | Session recording and transcripts | LiveKit Docs | Text and transcriptions | LiveKit Docswonderful-account-72949
08/27/2025, 11:11 AMtall-airline-16756
08/27/2025, 11:11 AMconversation_item_added event only fires once a message is safely saved in the chat history, so it’s all secure and accounted for.
2. Message Order: The messages will stay in the right order. Even if one event takes a bit longer to process, the system makes sure that every message is added to the history exactly where it belongs.
So, while there might be some delays in handling the events, the messages themselves remain safe and in the correct sequence. Hope that helps clear things up!
Sources: Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | plugins/openai/src/realtime/realtime_model.ts | Events and error handling | LiveKit Docs | Events and error handling | LiveKit Docs