Skip to main content
zeroruntime.serve() runs your agent as a worker: it registers the agent with Zero Runtime and waits. Each time you start a session, the worker serves it with a fresh instance of your agent. How you start one depends on where you are:
  • Local development: call zeroruntime.invoke() from your code, or run zeroruntime invoke from the CLI. Both open a playground link you can talk to.
  • Production: deploy your worker to Zero Runtime Cloud or self-host it. Sessions then start from phone calls: inbound calls reach your agent through a routing rule, and you place outbound calls with the /v2/sip/call API.

Run it locally

During development, start the worker and fire zeroruntime.invoke() from on_ready. As soon as the worker registers, it opens a playground session and prints a link you can open to talk to your agent.
Start the worker:
serve() blocks and keeps the worker running, accepting a fresh session for every caller until you stop it. Code after serve() never runs, so use on_ready for anything that should happen once the worker is up. To scale out, run more workers with the same agent ID; the runtime load-balances sessions across them.

Go to production

on_ready + invoke() is only for local testing. Remove it before you deploy, or every worker you start dispatches the agent into a new room on startup. In production, sessions come from the zeroruntime invoke CLI, or phone calls.
Then choose where your workers run:

Zero Runtime Cloud

One command deploys your agent. Zero Runtime builds, hosts, and scales it for you.

Self-Hosting

Run the worker on your own Docker host, VM, or Kubernetes cluster.

Place a phone call

Pass Sip(...) instead of a playground room to start the session on an outbound call. You need an outbound gateway set up first.

Connect to the phone network

To take or place phone calls, set up gateways in the Zero Runtime dashboard or API, and a routing rule that points at your agent ID. Your worker must be running to receive calls.
1. Create an inbound gateway: the entry point for incoming calls.
  1. Copy the Inbound URL from the Zero Runtime dashboard.
  2. Go to Twilio and create a new SIP Trunk.
  3. Go to the Origination section, paste the Inbound URL there, and save it.
2. Create a routing rule: connects the inbound gateway to your agent.
  1. From your inbound gateway, click Configure rule, then Create new routing rule.
  2. Enter a Routing Rule Name and select API Key authentication.
  3. Choose the Call Direction (Inbound).
  4. Enter the Phone Number and select a Room Type.
  5. Enter your ZERORUNTIME_AGENT_ID as the Agent ID and click Save.
3. Test it: with your worker running, dial your provider’s phone number from any phone. The agent greets you as soon as the call connects.
Using a different SIP provider? Follow its inbound setup: Telnyx, Vonage, or Plivo.
1. Create an outbound gateway: lets the agent dial out to the PSTN.
  1. In Twilio, open your SIP Trunk and go to the Termination section. Create a Termination URI and add username/password credentials.
  2. Back in the Zero Runtime Dashboard, open the outbound gateway configuration.
  3. Paste the Twilio Termination URI as the address, add the same username/password credentials, and save.
2. Place a call: with your worker running, trigger a call with the SDK or the API. Replace YOUR_ZERORUNTIME_AUTH_TOKEN and routingRuleId with your own.
For lower latency, run your agent in the same region as your SIP provider.
Using a different SIP provider? Follow its outbound setup: Telnyx, Vonage, or Plivo.

Troubleshooting

What’s Next

Create an Agent

Define the agent that serve runs.

Tools and Capabilities

Give the agent function tools and external services.

Telephony

DTMF, call transfer, and voicemail detection.

Deploy to Zero Runtime Cloud

Take your agent to production.

References

Examples

Cascade Basic

Smallest complete agent showing serve + invoke.