Skip to main content

Prerequisites

Before you begin, ensure you have:

Understanding the Architecture

Before diving into implementation, choose the pipeline architecture that fits your use case.
Cascade processes audio through distinct stages for maximum control:
The cascade processes audio through sequential stages:User Voice InputSTT (Speech-to-Text)LLM (Large Language Model)TTS (Text-to-Speech)Agent Voice OutputThis approach provides better control over each processing stage and supports more complex AI reasoning. Power each stage through the Zero Runtime Inference gateway (one token, no per-provider keys) or bring your own provider keys.

Build the Agent

Pick your language. Each track builds the same agent on the Cascade pipeline (Deepgram STT → Google Gemini LLM → Cartesia TTS).

Setup the project

Use Python 3.11 or higher, then install the Zero Runtime Agents SDK. Create and activate a virtual environment, then install zrt. Every provider plugin ships with it.
New to uv? See the uv install guide.
Prefer to bring your own provider keys? Every provider ships with zrt. Just import from zrt.plugins.*. See the plugin pages for STT, LLM, and TTS.

Configure environment variables

Store API keys and tokens in a .env file in your project root.
.env

Create the pipeline and agent

Build the pipeline first, then create the agent that uses it. The Pipeline auto-detects its mode from the components you pass it: provide STT, LLM, and TTS for Cascade, or a single realtime model for Realtime. Define it at module scope so the agent class can reference it directly. The agent inherits from the base Agent class, the same for both pipelines. Only the pipeline setup and imports differ. instructions defines the agent’s personality, on_enter() runs when it joins the room, and on_exit() runs when it leaves.
main.py

Start the session

With the pipeline and agent defined, hand the agent class to zrt.serve(...). This wiring is the same for both pipelines.
main.py
serve() registers the agent under its agent_id and blocks, starting a fresh session for each caller. Passing the MyVoiceAgent class itself (not a pre-built instance) lets serve() construct a fresh agent + pipeline per call, which is required for correct per-call state under concurrent calls. on_ready=invoke_agent fires zrt.invoke(...) once the agent is registered, which resolves a room and returns a playground URL to open the session.

Run the project

With your .env configured and dependencies installed, run the project with Python.
Once you run this command, a playground URL appears in your terminal. Use this URL to interact with your AI agent.

Verify

  • The agent connects to the room and greets you.
  • Audio flows both ways: the agent hears you and you hear it.
  • In Cascade mode, the LLM’s responses are spoken back through TTS; in Realtime mode, the model streams speech directly.
Common errors:
  • Missing auth token: set ZRT_AUTH_TOKEN in your .env.
  • Plugin import error: make sure zrt is installed in the active virtual environment (every provider ships with it).
  • No audio: check microphone permissions, or confirm the client joined the same room.
Get started quickly with the Quick Start Example for the Zero Runtime AI Agent SDK: everything you need to build your first AI agent fast.

Troubleshooting

Common issues when setting up the project:
Make sure Python 3.11 is installed, then create the virtual environment with it.
Newer Python versions (3.13+) removed the implicit event loop. Create your virtual environment with Python 3.11.
You’re running a Python outside the project’s virtual environment. Activate it first, then install the dependencies.

What’s Next

Add tools to an agent

Let your agent call functions and act.

Pipelines

Understand the STT, LLM, and TTS flow.

References