miniature-nail-35141
10/28/2025, 4:09 PMtall-airline-16756
10/28/2025, 4:09 PMtall-airline-16756
10/28/2025, 4:11 PMsession.generate_reply() method! This method is primarily designed for voice agents to generate and play audio responses, and it returns a SpeechHandle object instead of a string. But don't worry—you can still get the generated text by checking the conversation history or by listening to conversation events.
Here are two friendly ways to do that:
1. Accessing Conversation History:
# After the agent has responded
call_summary = session.history.messages[-1].text_content
2. Using the conversation_item_added Event:
call_summary = None
@session.on("conversation_item_added")
async def on_conversation_item_added(item):
global call_summary
if item.role == "assistant":
call_summary = item.text_content
# Trigger the reply
generate_reply("give the call summary")
These approaches let you capture the agent's response as a string variable, so you can use it however you need. If you have any questions or want to explore more, feel free to ask—I'm here to help!
Sources: examples/voice_agents/realtime_load_chat_history.py | Agent speech and audio | LiveKit Docs | agents/src/voice/agent_session.ts