when ever the Realtime agent is ready it need to ...
# ask-ai
s
when ever the Realtime agent is ready it need to automatically greet the user , what to do for that?
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help with that. You're asking how to have a Realtime agent automatically greet the user when it becomes ready. Use the agent's on_enter lifecycle hook to run code as soon as the agent becomes active, and call
session.generate_reply
to send the greeting. For example:
Copy code
async def on_enter(self):
    await self.session.generate_reply(
        instructions="Greet the user with a warm welcome",
    )
This works for both the STT‑LLM‑TTS pipeline and Realtime model agents. Do you want the greeting to be spoken (TTS), shown as text, or both? If spoken, tell me which voice/language you want and I can show the exact TTS parameters. Sources: Pipeline nodes and hooks | LiveKit docs
s
so this on_enter is for initial greeting ??
t
Yes —
on_enter
is the lifecycle hook you use for an initial greeting when the agent becomes active. It runs once when the agent enters the ready/active state, so it’s ideal for sending a welcome message. If you want an example:
Copy code
async def on_enter(self):
    await self.session.generate_reply(instructions="Greet the user with a warm welcome")
Do you want the greeting as text, TTS (spoken), or both? If TTS, tell me desired voice/language and I’ll give the exact parameters.
s
will this work for realtimeagent. i am using gemini real time .
t
Yes —
on_enter
works for a Gemini Realtime agent. It runs when the agent becomes active, so use it to send your initial greeting (text, TTS, or both). Example for Gemini RealtimeAgent:
Copy code
async def on_enter(self):
    await self.session.generate_reply(
        instructions="Greet the user with a warm welcome"
    )
Do you want the greeting spoken with TTS (and if so, which voice/language) or only text? I can provide the exact TTS parameters and a fuller example for your setup.
s
give a simple Realtime agent code with this implementation
t
Below is a simple Gemini Realtime agent example that uses the
on_enter
lifecycle hook to automatically greet the user when the agent becomes ready. This example shows a minimal agent class and uses
session.generate_reply
to send a greeting (works for text, or TTS if your pipeline supports it).
Copy code
# Simple Gemini Realtime agent with automatic greeting on enter

class WelcomeAgent(RealtimeAgent):
    async def on_enter(self):
        # Send a warm welcome when the agent becomes active
        await self.session.generate_reply(
            instructions="Greet the user with a warm welcome",
        )

    async def on_message(self, message):
        # Handle incoming user messages (simple echo example)
        user_text = message.get("text", "")
        if user_text:
            await self.session.generate_reply(
                instructions=f"You said: {user_text}"
            )
Notes: • Replace
RealtimeAgent
with your actual base class if it has a different import path in your environment. • If you want a spoken greeting (TTS), add TTS parameters inside
generate_reply
(voice/language). Tell me the desired voice/language and I’ll show the exact parameters.
s
why in code i cant see
on_enter??
t
Good question — yes,
on_enter
is an optional lifecycle method you must add (override) on your agent class. If you don't see it in example code, that code simply didn't include the optional hook or it uses a different place to trigger greetings. Quick explanation and minimal example for a Gemini Realtime agent:
Copy code
from livekit.agents import Agent, AgentSession
from livekit.plugins import google

class MyGeminiAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            llm=google.realtime.RealtimeModel(
                model="gemini-2.0-flash-exp",
                voice="Puck",
                instructions="You are a helpful assistant."
            )
        )

    async def on_enter(self):
        # runs once when agent becomes active — use this for the initial greeting
        await self.session.generate_reply(
            instructions="Hello! I'm ready. How can I help you today?"
        )

# entrypoint example
async def entrypoint(ctx):
    session = AgentSession()
    await session.start(agent=MyGeminiAgent(), room=ctx.room)
If you want the greeting to be spoken, tell me the voice/language and I’ll add the exact TTS parameters. Sources: Pipeline nodes and hooks | LiveKit docs