import zrt
from zrt import Agent, Pipeline, EOUConfig, InterruptConfig
from zrt.plugins import DeepgramSTT, GoogleLLM, CartesiaTTS, SileroVAD, TurnDetector, RNNoise
AGENT_ID = "assistant"
pipeline = Pipeline(
stt=DeepgramSTT(),
llm=GoogleLLM(model="gemini-2.5-flash", max_output_tokens=8192),
tts=CartesiaTTS(),
vad=SileroVAD(threshold=0.4),
turn_detector=TurnDetector(model="echo-large"),
denoise=RNNoise(),
eou_config=EOUConfig(mode="ADAPTIVE", min_max_speech_wait_timeout=[0.1, 0.3]),
interrupt_config=InterruptConfig(
interrupt_min_duration=0.5,
interrupt_min_words=2,
resume_on_false_interrupt=True,
),
)
class Assistant(Agent):
def __init__(self):
super().__init__(
agent_id=AGENT_ID,
instructions="You are a friendly voice assistant. Keep replies short.",
pipeline=pipeline,
)
async def on_enter(self):
await self.session.say("Hi! How can I help?")
async def on_exit(self):
pass
if __name__ == "__main__":
# Pass the class itself (not an instance): serve() builds a fresh Assistant +
# pipeline per call, which is required for correct per-call state under concurrent calls.
zrt.serve(Assistant, on_ready=lambda: zrt.invoke(AGENT_ID, room=zrt.Room(playground=True)))