few-soccer-7112
07/10/2025, 9:53 PMtall-airline-16756
07/10/2025, 9:53 PMtall-airline-16756
07/10/2025, 9:54 PMon_enter
or on_exit
) to control behavior before and after a switch.
An example pattern is to have your realtime agent (Nova Sonic) invoke a function (e.g., switch_to_pipeline
) when the target node is reached, returning the new pipeline agent and effectively handing off control. User context and chat state can be preserved between agents, supporting a seamless experience.
Sources: Building voice agents | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs | Voice pipeline nodes | LiveKit Docs | Workflows | LiveKit Docs | examples/voice_agents/restaurant_agent.py | complex-agents/shopify-voice-shopper/shopify.pyfew-soccer-7112
07/10/2025, 9:55 PMtall-airline-16756
07/10/2025, 9:57 PMclass VoicePipelineAgent(Agent):
def __init__(self):
super().__init__(
instructions="You are now using a voice pipeline",
stt=deepgram.STT(),
llm=openai.LLM(),
tts=cartesia.TTS(),
)
async def on_enter(self):
# Custom logic when this agent becomes active
await self.session.say("I've switched to the voice pipeline agent")
async def on_exit(self):
# Custom logic before handing off to another agent
await self.session.say("Exiting the voice pipeline agent")
• on_enter
is like your agent's warm welcome moment - it runs when the agent starts up. You can set up initial states, transfer context, or just say a friendly hello!
• on_exit
is the agent's polite goodbye, happening right before switching to a new agent. Perfect for tidying up, saving important info, or sending a final message.
Pretty neat, right? This approach lets you create super smooth, personalized transitions between different stages of your agent workflow. It's all about making your AI interactions feel more natural and responsive!
Sources: Voice pipeline nodes | LiveKit Docs | complex-agents/medical_office_triage/triage.py | examples/voice_agents/restaurant_agent.py