SIP Integration¶
Stimm can connect incoming phone calls to AI agents via SIP (Session Initiation Protocol). This allows you to offer voice-based customer support, interactive voice response (IVR), or any other telephony-powered application.
Overview¶
The SIP integration works as follows:
- An external SIP client (softphone, IP phone, or telephony carrier) places a call to a configured phone number.
- The LiveKit SIP server receives the call and creates a LiveKit room with the prefix
sip-inbound-. - The Stimm SIP bridge detects the new room and spawns an agent specifically for that call.
- The agent joins the room and begins a real-time voice conversation with the caller.
- When the call ends, the room is cleaned up and the agent process terminates.
Prerequisites¶
- A running LiveKit instance with SIP support enabled (the default Docker Compose includes this).
- Redis (used for SIP trunk and dispatch rule storage).
- At least one configured agent.
Enabling SIP Bridge¶
- Set the environment variable
ENABLE_SIP_BRIDGE=truein your.envfile (root and/ordocker/stimm/.env). - Restart the Stimm backend (or the whole Docker Compose stack).
Configuring SIP Trunks¶
A SIP trunk defines how LiveKit accepts incoming calls. You can create a trunk using the provided script:
This script stores the trunk configuration in Redis. You can list existing trunks with:
To update a trunk’s phone number or allowed addresses:
Or use the shell wrapper:
Configuring Dispatch Rules¶
Dispatch rules determine which agent answers a call based on the called number. The rules are stored in Redis under the key sip_dispatch_rules.
To set up a rule that routes calls to +1234567 to agent support:
The script will guide you through interactive rule creation. Alternatively, you can edit the Redis key directly.
Making a Test Call¶
- Ensure all services are running (
docker compose up). - Use a SIP client (e.g., MicroSIP, Linphone) to dial the phone number you configured (e.g.,
+1234567). - The call should be answered by the default agent (or the agent specified in dispatch rules).
Monitoring¶
Health Endpoints¶
GET /health/sip-bridge– Basic health check (enabled/running status).GET /health/sip-bridge-status– Detailed status (active rooms, agent processes, errors).
Logs¶
SIP bridge logs are written with the SIP prefix. You can view them with:
Cleaning Up Stale Rooms¶
If a call ends abruptly, rooms may remain in LiveKit. You can clean them up using the CLI:
# List all LiveKit rooms
uv run python -m src.cli.main livekit list-rooms
# Delete all SIP rooms and terminate agent processes
uv run python -m src.cli.main livekit clear-sip-bridge
# Delete all LiveKit rooms (SIP and non-SIP)
uv run python -m src.cli.main livekit clear-rooms
Advanced Configuration¶
SIP Server Settings¶
The LiveKit SIP server is configured via sip-server-config.yaml. Refer to the LiveKit SIP documentation for advanced options (codecs, DTMF, encryption, etc.).
Custom Agent per Number¶
You can modify the dispatch rules to route different numbers to different agents. The SIP bridge reads the agent_name from the rule and spawns that specific agent.
Fallback Agent¶
If no dispatch rule matches the called number, the SIP bridge uses a default agent (configurable via environment variable DEFAULT_SIP_AGENT). If that variable is not set, it uses the first agent found in the database.
Troubleshooting¶
- “No agent spawned”: Check that
ENABLE_SIP_BRIDGE=trueand that there is at least one agent in the database. - “Call rejected”: Verify that the SIP trunk is correctly configured and that the caller’s IP is allowed.
- “One-way audio”: Ensure your network allows bidirectional UDP traffic on the RTP ports (50000-60000 by default).
- “High latency”: Consider using a media server closer to the caller or enabling OPUS low-bitrate codec.
Next Steps¶
- Learn about Managing Agents to create specialized agents for phone support.
- Explore the Architecture to understand how SIP fits into the overall system.
- Read the LiveKit SIP documentation for advanced telephony features.