Skip to main content

Architecture

A WhatsApp caller reaches the Meta Business Platform, which forwards the call over SIP to the Zero Runtime SIP Gateway. A routing rule invokes your self-hosted agent by matching its agent_id.
WhatsApp voice agent architecture: a WhatsApp user calls through the Meta Business platform, which bridges the call over SIP to the ZRT SIP Gateway (inbound and outbound). A routing rule sends it into ZRT Cloud, where the routing layer hands it to the ZRT Runtime hosting your AI agent, and the ZRT API Server invokes the agent to start the call.

Prerequisites

  • Meta side:
    • A verified Meta Business Manager account.
    • A phone number verified in your WhatsApp Business Account (WABA).
    • A Meta Developer App with the whatsapp_business_management permission enabled.
    • A permanent user access token for the Meta Graph API.
  • Zero Runtime side: A ZRT Auth token (ZRT_AUTH_TOKEN). Generate one in the Zero Runtime Dashboard.

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.
New to uv? See the uv install guide.

Configure environment variables

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

Build the agent

The agent must register itself with Zero Runtime so calls can be routed to it. Give it a unique agent_id and start it with zrt.serve(), which registers it automatically. WhatsApp calls arrive through your routing rule, so there is no playground to open. Just keep the process running.
main.py
Declare your dependencies in a pyproject.toml, then let uv build the environment and run the agent:
pyproject.toml
Keep the process running. It registers with Zero Runtime using the ID agent1.
Agent running locally and registering with Zero Runtime

Configure Zero Runtime gateways

Set up two gateways so Zero Runtime can route WhatsApp calls in and out. Use the Dashboard or the API for each.1. Inbound gateway: the entry point for incoming WhatsApp calls.
  1. In the Zero Runtime Dashboard, go to Telephony > Inbound Gateways and click Add.
  2. Enter a gateway name (e.g. WhatsApp Gateway).
  3. Add your WhatsApp Business phone number and click Create.
2. Outbound gateway: lets the agent dial out to WhatsApp numbers. First fetch the SIP credentials from Meta:
Use the returned hostname (address) and sip_user_password (password) to create the gateway.
  1. In the Zero Runtime Dashboard, go to Telephony > Outbound Gateways and click Add.
  2. Enter a gateway name.
  3. Provide the SIP details from Meta (the hostname as the address, your WhatsApp number as the username, and sip_user_password as the password), then click Create.

Create a routing rule

Connect the inbound gateway to your agent by ID. The agent ID must match the agent_id you pass to your agent (registered by zrt.serve()).
  1. In the Zero Runtime Dashboard, go to Telephony > Routing Rules and click Add.
  2. Select your inbound gateway (e.g. WhatsApp Gateway).
  3. Add your WhatsApp Business phone number.
  4. Set Dispatch to Agent and Agent Type to Self Hosted.
  5. Enter the Agent ID as agent1 (must match main.py) and click Create.

Enable WhatsApp SIP forwarding

Tell Meta to forward incoming WhatsApp calls to your inbound gateway. Substitute the inbound gateway hostname (it appears in the dashboard).
A successful response is { "success": true }.

Place a test call

Make sure your main.py script is still running locally before making or receiving calls. The agent must be active to handle any communication.
From a different WhatsApp account, place a voice call to your WhatsApp Business number. The agent answers and greets you.

Verify

  • The agent registers under the ID agent1 and the worker process stays running.
  • An incoming WhatsApp call reaches the agent and you hear the greeting.
  • Outbound calls dial the target WhatsApp number through your outbound gateway.
Common errors:
  • agent_id mismatch: the routing rule’s agentId must exactly match the agent’s agent_id.
  • Missing Meta permission: the access token needs whatsapp_business_management.
  • SIP forwarding off: the Meta calling.sip.status must be ENABLED.
  • Agent not running: the worker process must be alive to accept the inbound call.

What’s Next

Telephony docs

Explore call transfer, DTMF, voicemail, and more.

Deploy an agent

Move from local to production.

References