some-breakfast-27057
08/01/2025, 6:51 PMtall-airline-16756
08/01/2025, 6:51 PMtall-airline-16756
08/01/2025, 6:52 PMsession.say() method within the on_enter lifecycle method of your agent. This triggers the agent to speak a predefined message immediately when the conversation begins.
Here’s an example implementation:
class MyAgent(Agent):
async def on_enter(self):
await self.session.say("Hello! How can I assist you today?")
Ensure that your agent is configured with a TTS plugin, as session.say() requires TTS to function properly.some-breakfast-27057
08/01/2025, 6:53 PMtall-airline-16756
08/01/2025, 6:53 PMon_enter method to have your agent say a friendly greeting right when the conversation starts. Here’s a simple way to do it:
from livekit.agents import Agent, AgentSession
from livekit.plugins import openai
class GreetingAgent(Agent):
async def on_enter(self):
await self.session.say(
"Hello! How can I assist you today?",
allow_interruptions=True
)
async def entrypoint(ctx: JobContext):
session = AgentSession(
tts=openai.TTS() # Make sure you have a TTS plugin set up
)
await session.start(
agent=GreetingAgent(),
room=ctx.room
)
if __name__ == "__main__":
# Just configure and run your LiveKit worker here
pass
Just a heads-up: your TTS plugin needs to support real-time streaming to make the speech-to-speech flow smooth. Also, the allow_interruptions option is there so users can jump in and interrupt the agent if needed. Hope this helps!some-breakfast-27057
08/01/2025, 6:56 PMtall-airline-16756
08/01/2025, 6:57 PMawait session.say("Hello! How can I help you today?")
2. `agent.say()`:
await agent.say("Hey, how can I help you today", allow_interruptions=True)
Just a quick heads-up: make sure you have a TTS plugin set up if you're using a real-time model, since it's needed to turn text into speech.
Sources: Agent speech and audio | LiveKit Docs | delay-handling/agent.pysome-breakfast-27057
08/01/2025, 6:57 PMtall-airline-16756
08/01/2025, 6:58 PMfrom livekit.agents import Agent, AgentSession
from livekit.plugins import openai
from dotenv import load_dotenv
import asyncio
load_dotenv() # Load environment variables
b. Configure the TTS Plugin:
tts = openai.TTS(model="tts-1", voice="nova")
c. Create the Agent Class:
class GreetingAgent(Agent):
def __init__(self):
super().__init__(
instructions="You are a helpful assistant.",
tts=tts
)
async def on_enter(self):
try:
await self.session.say(
"Welcome! How can I assist you today?",
allow_interruptions=False
)
except Exception as e:
print(f"Error during greeting: {e}")
d. Initialize and Start the Agent Session:
async def entrypoint(ctx: JobContext):
session = AgentSession()
await session.start(
agent=GreetingAgent(),
room=ctx.room
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
• Key Considerations:
◦ TTS Configuration: Double-check that your TTS plugin is set up correctly because session.say() depends on it.
◦ Error Handling: Wrapping the greeting in try-except blocks helps catch any hiccups gracefully.
◦ Real-time Models: Make sure your TTS is ready for real-time speech synthesis to keep things smooth.
With this setup, your agent will warmly greet users with a friendly message as soon as the conversation starts — making the whole experience feel a bit more personal and welcoming.some-breakfast-27057
08/01/2025, 7:05 PMtall-airline-16756
08/01/2025, 7:06 PMfrom livekit.plugins import elevenlabs
from livekit.agents import AgentSession
eleven_tts = elevenlabs.TTS(
model="eleven_turbo_v2_5",
voice=elevenlabs.Voice(
id="EXAVITQu4vr4xnSDxMaL",
name="Bella",
),
language="en",
enable_ssml_parsing=False,
)
session = AgentSession(tts=eleven_tts)
2. Using `generate_reply()`:
`session.generate_reply(
instructions="speak: Hello! Welcome to our conversation. How can I assist you today?"
)`The great thing about this one is it works even if you don’t have a TTS plugin — it uses the agent’s language model to handle the instruction.
3. Pre-configuring the Agent:
You can also set up initial instructions so the agent automatically greets users like this:
model = openai.realtime.RealtimeModel(
instructions="You are a friendly assistant. Greet the user by saying: 'Hello! Welcome to our conversation. How can I assist you today?'"
)
agent = multimodal.MultimodalAgent(model=model)
session = agent.start(room, participant)
Feel free to pick whichever method feels right for your setup. And if you have any questions or need a hand, just let me know — I’m here to help!some-breakfast-27057
08/02/2025, 4:02 AMtall-airline-16756
08/02/2025, 4:03 AMconversation.item.delete method to remove specific items from the conversation history:
this.conversation.item.delete(itemId);
2. Create a New Empty Message:
Once you’ve deleted the items, create a new empty user audio message to reset the conversation:
this.conversation.item.create(this.#createEmptyUserAudioMessage(1));
3. Clear Audio Buffer:
If there’s any buffered audio you want to clear, just use:
this.inputAudioBuffer.clear();
Quick heads-up:
• By default, every new agent session starts with a fresh conversation history. But if you’d like to keep the context, you can pass the chat_ctx parameter in the agent constructor.
• Clearing the history makes sure the model starts with a clean slate, so there’s no leftover context from before.
If you have any questions or want a hand with setting this up, just let me know—I’m here to help!
Sources: OpenAI Realtime API integration guide | LiveKit Docs | Workflows | LiveKit Docs | plugins/openai/src/realtime/api_proto.ts | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...some-breakfast-27057
08/02/2025, 4:04 AMtall-airline-16756
08/02/2025, 4:05 AMInputAudioBufferClearEvent to clear out the audio buffer like this:
const clearBufferEvent = {
type: 'input_audio_buffer.clear'
};
session.queueMsg(clearBufferEvent);
2. Clear Conversation History:
To remove specific items from the conversation history, just use the `ConversationItemDeleteEvent`:
`const deleteEvent = {
type: 'conversation.item.delete',
item_id: 'ITEM_ID_HERE'
};
session.queueMsg(deleteEvent);`Make sure to swap out ITEM_ID_HERE with the actual ID of the conversation item you want to delete. You’ll want to repeat this for each item to clear everything.
Here’s a complete example to make it clearer:
// Clear audio buffer
const clearBufferEvent = {
type: 'input_audio_buffer.clear'
};
session.queueMsg(clearBufferEvent);
// Clear conversation history
const deleteEvent = {
type: 'conversation.item.delete',
item_id: 'ITEM_ID_HERE'
};
session.queueMsg(deleteEvent);
If you have any questions or want a hand with implementing this, just let me know—I’m here to help!some-breakfast-27057
08/02/2025, 4:05 AMtall-airline-16756
08/02/2025, 4:06 AMclearChats. It wipes out all chat records for a user in one go. Here’s the scoop on how it works:
1. Retrieve All Chat IDs:
The function grabs all the chat IDs linked to the user.
2. Delete All Chats:
Then, it goes through those chat IDs and deletes them all in one smooth operation.
3. Update the User Interface:
Finally, it makes sure the UI updates to show the cleared history.
If you’re setting this up, you can call the clearChats function either through code or a UI button like ClearHistory. Just give me a shout if you want a hand getting it going!
Sources: client/components/sidebar-list.tsxsome-breakfast-27057
08/02/2025, 4:06 AMtall-airline-16756
08/02/2025, 4:07 AMclearChats function to clear your entire conversation history in the LiveKit OpenAI real-time agent—it’s pretty straightforward!
1. Access the Clear History Component:
The clearChats function is part of a ClearHistory React component. This component includes a handy button that lets you clear your chat history whenever you want.
2. Trigger the Clear Action:
When you click the "Clear history" button, you’ll see a confirmation dialog pop up. If you confirm, the clearChats function kicks in.
3. Execute the clearChats Function:
Here’s what happens next:
◦ It first checks if you’re logged in.
◦ Then, it grabs all your chat records.
◦ Deletes those chats from the database using a transaction pipeline.
◦ Finally, it takes you back to the home page once everything’s cleared.
1. Update the UI:
Once your history is cleared, the UI refreshes to show that your chat history is gone, along with a message letting you know there’s nothing saved.
This feature is all about giving you control and peace of mind by letting you delete your conversation history whenever you need. If you want a hand setting this up, just let me know—I’m here to help!some-breakfast-27057
08/02/2025, 4:07 AMtall-airline-16756
08/02/2025, 4:08 AM