how can I set up the livekit agent to only respond...
# ask-ai
h
how can I set up the livekit agent to only respond when specifically called upon
t
Thanks for reaching out, Julian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To configure a LiveKit agent to only respond when specifically called upon, follow these steps: 1. Set Up Explicit Agent Dispatch: Configure the agent with an explicit dispatch rule by setting the
agent_name
in the
WorkerOptions
. This disables automatic dispatch. Example:
Copy code
if __name__ == "__main__":
    cli.run_app(WorkerOptions(
        entrypoint_fnc=entrypoint,
        agent_name="my-specific-agent"  # Disables automatic dispatch
    ))
2. Implement Conditional Response Logic: Modify the agent's instructions to only respond to specific triggers. Example:
Copy code
class MyAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a helpful agent. Only respond when explicitly called.",
            stt=deepgram.STT(),
            llm=openai.LLM(model="gpt-4o-mini"),
            tts=cartesia.TTS(),
            vad=silero.VAD.load(),
        )
        self.waiting_for_trigger = True

    async def on_enter(self):
        self.session.say("Waiting for trigger...")
3. Set Up Request Handling: Use the
request_fnc
in
WorkerOptions
to control when the agent accepts or rejects job requests. Example:
Copy code
async def handle_request(request: JobRequest):
    if request.metadata.get("trigger_condition"):
        await request.accept(
            name="my-specific-agent",
            identity="my-specific-agent-id",
        )
    else:
        await request.reject()

if __name__ == "__main__":
    cli.run_app(WorkerOptions(
        entrypoint_fnc=entrypoint,
        request_fnc=handle_request
    ))
This setup ensures the agent only responds when explicitly called. Let me know if you need further clarification or additional examples. Sources: Anatomy of an Agent | LiveKit Docs | Agents telephony integration | LiveKit Docs | examples/voice_agents/toggle_io.py