is it possible to interrupt the agent from js or r...
# ask-ai
g
is it possible to interrupt the agent from js or react sdk?
t
Thanks for reaching out, Oliver. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks so much for reaching out! To better assist you, could you please share a bit more about your specific use case for interrupting the agent? For example: • Are you building a client application that needs to interrupt a running agent, or are you working on the agent-side code? • Are you hoping to interrupt the agent’s speech output, or are you looking to cancel its current processing altogether? • Do you think using LiveKit’s RPC system to send custom interruption commands might work well for your situation? • Are you working specifically with LiveKit’s voice agents, or is this a custom agent implementation? Understanding these details will really help me guide you in the best way possible. Looking forward to your reply! Sources: Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | Turn detection and interruptions | LiveKit Docs | agents/src/voice/agent_activity.ts | Bringing AI avatars to voice agents
g
client app. I'd like to do the same as whatever the python code does
t
Hi there! To gently guide you through interrupting an agent from your client application using the JavaScript or React SDK, you can use LiveKit's RPC system to send a signal to the backend to trigger the interruption. Let's walk through how you can do this together: 1. Backend Setup: First, you'll want to register an RPC method on the agent backend that calls the
session.interrupt()
method. Here's a simple example:
Copy code
// Node.js Agent
ctx.room.localParticipant?.registerRpcMethod('interrupt_agent', async () => {
  await session.interrupt(); // Cancel current speech
  return 'interrupted';
});
2. Frontend Implementation: On your React app side, you can use the
LocalParticipant.rpc()
method to call this RPC. Here's how you might set that up:
Copy code
import { useLocalParticipant } from '@livekit/react-components';

function InterruptButton() {
  const { localParticipant } = useLocalParticipant();

  const handleInterrupt = async () => {
    try {
      await localParticipant.rpc('interrupt_agent');
      console.log('Agent interrupted');
    } catch (err) {
      console.error('Failed to interrupt agent:', err);
    }
  };

  return ;
}
This method lets you smoothly interrupt the agent's speech or processing directly from the client side by signaling your backend. If you have any questions or need a hand with this setup, please don’t hesitate to ask—I’m here to help! Sources: livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | Turn detection and interruptions | LiveKit Docs | docs/index.yaml | agents/src/voice/agent_activity.ts
g
so there is no way expect with RPC?
t
You’re absolutely right! The JavaScript and React SDKs don’t have a built-in way to directly interrupt the agent. Instead, the interruption logic—like `session.interrupt()`—happens on the backend. So, using RPC is the best way to let the backend know it should perform the interruption. If you’re facing any specific challenges or want to explore other options, please feel free to share. I’m here to help you every step of the way!