Architecture
PSTN callers dial your number; your SIP provider forwards the call to the Zero Runtime SIP Gateway, and a routing rule routes it to your agent by matching its agent id. The agent can run on your own machine or servers, or on Zero Runtime Cloud.For outbound calls, your agent dials through an outbound gateway to the SIP provider, which places the PSTN call.
Prerequisites
- Python 3.11 or higher.
- A Zero Runtime Auth token (
ZERORUNTIME_AUTH_TOKEN). Generate one in the Zero Runtime Dashboard. - A phone number from Twilio, Plivo, Vonage, or Telnyx, plus access to its console.
Quickstart
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 and python-dotenv. Every provider plugin ships with zrt.Configure environment variables
Store API keys and tokens in a
.env file in your project root.- Cascade
- Realtime
.env
Build the agent
For telephony, the agent must register itself so calls can be routed to it. With your Keep the process running. It registers with Zero Runtime using the ID
zeroruntime.serve() registers the agent under its agent id automatically. The agent half is the same as any voice agent. Pick your language.For telephony, the agent must register itself with Zero Runtime so calls can be routed to it. The agent needs a unique agent id for the routing rule to match. Set ZERORUNTIME_AGENT_ID to that id (it defaults to zeroruntime_agent) and start it with zeroruntime.serve(), which registers it automatically. Inbound calls arrive through routing, so there is no need to self-invoke a session.- Cascade
- Realtime
.env configured and dependencies installed, run the agent:MyTelephonyAgent.Deploying to Zero Runtime Cloud instead? Run
zeroruntime init and zeroruntime up --env .env (see Zero Runtime Cloud). Cloud assigns the agent ID, so use the Agent ID that zeroruntime up prints wherever this guide uses MyTelephonyAgent.Add a phone number
- Import number
- Bring your own SIP (BYOS)
Import a number you already own from a supported provider (Twilio or Plivo). The video uses Twilio.
- Open Telephony. In the Zero Runtime Dashboard, open Telephony and select Add Number → Import Number.
- Choose a provider. Select Twilio or Plivo.
- Enter the details. Enter a Name For Phone Number, your provider credentials (Account SID and Auth Token for Twilio, or Auth ID and Auth Token for Plivo), and the phone number.
- Import. Select Import Number. The number is active and ready to use.
Create a routing rule
A routing rule links your phone numbers to an agent:
- Inbound: calls to the number are answered by the agent.
- Outbound: the agent places calls from the number, one at a time or through batch calls.
- Self-hosted: the value of
ZERORUNTIME_AGENT_ID(hereMyTelephonyAgent). Keepmain.pyrunning so the agent is registered when you verify its ID. - Zero Runtime Cloud: the Agent ID printed by
zeroruntime up.
- Dashboard
- API
- Create the rule. Open Telephony → Routing Rules and select Create Routing Rule. Choose Inbound or Outbound, enter a Routing Rule Name, and select your phone numbers.
- Add your agent. Under Agent Configuration, enter your agent’s ID in Agent Name or ID, then select Verify Agent ID.
- Save. Select Create Rule.
Place a call
- Inbound
- Outbound
Call your number from any phone. The agent answers with its greeting from
on_enter.If the call isn’t answered, check that:main.pyis running, or your Cloud deployment is live (zeroruntime version describe).- The number has an inbound routing rule with your agent’s ID.
- For BYOS, your carrier sends calls to the Inbound Gateway URL.
Verify
- The agent registers under the ID
MyTelephonyAgentand the worker process stays running. - An incoming call reaches the agent and you hear the greeting.
- Your number shows a routing rule in Telephony > Phone Numbers.
- Outbound calls dial the target number through your outbound gateway.
What’s Next
Telephony overview
Explore SIP connect, call routing, and integrations.
Managing calls
Handle call transfer, DTMF events, and webhooks.