viola-agent
A self-hosted WhatsApp AI agent. A company deploys one copy, fills in its own Twilio, LLM (OpenRouter or UniAPI) and optional billing credentials, and gets an assistant its customers and staff can message on WhatsApp. Its own backend can talk to the same agent over an OpenAI-compatible API and send proactive WhatsApp messages.
- One process, one port.
viola serveruns the Twilio webhook, the/v1/*API and/health. Redis holds short-lived state (de-duplication, rate limits, the 24-hour window); everything else lives in one data folder. - One deployment = one company. Each deployment has its own
.env, Twilio account, public URL and data. - Safe defaults. Twilio signatures are verified, every
/v1/*call needs a server key, and the agent has no tools until you list them inconfig.json. - WhatsApp's rules built in. Free text inside the 24-hour window, approved templates outside it, idempotent sends.
Full setup guide: docs/getting-started.md. It goes through
every .env variable, HTTPS, Twilio, templates, customisation, backups and
troubleshooting. The API contract is docs/openapi.json.
Quick start (Docker)
You need Docker Compose v2, a Twilio account with a WhatsApp sender (the sandbox is fine for a first test), an OpenRouter or UniAPI key, and a public HTTPS address for the server.
git clone https://github.com/virpluzteam/viola-agent.git && cd viola-agent
cp .env.example .env && chmod 600 .env
# fill in TWILIO_*, PUBLIC_BASE_URL, LLM_API_KEY, LLM_MODEL_DEFAULT (see the guide)
docker compose up -d
docker compose exec viola viola doctor # checks every credential and service
docker compose up -d pulls ghcr.io/virpluzteam/viola-agent (amd64 and arm64) and starts
it with Redis. Pin a release with VIOLA_IMAGE=ghcr.io/virpluzteam/viola-agent:0.2.2 in
.env. The agent listens on 127.0.0.1:8900; the next two steps make it reachable from
Twilio.
The repository and image are private for now. Run
docker login ghcr.iowith an account (or a token withread:packages) that can readvirpluzteampackages first.
Without Docker
python3 -m venv .venv && .venv/bin/pip install 'viola-agent[twilio]'
cp .env.example .env # APP_ENV=development runs without Redis
.venv/bin/viola serve --port 8900
Production (APP_ENV=production) requires REDIS_URL. Background tasks (cron reminders,
proactive delivery) run only with VIOLA_API_BACKGROUND_TASKS=true; the Docker image sets
it for you.
Expose the webhook over HTTPS
Twilio must reach https://<your domain>/twilio/webhook. Set PUBLIC_BASE_URL to the
public base URL first: signatures are checked against it, and a mismatch rejects every
message with 403. Only /twilio/* (and /health) needs to be public; keep /v1/* for
your own backend.
| Option | When | How |
|---|---|---|
| Bundled Caddy | Server with a public IP and a domain | COMPOSE_PROFILES=caddy and VIOLA_DOMAIN=agent.example.com in .env. Caddy gets the certificate and publishes only /twilio/* and /health. |
| Cloudflare Tunnel | No open ports; domain on Cloudflare | Named tunnel to http://127.0.0.1:8900, path ^/(twilio/.*|health)$ |
| Your own reverse proxy | nginx / Caddy already on 80/443 | Proxy /twilio/* and /health to 127.0.0.1:8900 |
| ngrok | Development only | ngrok http 8900. Free hostnames change on restart, so update PUBLIC_BASE_URL and Twilio each time. |
Details: Expose it over HTTPS.
Connect Twilio
In the Twilio Console, open your WhatsApp sender (sandbox: Messaging → Try it out → Send a WhatsApp message → Sandbox settings) and set:
- When a message comes in:
https://<your domain>/twilio/webhook,POST - Status callback URL (optional):
https://<your domain>/twilio/status
Message the number on WhatsApp; the agent answers within a few seconds. The webhook
replies 202 at once and sends the answer through Twilio when it's ready. Repeated
MessageSids are ignored and each sender is rate-limited.
Each deployment uses its own domain. Two companies never share one webhook URL: a deployment rejects signatures from any Twilio account but its own.
Message templates
WhatsApp allows free text only within 24 hours of the customer's last message. Outside
that window only Meta-approved templates may be sent. /v1/notify, cron reminders and
heartbeat all follow the same rule:
- Window open and
fallback_textgiven: the text is sent. - Otherwise, if the
template_idis approved: the template is sent. - Otherwise nothing is sent, and the response is
422 template_requiredwith the reason. This is the rule working, not a failure.
The bundled catalogue viola/notify/templates.yaml has welcome, reminder, follow-up and
generic notification templates in en and zh_HK. To use your own, copy it to
$VIOLA_DATA_DIR/templates.yaml (Docker: ./data/templates.yaml) and edit it. Then
create the templates in your Twilio account and submit them to Meta:
docker compose exec viola viola templates sync --dry-run # preview
docker compose exec viola viola templates sync # create + submit for approval
docker compose exec viola viola templates status # check approval later
ContentSids and approval statuses are kept in content_sid_map.json in the data folder.
Only approved templates are used.
Calling the agent from your backend
Set VIOLA_API_SERVER_KEY in .env. Without it every /v1/* route returns 404. Only
your backend calls the API; never put the key in a browser. During key rotation,
VIOLA_API_SERVER_KEY_PREVIOUS is accepted too.
# Talk to the agent as one of your users (OpenAI-compatible; "stream": true for SSE)
curl https://agent.example.com/v1/chat/completions \
-H "Authorization: Bearer $VIOLA_API_SERVER_KEY" -H "Content-Type: application/json" \
-d '{"user": "u_42", "session_id": "support-7",
"messages": [{"role": "user", "content": "What are your opening hours?"}]}'
# Send a proactive WhatsApp message
curl https://agent.example.com/v1/notify \
-H "Authorization: Bearer $VIOLA_API_SERVER_KEY" -H "Content-Type: application/json" \
-d '{"to": "+85212345678", "template_id": "reminder",
"variables": {"reminder_text": "your appointment is tomorrow at 10:00"},
"fallback_text": "Hi! Your appointment is tomorrow at 10:00.",
"idempotency_key": "appt-123-reminder"}'
- Chat:
useris required and is the user your backend authenticated (the agent doesn't check logins). History is kept perportal:<user>:<session_id>, and usage is billed toportal:<user>. Send only the new message; the agent keeps the history. - Notify:
200sent,422 template_required,502 twilio_error,409key reused with a different body (or still sending),400bad request. A repeatedidempotency_keynever sends twice; the first result is returned for 7 days.
Every route, body, status code and limit is described in
docs/openapi.json (OpenAPI 3.1). Load it into Swagger UI, Redoc or a
client generator, or print the version you're running with viola openapi.
Configuration
| Where | What |
|---|---|
.env |
Secrets, deployment values and switches: Twilio, LLM, billing, Redis, server key. See .env.example. |
config.json in the data folder (optional) |
Behaviour: tools for each channel profile (whatsapp, portal), MCP servers, transcription language. Tools are off until listed. |
workspace/ in the data folder |
Persona and instructions (SOUL.md and friends), chat history and memory |
When .env and config.json disagree, the environment wins.
Feature switches
Off by default. Each one makes background LLM calls, and those calls are billed.
| Variable | What it does |
|---|---|
VIOLA_DREAM_ENABLED |
Periodically consolidates chat history into long-term memory |
VIOLA_HEARTBEAT_ENABLED |
Periodically runs the tasks in workspace/HEARTBEAT.md |
The startup summary shows the state of each switch; viola doctor also lists the tools
each profile can use.
Data and backups
Everything the agent keeps is in one folder: ./data with Docker (VIOLA_DATA_PATH), or
$VIOLA_DATA_DIR (default ~/.viola) without it. That's config.json, the workspace
(chat history, memory, persona), media, content_sid_map.json, and the SQLite files
(billing outbox, notification idempotency). Back it up with the agent stopped:
docker compose stop viola
tar czf viola-data-$(date +%F).tgz data/
docker compose start viola
Redis only holds short-lived state and needs no backup.
Updating
git pull # compose file and docs
docker compose pull && docker compose up -d
With a pinned VIOLA_IMAGE, change the tag first. With pip: pip install -U 'viola-agent[twilio]'.
Development
python3.13 -m venv .venv && .venv/bin/pip install -e ".[twilio]" --group dev # pip >= 25.1; or: uv sync --all-extras
.venv/bin/ruff check viola/
.venv/bin/pytest
docker compose up -d --build # run this checkout instead of the released image
Layout: viola/ is the package (viola/api/ has the HTTP routes, viola/notify/ has
templates and proactive sends), tests/ mirrors it, and docs/ has the guides and the
OpenAPI document.
If you change a /v1/* route or its body, update the models in viola/api/openapi.py and
regenerate the document. tests/api/test_openapi.py fails when the document, the models
and the served routes disagree.
.venv/bin/viola openapi --output docs/openapi.json
CI (.github/workflows/ci.yml) runs ruff, pytest (Python 3.11–3.14, Linux and Windows),
a gitleaks scan of the full history (allowlist example values in .gitleaks.toml;
one-off false positives go in .gitleaksignore), a wheel
build and an image build with a smoke test (.github/scripts/smoke-image.sh).
Releasing
-
Set
versioninpyproject.toml(e.g.0.2.2), regeneratedocs/openapi.json(it carries the version), and merge tomain. Wait for CI to pass. -
Tag that commit and push the tag:
git tag v0.2.2 && git push origin v0.2.2
.github/workflows/release.yml checks the tag matches the version and runs CI. It then
publishes the wheel and sdist to PyPI, pushes the image to GHCR as 0.2.2, 0.2 and
latest, and creates a GitHub release. One-time setup is described at the top of that
file.
License
MIT. See LICENSE.
Metadata
Release files for viola-agent 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| viola_agent-0.2.2.tar.gz | 357.2 kB | With provenance | Details for viola_agent-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| viola_agent-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for viola_agent-0.2.2-py3-none-any.whl |
Total release size: 787.0 kB
Release files / viola_agent-0.2.2.tar.gz
| Download URL | viola_agent-0.2.2.tar.gz |
|---|---|
| Size | 357.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1165da26919e23a49b403aad0418498aeff6d4872e1afdaff9eef7e7ef42279
|
|
BLAKE2b-256 checksum How to use checksums |
31554d7e05e80059e8a9ca5ce48c65a7a7c3a23d88ad5d1d094d55ac7a7b6589
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / viola_agent-0.2.2-py3-none-any.whl
| Download URL | viola_agent-0.2.2-py3-none-any.whl |
|---|---|
| Size | 429.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f80a53f111b5e043cd0e83ced5d7a0134a394f4524ab769319a29c1a21551710
|
|
BLAKE2b-256 checksum How to use checksums |
3291d5829cadc77f351c7e9bccbb0952b0b6b342e3234bc8aac249b8e9391b97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for viola-agent 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for viola_agent-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.