astonishing-horse-62951
09/24/2025, 10:40 AMtall-airline-16756
09/24/2025, 10:40 AMtall-airline-16756
09/24/2025, 10:42 AMastonishing-horse-62951
09/24/2025, 10:44 AMtall-airline-16756
09/24/2025, 10:44 AM// Agent-side code
ctx.room.localParticipant.registerRpcMethod('stop_agent', async () => {
ctx.shutdown('Stopped by user request');
return 'Agent stopping';
});
Then, from your React app, you can call this RPC like so:
// React-side code
const { room } = useRoomContext();
const stopAgent = () => {
room.localParticipant.rpc('stop_agent');
};
return <button onClick={stopAgent}>Stop Agent</button>;
2. Another Option: End the Entire Room Session:
If your goal is to end the session for all participants, you can disconnect the local participant from the room using this method:
const { disconnect } = useConnection();
const endSession = () => {
disconnect(); // This disconnects the frontend from the room
};
If you’d like, I’m here to help you walk through setting up the React component or the agent-side code step-by-step. Just let me know!
Sources: Text and transcriptions | LiveKit Docs | Job lifecycle | LiveKit Docs | Inside a session | LiveKit Docs | Inside a session | LiveKit Docs | Turn detection and interruptions | LiveKit Docsastonishing-horse-62951
09/24/2025, 10:47 AMtall-airline-16756
09/24/2025, 10:48 AMinterrupt() method on your agent session. This handy method stops any speech that's happening right now and clears any responses waiting in line, all while keeping your agent connected and ready for whatever comes next.
Here’s a quick example in Python to get you started:
# Stop the agent's current speech
session.interrupt()
And if you’re working with Node.js, it looks like this:
import { voice } from '@livekit/agents';
const session = new voice.AgentSession({
// ... configuration
});
// Stop the agent's current speech
session.interrupt();
Now, if you happen to have a specific speech handle you want to stop, you can do that too!
In Python:
handle = session.say("Hello world")
handle.interrupt()
And in Node.js:
const handle = session.say('Hello world');
handle.interrupt();
Does this sound good? If you'd like, I’d be happy to help you add this feature to your React button—just let me know!
Sources: Text and transcriptions | LiveKit Docs | Turn detection and interruptions | LiveKit Docs | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | VoicePipelineAgent | LiveKit Docs