viola-agent 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. viola_agent-0.2.1/.gitignore +101 -0
  2. viola_agent-0.2.1/LICENSE +21 -0
  3. viola_agent-0.2.1/PKG-INFO +198 -0
  4. viola_agent-0.2.1/README.md +133 -0
  5. viola_agent-0.2.1/THIRD_PARTY_NOTICES.md +5 -0
  6. viola_agent-0.2.1/pyproject.toml +163 -0
  7. viola_agent-0.2.1/viola/__init__.py +33 -0
  8. viola_agent-0.2.1/viola/__main__.py +8 -0
  9. viola_agent-0.2.1/viola/agent/__init__.py +20 -0
  10. viola_agent-0.2.1/viola/agent/autocompact.py +121 -0
  11. viola_agent-0.2.1/viola/agent/context.py +339 -0
  12. viola_agent-0.2.1/viola/agent/hook.py +141 -0
  13. viola_agent-0.2.1/viola/agent/loop.py +2058 -0
  14. viola_agent-0.2.1/viola/agent/memory.py +1092 -0
  15. viola_agent-0.2.1/viola/agent/model_presets.py +65 -0
  16. viola_agent-0.2.1/viola/agent/profiles.py +160 -0
  17. viola_agent-0.2.1/viola/agent/progress_hook.py +178 -0
  18. viola_agent-0.2.1/viola/agent/runner.py +1210 -0
  19. viola_agent-0.2.1/viola/agent/skills.py +242 -0
  20. viola_agent-0.2.1/viola/agent/subagent.py +337 -0
  21. viola_agent-0.2.1/viola/agent/tools/__init__.py +31 -0
  22. viola_agent-0.2.1/viola/agent/tools/base.py +296 -0
  23. viola_agent-0.2.1/viola/agent/tools/context.py +33 -0
  24. viola_agent-0.2.1/viola/agent/tools/cron.py +337 -0
  25. viola_agent-0.2.1/viola/agent/tools/dream_workspace_tools.py +292 -0
  26. viola_agent-0.2.1/viola/agent/tools/exec_session.py +596 -0
  27. viola_agent-0.2.1/viola/agent/tools/file_state.py +205 -0
  28. viola_agent-0.2.1/viola/agent/tools/loader.py +117 -0
  29. viola_agent-0.2.1/viola/agent/tools/long_task.py +227 -0
  30. viola_agent-0.2.1/viola/agent/tools/mcp.py +725 -0
  31. viola_agent-0.2.1/viola/agent/tools/message.py +196 -0
  32. viola_agent-0.2.1/viola/agent/tools/notebook.py +169 -0
  33. viola_agent-0.2.1/viola/agent/tools/registry.py +157 -0
  34. viola_agent-0.2.1/viola/agent/tools/runtime_state.py +59 -0
  35. viola_agent-0.2.1/viola/agent/tools/sandbox.py +57 -0
  36. viola_agent-0.2.1/viola/agent/tools/schema.py +232 -0
  37. viola_agent-0.2.1/viola/agent/tools/search.py +557 -0
  38. viola_agent-0.2.1/viola/agent/tools/self.py +475 -0
  39. viola_agent-0.2.1/viola/agent/tools/shell.py +559 -0
  40. viola_agent-0.2.1/viola/agent/tools/spawn.py +78 -0
  41. viola_agent-0.2.1/viola/agent/tools/web.py +595 -0
  42. viola_agent-0.2.1/viola/agent/tools/workspace_paths.py +103 -0
  43. viola_agent-0.2.1/viola/api/__init__.py +1 -0
  44. viola_agent-0.2.1/viola/api/server.py +822 -0
  45. viola_agent-0.2.1/viola/api/twilio_media.py +257 -0
  46. viola_agent-0.2.1/viola/api/twilio_webhook.py +359 -0
  47. viola_agent-0.2.1/viola/api/whatsapp_response_template.py +509 -0
  48. viola_agent-0.2.1/viola/billing.py +242 -0
  49. viola_agent-0.2.1/viola/bus/__init__.py +6 -0
  50. viola_agent-0.2.1/viola/bus/events.py +38 -0
  51. viola_agent-0.2.1/viola/bus/queue.py +44 -0
  52. viola_agent-0.2.1/viola/channels/__init__.py +6 -0
  53. viola_agent-0.2.1/viola/channels/base.py +244 -0
  54. viola_agent-0.2.1/viola/channels/manager.py +421 -0
  55. viola_agent-0.2.1/viola/channels/registry.py +41 -0
  56. viola_agent-0.2.1/viola/cli/__init__.py +1 -0
  57. viola_agent-0.2.1/viola/cli/commands.py +2088 -0
  58. viola_agent-0.2.1/viola/cli/doctor.py +443 -0
  59. viola_agent-0.2.1/viola/cli/models.py +31 -0
  60. viola_agent-0.2.1/viola/cli/onboard.py +1169 -0
  61. viola_agent-0.2.1/viola/cli/stream.py +230 -0
  62. viola_agent-0.2.1/viola/command/__init__.py +6 -0
  63. viola_agent-0.2.1/viola/command/builtin.py +624 -0
  64. viola_agent-0.2.1/viola/command/router.py +98 -0
  65. viola_agent-0.2.1/viola/config/__init__.py +30 -0
  66. viola_agent-0.2.1/viola/config/loader.py +482 -0
  67. viola_agent-0.2.1/viola/config/paths.py +81 -0
  68. viola_agent-0.2.1/viola/config/schema.py +568 -0
  69. viola_agent-0.2.1/viola/cron/__init__.py +7 -0
  70. viola_agent-0.2.1/viola/cron/registry.py +202 -0
  71. viola_agent-0.2.1/viola/cron/service.py +686 -0
  72. viola_agent-0.2.1/viola/cron/types.py +83 -0
  73. viola_agent-0.2.1/viola/heartbeat/__init__.py +5 -0
  74. viola_agent-0.2.1/viola/heartbeat/service.py +243 -0
  75. viola_agent-0.2.1/viola/infra/__init__.py +1 -0
  76. viola_agent-0.2.1/viola/infra/redis/__init__.py +29 -0
  77. viola_agent-0.2.1/viola/infra/redis/client.py +21 -0
  78. viola_agent-0.2.1/viola/infra/redis/guards.py +259 -0
  79. viola_agent-0.2.1/viola/infra/redis/runtime/__init__.py +17 -0
  80. viola_agent-0.2.1/viola/infra/redis/runtime/cache.py +24 -0
  81. viola_agent-0.2.1/viola/infra/redis/runtime/client.py +63 -0
  82. viola_agent-0.2.1/viola/infra/redis/runtime/keys.py +8 -0
  83. viola_agent-0.2.1/viola/infra/redis/runtime/lock.py +41 -0
  84. viola_agent-0.2.1/viola/infra/redis/runtime/rate_limit.py +23 -0
  85. viola_agent-0.2.1/viola/infra/redis/runtime/session.py +80 -0
  86. viola_agent-0.2.1/viola/notify/__init__.py +36 -0
  87. viola_agent-0.2.1/viola/notify/catalog.py +138 -0
  88. viola_agent-0.2.1/viola/notify/service.py +281 -0
  89. viola_agent-0.2.1/viola/notify/store.py +144 -0
  90. viola_agent-0.2.1/viola/notify/templates.yaml +79 -0
  91. viola_agent-0.2.1/viola/notify/twilio_content.py +254 -0
  92. viola_agent-0.2.1/viola/notify/window.py +58 -0
  93. viola_agent-0.2.1/viola/pairing/__init__.py +33 -0
  94. viola_agent-0.2.1/viola/pairing/store.py +254 -0
  95. viola_agent-0.2.1/viola/providers/__init__.py +33 -0
  96. viola_agent-0.2.1/viola/providers/anthropic_provider.py +629 -0
  97. viola_agent-0.2.1/viola/providers/base.py +814 -0
  98. viola_agent-0.2.1/viola/providers/factory.py +214 -0
  99. viola_agent-0.2.1/viola/providers/fallback_provider.py +273 -0
  100. viola_agent-0.2.1/viola/providers/image_generation.py +395 -0
  101. viola_agent-0.2.1/viola/providers/openai_compat_provider.py +1079 -0
  102. viola_agent-0.2.1/viola/providers/openai_responses/__init__.py +29 -0
  103. viola_agent-0.2.1/viola/providers/openai_responses/converters.py +110 -0
  104. viola_agent-0.2.1/viola/providers/openai_responses/parsing.py +297 -0
  105. viola_agent-0.2.1/viola/providers/registry.py +542 -0
  106. viola_agent-0.2.1/viola/providers/transcription.py +881 -0
  107. viola_agent-0.2.1/viola/runtime/__init__.py +17 -0
  108. viola_agent-0.2.1/viola/runtime/background_tasks.py +274 -0
  109. viola_agent-0.2.1/viola/runtime/whatsapp_outbound.py +105 -0
  110. viola_agent-0.2.1/viola/security/__init__.py +1 -0
  111. viola_agent-0.2.1/viola/security/network.py +119 -0
  112. viola_agent-0.2.1/viola/session/__init__.py +5 -0
  113. viola_agent-0.2.1/viola/session/goal_state.py +117 -0
  114. viola_agent-0.2.1/viola/session/manager.py +660 -0
  115. viola_agent-0.2.1/viola/settings.py +243 -0
  116. viola_agent-0.2.1/viola/skills/README.md +30 -0
  117. viola_agent-0.2.1/viola/skills/cron/SKILL.md +57 -0
  118. viola_agent-0.2.1/viola/skills/github/SKILL.md +48 -0
  119. viola_agent-0.2.1/viola/skills/long-goal/SKILL.md +79 -0
  120. viola_agent-0.2.1/viola/skills/memory/SKILL.md +36 -0
  121. viola_agent-0.2.1/viola/skills/my/SKILL.md +72 -0
  122. viola_agent-0.2.1/viola/skills/my/references/examples.md +75 -0
  123. viola_agent-0.2.1/viola/skills/skill-creator/SKILL.md +374 -0
  124. viola_agent-0.2.1/viola/skills/skill-creator/scripts/init_skill.py +378 -0
  125. viola_agent-0.2.1/viola/skills/skill-creator/scripts/package_skill.py +152 -0
  126. viola_agent-0.2.1/viola/skills/skill-creator/scripts/quick_validate.py +213 -0
  127. viola_agent-0.2.1/viola/skills/summarize/SKILL.md +67 -0
  128. viola_agent-0.2.1/viola/skills/tmux/SKILL.md +121 -0
  129. viola_agent-0.2.1/viola/skills/tmux/scripts/find-sessions.sh +112 -0
  130. viola_agent-0.2.1/viola/skills/tmux/scripts/wait-for-text.sh +83 -0
  131. viola_agent-0.2.1/viola/skills/update-setup/SKILL.md +123 -0
  132. viola_agent-0.2.1/viola/skills/weather/SKILL.md +49 -0
  133. viola_agent-0.2.1/viola/templates/AGENTS.md +15 -0
  134. viola_agent-0.2.1/viola/templates/HEARTBEAT.md +16 -0
  135. viola_agent-0.2.1/viola/templates/SKILL.md +0 -0
  136. viola_agent-0.2.1/viola/templates/SOUL.md +23 -0
  137. viola_agent-0.2.1/viola/templates/TOOLS.md +36 -0
  138. viola_agent-0.2.1/viola/templates/USER.md +49 -0
  139. viola_agent-0.2.1/viola/templates/__init__.py +0 -0
  140. viola_agent-0.2.1/viola/templates/agent/_snippets/untrusted_content.md +2 -0
  141. viola_agent-0.2.1/viola/templates/agent/consolidator_archive.md +13 -0
  142. viola_agent-0.2.1/viola/templates/agent/dream_phase1.md +40 -0
  143. viola_agent-0.2.1/viola/templates/agent/dream_phase2.md +35 -0
  144. viola_agent-0.2.1/viola/templates/agent/evaluator.md +17 -0
  145. viola_agent-0.2.1/viola/templates/agent/identity.md +37 -0
  146. viola_agent-0.2.1/viola/templates/agent/max_iterations_message.md +1 -0
  147. viola_agent-0.2.1/viola/templates/agent/platform_policy.md +10 -0
  148. viola_agent-0.2.1/viola/templates/agent/skills_section.md +6 -0
  149. viola_agent-0.2.1/viola/templates/agent/subagent_announce.md +8 -0
  150. viola_agent-0.2.1/viola/templates/agent/subagent_system.md +19 -0
  151. viola_agent-0.2.1/viola/templates/agent/tool_contract.md +67 -0
  152. viola_agent-0.2.1/viola/templates/memory/MEMORY.md +27 -0
  153. viola_agent-0.2.1/viola/templates/memory/__init__.py +0 -0
  154. viola_agent-0.2.1/viola/utils/__init__.py +6 -0
  155. viola_agent-0.2.1/viola/utils/artifacts.py +323 -0
  156. viola_agent-0.2.1/viola/utils/document.py +374 -0
  157. viola_agent-0.2.1/viola/utils/evaluator.py +89 -0
  158. viola_agent-0.2.1/viola/utils/gitstore.py +390 -0
  159. viola_agent-0.2.1/viola/utils/helpers.py +654 -0
  160. viola_agent-0.2.1/viola/utils/llm_runtime.py +22 -0
  161. viola_agent-0.2.1/viola/utils/logging_bridge.py +47 -0
  162. viola_agent-0.2.1/viola/utils/media_decode.py +54 -0
  163. viola_agent-0.2.1/viola/utils/path.py +107 -0
  164. viola_agent-0.2.1/viola/utils/progress_events.py +84 -0
  165. viola_agent-0.2.1/viola/utils/prompt_templates.py +35 -0
  166. viola_agent-0.2.1/viola/utils/restart.py +84 -0
  167. viola_agent-0.2.1/viola/utils/runtime.py +170 -0
  168. viola_agent-0.2.1/viola/utils/searchusage.py +168 -0
  169. viola_agent-0.2.1/viola/utils/subagent_channel_display.py +59 -0
  170. viola_agent-0.2.1/viola/utils/tool_hints.py +142 -0
  171. viola_agent-0.2.1/viola/viola.py +100 -0
@@ -0,0 +1,101 @@
1
+ # Project-specific
2
+ .worktrees/
3
+ .worktree/
4
+ .assets
5
+ .docs
6
+ .env
7
+ .web
8
+ .orion
9
+ /data/*
10
+ !/data/.gitkeep
11
+
12
+ # Claude / AI assistant artifacts
13
+ docs/superpowers/
14
+ docs/plans/
15
+
16
+ # webui (monorepo frontend)
17
+ node_modules/
18
+ webui/dist/
19
+ webui/coverage/
20
+ webui/.vite/
21
+ *.tsbuildinfo
22
+
23
+ # Python bytecode & caches
24
+ *.pyc
25
+ *.pyo
26
+ *.pyd
27
+ *.pyw
28
+ *.pyz
29
+ __pycache__/
30
+ *.egg-info/
31
+ *.egg
32
+ .venv/
33
+ venv/
34
+ .pytest_cache/
35
+ .mypy_cache/
36
+ .ruff_cache/
37
+ .pytype/
38
+ .dmypy.json
39
+ dmypy.json
40
+ .tox/
41
+ .nox/
42
+ .hypothesis/
43
+
44
+ # Build & packaging
45
+ dist/
46
+ build/
47
+ *.manifest
48
+ *.spec
49
+ pip-wheel-metadata/
50
+ share/python-wheels/
51
+
52
+ # Test & coverage
53
+ .coverage
54
+ .coverage.*
55
+ htmlcov/
56
+ coverage.xml
57
+ *.cover
58
+
59
+ # Lock files (project policy)
60
+ poetry.lock
61
+ uv.lock
62
+
63
+ # Jupyter
64
+ .ipynb_checkpoints/
65
+
66
+ # macOS
67
+ .DS_Store
68
+ .AppleDouble
69
+ .LSOverride
70
+
71
+ # Windows
72
+ Thumbs.db
73
+ ehthumbs.db
74
+ Desktop.ini
75
+
76
+ # Linux
77
+ .directory
78
+
79
+ # Editors & IDEs (local workspace / user settings)
80
+ .vscode/
81
+ .cursor/
82
+ .idea/
83
+ .fleet/
84
+ *.code-workspace
85
+ *.sublime-project
86
+ *.sublime-workspace
87
+ *.swp
88
+ *.swo
89
+ *~
90
+ nano.*.save
91
+
92
+ # Environment & secrets (keep examples tracked if needed)
93
+ .env.*
94
+ !.env.example
95
+
96
+ # Logs & temp
97
+ *.log
98
+ logs/
99
+ tmp/
100
+ temp/
101
+ *.tmp
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Xubin Ren and the viola contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.5
2
+ Name: viola-agent
3
+ Version: 0.2.1
4
+ Summary: Self-hosted WhatsApp AI agent (Twilio) with an OpenAI-compatible API
5
+ Project-URL: Homepage, https://github.com/virpluzteam/viola-agent
6
+ Project-URL: Source, https://github.com/virpluzteam/viola-agent
7
+ Project-URL: Issues, https://github.com/virpluzteam/viola-agent/issues
8
+ Author: Xubin Ren, the viola contributors
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ License-File: THIRD_PARTY_NOTICES.md
12
+ Keywords: agent,ai,chatbot,llm,twilio,whatsapp
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Requires-Python: <3.14,>=3.11
20
+ Requires-Dist: aiohttp<4.0.0,>=3.9.0
21
+ Requires-Dist: anthropic<1.0.0,>=0.45.0
22
+ Requires-Dist: boto3>=1.43.0
23
+ Requires-Dist: chardet<6.0.0,>=3.0.2
24
+ Requires-Dist: croniter<7.0.0,>=6.0.0
25
+ Requires-Dist: ddgs<10.0.0,>=9.5.5
26
+ Requires-Dist: dingtalk-stream<1.0.0,>=0.24.0
27
+ Requires-Dist: dulwich<1.0.0,>=0.22.0
28
+ Requires-Dist: filelock>=3.25.2
29
+ Requires-Dist: httpx<1.0.0,>=0.28.0
30
+ Requires-Dist: jinja2<4.0.0,>=3.1.0
31
+ Requires-Dist: json-repair<1.0.0,>=0.57.0
32
+ Requires-Dist: lark-oapi<2.0.0,>=1.5.0
33
+ Requires-Dist: loguru<1.0.0,>=0.7.3
34
+ Requires-Dist: mcp<2.0.0,>=1.26.0
35
+ Requires-Dist: msgpack<2.0.0,>=1.1.0
36
+ Requires-Dist: oauth-cli-kit<1.0.0,>=0.1.3
37
+ Requires-Dist: openai>=2.8.0
38
+ Requires-Dist: openpyxl<4.0.0,>=3.1.0
39
+ Requires-Dist: prompt-toolkit<4.0.0,>=3.0.50
40
+ Requires-Dist: pydantic-settings<3.0.0,>=2.12.0
41
+ Requires-Dist: pydantic<3.0.0,>=2.12.0
42
+ Requires-Dist: pypdf<6.0.0,>=5.0.0
43
+ Requires-Dist: python-docx<2.0.0,>=1.1.0
44
+ Requires-Dist: python-dotenv<2.0.0,>=1.0.0
45
+ Requires-Dist: python-pptx<2.0.0,>=1.0.0
46
+ Requires-Dist: python-socketio<6.0.0,>=5.16.0
47
+ Requires-Dist: python-socks[asyncio]<3.0.0,>=2.8.0; sys_platform != 'win32'
48
+ Requires-Dist: python-telegram-bot[socks]<23.0,>=22.6
49
+ Requires-Dist: pyyaml<7.0.0,>=6.0
50
+ Requires-Dist: qq-botpy<2.0.0,>=1.2.0
51
+ Requires-Dist: questionary<3.0.0,>=2.0.0
52
+ Requires-Dist: readability-lxml<1.0.0,>=0.8.4
53
+ Requires-Dist: redis[hiredis]<6.0.0,>=5.0.0
54
+ Requires-Dist: rich<15.0.0,>=14.0.0
55
+ Requires-Dist: slack-sdk<4.0.0,>=3.39.0
56
+ Requires-Dist: slackify-markdown<1.0.0,>=0.2.0
57
+ Requires-Dist: socksio<2.0.0,>=1.0.0
58
+ Requires-Dist: tiktoken<1.0.0,>=0.12.0
59
+ Requires-Dist: typer<1.0.0,>=0.20.0
60
+ Requires-Dist: websocket-client<2.0.0,>=1.9.0
61
+ Requires-Dist: websockets<17.0,>=16.0
62
+ Provides-Extra: twilio
63
+ Requires-Dist: twilio<10.0.0,>=9.0.0; extra == 'twilio'
64
+ Description-Content-Type: text/markdown
65
+
66
+ # viola-agent
67
+
68
+ A self-hosted WhatsApp AI agent. A company deploys one copy, fills in its own Twilio,
69
+ LLM (OpenRouter or UniAPI) and optional billing credentials, and gets an assistant its
70
+ customers and staff can message on WhatsApp.
71
+
72
+ **→ Setup guide: [docs/getting-started.md](docs/getting-started.md)** covers what goes in
73
+ `.env`, starting it with Docker Compose, connecting Twilio, and customising the agent.
74
+
75
+ ```bash
76
+ cp .env.example .env # fill in Twilio + LLM (see the guide)
77
+ docker compose up -d # image: ghcr.io/virpluzteam/viola-agent
78
+ ```
79
+
80
+ Releases are published as a Docker image (`ghcr.io/virpluzteam/viola-agent`, amd64 and
81
+ arm64) and as a pip package (`pip install 'viola-agent[twilio]'`). Both are built from
82
+ the same wheel and read the same `.env`.
83
+
84
+ > **Status:** being generalised from an internal project. See [PLAN.md](PLAN.md) for the
85
+ > roadmap.
86
+
87
+ ## Layout
88
+
89
+ - `viola/` — agent package. `viola serve` runs everything on one port: the Twilio
90
+ WhatsApp webhook, an OpenAI-compatible API and `/health`
91
+ - `tests/` — pytest suite
92
+
93
+ ## Run locally
94
+
95
+ ```bash
96
+ python3.13 -m venv .venv && .venv/bin/pip install -e ".[twilio]" --group dev # pip >= 25.1; or: uv sync --all-extras
97
+ cp .env.example .env # fill in Twilio, LLM and (optionally) billing values,
98
+ # and set APP_ENV=development to run without Redis
99
+ .venv/bin/viola serve --port 8900
100
+ ```
101
+
102
+ `viola serve` reads `.env` from the current directory (or `$VIOLA_ENV_FILE`) and stores
103
+ its data — `config.json`, the workspace with chat history, media, the billing outbox,
104
+ `viola.db` (notification idempotency), `content_sid_map.json` — in
105
+ `$VIOLA_DATA_DIR` (default `~/.viola`). Without `REDIS_URL` it uses in-memory dedup and rate
106
+ limits, which is fine for one local process; `APP_ENV=production` requires Redis.
107
+
108
+ Twilio must reach the webhook over public HTTPS. For a server, see
109
+ [Expose it over HTTPS](docs/getting-started.md#expose-it-over-https) (bundled Caddy profile
110
+ or a Cloudflare Tunnel; both publish only `/twilio/*`). For development, run `ngrok http 8900`,
111
+ set `PUBLIC_BASE_URL=https://<ngrok-host>` in `.env`, and set Twilio's "A message comes in"
112
+ URL to `https://<ngrok-host>/twilio/webhook`. Requests whose `X-Twilio-Signature` does not
113
+ match `PUBLIC_BASE_URL` + path are rejected with `403`.
114
+
115
+ Routes:
116
+
117
+ - `POST /twilio/webhook` — Twilio inbound; verifies the signature, ignores repeated
118
+ `MessageSid`s, rate-limits per sender, replies `202` and answers in the background
119
+ - `GET /twilio/webhook` — plain-text probe
120
+ - `POST /twilio/status` — optional Twilio status callback (acknowledged)
121
+ - `POST /v1/chat/completions` — OpenAI-compatible API for the portal backend: needs the
122
+ server key and a `user` in the body; the session is `portal:<user>:<session_id>`
123
+ - `POST /v1/notify` — send a proactive WhatsApp message (see below)
124
+
125
+ Every `/v1/*` route needs `Authorization: Bearer $VIOLA_API_SERVER_KEY` (`401` otherwise) and
126
+ returns `404` when no server key is configured.
127
+
128
+ Tools are off by default. Each channel profile (`whatsapp`, `portal`) gets only the tools
129
+ listed for it in `config.json` → `profiles`; see [docs/phase5-channels.md](docs/phase5-channels.md).
130
+ - `GET /health` — JSON health
131
+
132
+ ## Proactive messages and templates
133
+
134
+ WhatsApp lets a business send free text only within **24 hours** of the customer's last
135
+ message; outside that window only Meta-approved templates may be sent. Every inbound
136
+ message opens the window (stored in Redis, or memory in development). `/v1/notify`, cron
137
+ reminders and heartbeat all go through `viola.notify.send`:
138
+
139
+ - window open and `fallback_text` given → the text is sent
140
+ - otherwise an approved `template_id` → the template is sent
141
+ - otherwise nothing is sent: `422 template_required` with the reason (a rule, not a failure)
142
+
143
+ ```bash
144
+ curl -X POST https://<host>/v1/notify \
145
+ -H "Authorization: Bearer $VIOLA_API_SERVER_KEY" -H "Content-Type: application/json" \
146
+ -d '{"to": "+85212345678", "template_id": "reminder",
147
+ "variables": {"reminder_text": "your appointment is tomorrow at 10:00"},
148
+ "fallback_text": "Hi! Your appointment is tomorrow at 10:00.",
149
+ "idempotency_key": "appt-123-reminder"}'
150
+ ```
151
+
152
+ Responses: `200` sent (`mode` is `text` or `template`), `422 template_required`,
153
+ `502 twilio_error`, `409` same `idempotency_key` with a different body (or still sending),
154
+ `400` bad request or missing `idempotency_key`, `401` bad server key. A repeated
155
+ `idempotency_key` never sends twice: it returns the first result (kept for 7 days in
156
+ `$VIOLA_DATA_DIR/viola.db`). A key whose send failed may be retried.
157
+
158
+ Templates live in `viola/notify/templates.yaml` (welcome, reminder, follow-up, generic
159
+ notification; `en` and `zh_HK`). To use your own, copy it to
160
+ `$VIOLA_DATA_DIR/templates.yaml` and edit it. Then create them in your Twilio account:
161
+
162
+ ```bash
163
+ viola templates sync # create in Twilio + submit to Meta (--dry-run, --no-submit, --only)
164
+ viola templates status # refresh approval status (approved / pending / rejected)
165
+ ```
166
+
167
+ ContentSids and approval statuses are kept in `$VIOLA_DATA_DIR/content_sid_map.json`;
168
+ only `approved` templates are used. Cron reminders outside the window use the `reminder`
169
+ template.
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ .venv/bin/ruff check viola/
175
+ .venv/bin/pytest
176
+ ```
177
+
178
+ CI (`.github/workflows/ci.yml`) runs ruff, pytest (Python 3.11–3.13, Linux and Windows),
179
+ a gitleaks scan of the full history (false positives go in `.gitleaksignore`), a wheel
180
+ build and an image build with a smoke test (`.github/scripts/smoke-image.sh`).
181
+
182
+ ### Releasing
183
+
184
+ 1. Set `version` in `pyproject.toml` (e.g. `0.2.1`) and merge to `main`.
185
+ 2. Tag that commit and push the tag:
186
+
187
+ ```bash
188
+ git tag v0.2.1 && git push origin v0.2.1
189
+ ```
190
+
191
+ `.github/workflows/release.yml` checks the tag matches the version, runs CI, then
192
+ publishes the wheel and sdist to PyPI, pushes the image to GHCR as `0.2.1`, `0.2` and
193
+ `latest`, and creates a GitHub release. One-time setup is described at the top of that
194
+ file (PyPI trusted publisher, the `pypi` environment, making the GHCR package public).
195
+
196
+ ## License
197
+
198
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,133 @@
1
+ # viola-agent
2
+
3
+ A self-hosted WhatsApp AI agent. A company deploys one copy, fills in its own Twilio,
4
+ LLM (OpenRouter or UniAPI) and optional billing credentials, and gets an assistant its
5
+ customers and staff can message on WhatsApp.
6
+
7
+ **→ Setup guide: [docs/getting-started.md](docs/getting-started.md)** covers what goes in
8
+ `.env`, starting it with Docker Compose, connecting Twilio, and customising the agent.
9
+
10
+ ```bash
11
+ cp .env.example .env # fill in Twilio + LLM (see the guide)
12
+ docker compose up -d # image: ghcr.io/virpluzteam/viola-agent
13
+ ```
14
+
15
+ Releases are published as a Docker image (`ghcr.io/virpluzteam/viola-agent`, amd64 and
16
+ arm64) and as a pip package (`pip install 'viola-agent[twilio]'`). Both are built from
17
+ the same wheel and read the same `.env`.
18
+
19
+ > **Status:** being generalised from an internal project. See [PLAN.md](PLAN.md) for the
20
+ > roadmap.
21
+
22
+ ## Layout
23
+
24
+ - `viola/` — agent package. `viola serve` runs everything on one port: the Twilio
25
+ WhatsApp webhook, an OpenAI-compatible API and `/health`
26
+ - `tests/` — pytest suite
27
+
28
+ ## Run locally
29
+
30
+ ```bash
31
+ python3.13 -m venv .venv && .venv/bin/pip install -e ".[twilio]" --group dev # pip >= 25.1; or: uv sync --all-extras
32
+ cp .env.example .env # fill in Twilio, LLM and (optionally) billing values,
33
+ # and set APP_ENV=development to run without Redis
34
+ .venv/bin/viola serve --port 8900
35
+ ```
36
+
37
+ `viola serve` reads `.env` from the current directory (or `$VIOLA_ENV_FILE`) and stores
38
+ its data — `config.json`, the workspace with chat history, media, the billing outbox,
39
+ `viola.db` (notification idempotency), `content_sid_map.json` — in
40
+ `$VIOLA_DATA_DIR` (default `~/.viola`). Without `REDIS_URL` it uses in-memory dedup and rate
41
+ limits, which is fine for one local process; `APP_ENV=production` requires Redis.
42
+
43
+ Twilio must reach the webhook over public HTTPS. For a server, see
44
+ [Expose it over HTTPS](docs/getting-started.md#expose-it-over-https) (bundled Caddy profile
45
+ or a Cloudflare Tunnel; both publish only `/twilio/*`). For development, run `ngrok http 8900`,
46
+ set `PUBLIC_BASE_URL=https://<ngrok-host>` in `.env`, and set Twilio's "A message comes in"
47
+ URL to `https://<ngrok-host>/twilio/webhook`. Requests whose `X-Twilio-Signature` does not
48
+ match `PUBLIC_BASE_URL` + path are rejected with `403`.
49
+
50
+ Routes:
51
+
52
+ - `POST /twilio/webhook` — Twilio inbound; verifies the signature, ignores repeated
53
+ `MessageSid`s, rate-limits per sender, replies `202` and answers in the background
54
+ - `GET /twilio/webhook` — plain-text probe
55
+ - `POST /twilio/status` — optional Twilio status callback (acknowledged)
56
+ - `POST /v1/chat/completions` — OpenAI-compatible API for the portal backend: needs the
57
+ server key and a `user` in the body; the session is `portal:<user>:<session_id>`
58
+ - `POST /v1/notify` — send a proactive WhatsApp message (see below)
59
+
60
+ Every `/v1/*` route needs `Authorization: Bearer $VIOLA_API_SERVER_KEY` (`401` otherwise) and
61
+ returns `404` when no server key is configured.
62
+
63
+ Tools are off by default. Each channel profile (`whatsapp`, `portal`) gets only the tools
64
+ listed for it in `config.json` → `profiles`; see [docs/phase5-channels.md](docs/phase5-channels.md).
65
+ - `GET /health` — JSON health
66
+
67
+ ## Proactive messages and templates
68
+
69
+ WhatsApp lets a business send free text only within **24 hours** of the customer's last
70
+ message; outside that window only Meta-approved templates may be sent. Every inbound
71
+ message opens the window (stored in Redis, or memory in development). `/v1/notify`, cron
72
+ reminders and heartbeat all go through `viola.notify.send`:
73
+
74
+ - window open and `fallback_text` given → the text is sent
75
+ - otherwise an approved `template_id` → the template is sent
76
+ - otherwise nothing is sent: `422 template_required` with the reason (a rule, not a failure)
77
+
78
+ ```bash
79
+ curl -X POST https://<host>/v1/notify \
80
+ -H "Authorization: Bearer $VIOLA_API_SERVER_KEY" -H "Content-Type: application/json" \
81
+ -d '{"to": "+85212345678", "template_id": "reminder",
82
+ "variables": {"reminder_text": "your appointment is tomorrow at 10:00"},
83
+ "fallback_text": "Hi! Your appointment is tomorrow at 10:00.",
84
+ "idempotency_key": "appt-123-reminder"}'
85
+ ```
86
+
87
+ Responses: `200` sent (`mode` is `text` or `template`), `422 template_required`,
88
+ `502 twilio_error`, `409` same `idempotency_key` with a different body (or still sending),
89
+ `400` bad request or missing `idempotency_key`, `401` bad server key. A repeated
90
+ `idempotency_key` never sends twice: it returns the first result (kept for 7 days in
91
+ `$VIOLA_DATA_DIR/viola.db`). A key whose send failed may be retried.
92
+
93
+ Templates live in `viola/notify/templates.yaml` (welcome, reminder, follow-up, generic
94
+ notification; `en` and `zh_HK`). To use your own, copy it to
95
+ `$VIOLA_DATA_DIR/templates.yaml` and edit it. Then create them in your Twilio account:
96
+
97
+ ```bash
98
+ viola templates sync # create in Twilio + submit to Meta (--dry-run, --no-submit, --only)
99
+ viola templates status # refresh approval status (approved / pending / rejected)
100
+ ```
101
+
102
+ ContentSids and approval statuses are kept in `$VIOLA_DATA_DIR/content_sid_map.json`;
103
+ only `approved` templates are used. Cron reminders outside the window use the `reminder`
104
+ template.
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ .venv/bin/ruff check viola/
110
+ .venv/bin/pytest
111
+ ```
112
+
113
+ CI (`.github/workflows/ci.yml`) runs ruff, pytest (Python 3.11–3.13, Linux and Windows),
114
+ a gitleaks scan of the full history (false positives go in `.gitleaksignore`), a wheel
115
+ build and an image build with a smoke test (`.github/scripts/smoke-image.sh`).
116
+
117
+ ### Releasing
118
+
119
+ 1. Set `version` in `pyproject.toml` (e.g. `0.2.1`) and merge to `main`.
120
+ 2. Tag that commit and push the tag:
121
+
122
+ ```bash
123
+ git tag v0.2.1 && git push origin v0.2.1
124
+ ```
125
+
126
+ `.github/workflows/release.yml` checks the tag matches the version, runs CI, then
127
+ publishes the wheel and sdist to PyPI, pushes the image to GHCR as `0.2.1`, `0.2` and
128
+ `latest`, and creates a GitHub release. One-time setup is described at the top of that
129
+ file (PyPI trusted publisher, the `pypi` environment, making the GHCR package public).
130
+
131
+ ## License
132
+
133
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,5 @@
1
+ # Third-Party Notices
2
+
3
+ This project includes third-party software components that are subject to their own licenses.
4
+
5
+ For dependency license details, refer to the dependency metadata resolved by Poetry in `poetry.lock`.
@@ -0,0 +1,163 @@
1
+ [project]
2
+ name = "viola-agent"
3
+ version = "0.2.1"
4
+ description = "Self-hosted WhatsApp AI agent (Twilio) with an OpenAI-compatible API"
5
+ readme = { file = "README.md", content-type = "text/markdown" }
6
+ requires-python = ">=3.11,<3.14"
7
+ #license = {text = "MIT"}
8
+ license = "MIT"
9
+ authors = [
10
+ {name = "Xubin Ren"},
11
+ {name = "the viola contributors"}
12
+ ]
13
+ keywords = ["ai", "agent", "chatbot", "whatsapp", "twilio", "llm"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ ]
22
+ license-files = [
23
+ "LICENSE",
24
+ "THIRD_PARTY_NOTICES.md",
25
+ ]
26
+
27
+ dependencies = [
28
+ "typer>=0.20.0,<1.0.0",
29
+ "anthropic>=0.45.0,<1.0.0",
30
+ "pydantic>=2.12.0,<3.0.0",
31
+ "pydantic-settings>=2.12.0,<3.0.0",
32
+ "websockets>=16.0,<17.0",
33
+ "websocket-client>=1.9.0,<2.0.0",
34
+ "httpx>=0.28.0,<1.0.0",
35
+ "ddgs>=9.5.5,<10.0.0",
36
+ "oauth-cli-kit>=0.1.3,<1.0.0",
37
+ "loguru>=0.7.3,<1.0.0",
38
+ "readability-lxml>=0.8.4,<1.0.0",
39
+ "rich>=14.0.0,<15.0.0",
40
+ "croniter>=6.0.0,<7.0.0",
41
+ "dingtalk-stream>=0.24.0,<1.0.0",
42
+ "python-telegram-bot[socks]>=22.6,<23.0",
43
+ "lark-oapi>=1.5.0,<2.0.0",
44
+ "socksio>=1.0.0,<2.0.0",
45
+ "python-socketio>=5.16.0,<6.0.0",
46
+ "msgpack>=1.1.0,<2.0.0",
47
+ "slack-sdk>=3.39.0,<4.0.0",
48
+ "slackify-markdown>=0.2.0,<1.0.0",
49
+ "qq-botpy>=1.2.0,<2.0.0",
50
+ "python-socks[asyncio]>=2.8.0,<3.0.0; sys_platform != 'win32'",
51
+ "prompt-toolkit>=3.0.50,<4.0.0",
52
+ "questionary>=2.0.0,<3.0.0",
53
+ "mcp>=1.26.0,<2.0.0",
54
+ "json-repair>=0.57.0,<1.0.0",
55
+ "chardet>=3.0.2,<6.0.0",
56
+ "openai>=2.8.0",
57
+ "tiktoken>=0.12.0,<1.0.0",
58
+ "jinja2>=3.1.0,<4.0.0",
59
+ "dulwich>=0.22.0,<1.0.0",
60
+ "pyyaml>=6.0,<7.0.0",
61
+ "pypdf>=5.0.0,<6.0.0",
62
+ "python-docx>=1.1.0,<2.0.0",
63
+ "openpyxl>=3.1.0,<4.0.0",
64
+ "python-pptx>=1.0.0,<2.0.0",
65
+ "filelock>=3.25.2",
66
+ "boto3>=1.43.0",
67
+ "redis[hiredis]>=5.0.0,<6.0.0",
68
+ "aiohttp>=3.9.0,<4.0.0",
69
+ "python-dotenv>=1.0.0,<2.0.0",
70
+ ]
71
+
72
+ [project.optional-dependencies]
73
+ twilio = [
74
+ "twilio>=9.0.0,<10.0.0",
75
+ ]
76
+
77
+ [dependency-groups]
78
+ dev = [
79
+ "pytest>=9.0.0,<10.0.0",
80
+ "pytest-asyncio>=1.3.0,<2.0.0",
81
+ "pytest-cov>=6.0.0,<7.0.0",
82
+ "ruff>=0.1.0",
83
+ "pymupdf>=1.25.0",
84
+ "fakeredis>=2.26.0",
85
+ ]
86
+
87
+ [project.urls]
88
+ Homepage = "https://github.com/virpluzteam/viola-agent"
89
+ Source = "https://github.com/virpluzteam/viola-agent"
90
+ Issues = "https://github.com/virpluzteam/viola-agent/issues"
91
+
92
+ [project.scripts]
93
+ viola = "viola.cli.commands:app"
94
+
95
+ # Third-party tool plugins register here. Built-in tools are discovered
96
+ # automatically via pkgutil scanning in ToolLoader.discover().
97
+ # [project.entry-points."viola.tools"]
98
+ # my_plugin = "my_package.plugins:MyTool"
99
+
100
+ [build-system]
101
+ requires = ["hatchling"]
102
+ build-backend = "hatchling.build"
103
+
104
+ [tool.hatch.metadata]
105
+ allow-direct-references = true
106
+
107
+ [tool.poetry]
108
+ packages = [{ include = "viola" }]
109
+
110
+ [tool.hatch.build]
111
+ include = [
112
+ "viola/**/*.py",
113
+ "viola/templates/**/*.md",
114
+ "viola/notify/*.yaml",
115
+ "viola/skills/**/*.md",
116
+ "viola/skills/**/*.sh",
117
+ ]
118
+
119
+ [tool.hatch.build.targets.wheel]
120
+ packages = ["viola"]
121
+
122
+ [tool.hatch.build.targets.wheel.sources]
123
+ "viola" = "viola"
124
+
125
+ [tool.hatch.build.targets.sdist]
126
+ include = [
127
+ "viola/",
128
+ "README.md",
129
+ "LICENSE",
130
+ "THIRD_PARTY_NOTICES.md",
131
+ "pyproject.toml",
132
+ ]
133
+
134
+ [tool.ruff]
135
+ line-length = 100
136
+ target-version = "py311"
137
+
138
+ [tool.ruff.lint]
139
+ select = ["E", "F", "I", "N", "W"]
140
+ ignore = ["E501"]
141
+
142
+ [tool.ruff.lint.per-file-ignores]
143
+ # The CLI fixes Windows stdio and configures loguru before importing viola modules
144
+ # that log at import time, so its imports cannot all sit at the top.
145
+ "viola/cli/commands.py" = ["E402"]
146
+
147
+ [tool.pytest.ini_options]
148
+ asyncio_mode = "auto"
149
+ asyncio_default_fixture_loop_scope = "function"
150
+ testpaths = ["tests"]
151
+
152
+ [tool.coverage.run]
153
+ source = ["viola"]
154
+ omit = ["tests/*", "**/tests/*"]
155
+
156
+ [tool.coverage.report]
157
+ exclude_lines = [
158
+ "pragma: no cover",
159
+ "def __repr__",
160
+ "raise NotImplementedError",
161
+ "if __name__ == .__main__.:",
162
+ "if TYPE_CHECKING:",
163
+ ]
@@ -0,0 +1,33 @@
1
+ """
2
+ viola - A lightweight AI agent framework
3
+ """
4
+
5
+ import tomllib
6
+ from importlib.metadata import PackageNotFoundError
7
+ from importlib.metadata import version as _pkg_version
8
+ from pathlib import Path
9
+
10
+
11
+ def _read_pyproject_version() -> str | None:
12
+ """Read the source-tree version when package metadata is unavailable."""
13
+ pyproject = Path(__file__).resolve().parent.parent / "pyproject.toml"
14
+ if not pyproject.exists():
15
+ return None
16
+ data = tomllib.loads(pyproject.read_text(encoding="utf-8"))
17
+ return data.get("project", {}).get("version")
18
+
19
+
20
+ def _resolve_version() -> str:
21
+ try:
22
+ return _pkg_version("viola-agent")
23
+ except PackageNotFoundError:
24
+ # Source checkouts often import viola without installed dist-info.
25
+ return _read_pyproject_version() or "0.0.0"
26
+
27
+
28
+ __version__ = _resolve_version()
29
+ __logo__ = "🐈"
30
+
31
+ from viola.viola import RunResult, Viola # noqa: E402 (submodules import __version__ during this import)
32
+
33
+ __all__ = ["Viola", "RunResult"]
@@ -0,0 +1,8 @@
1
+ """
2
+ Entry point for running viola as a module: python -m viola
3
+ """
4
+
5
+ from viola.cli.commands import app
6
+
7
+ if __name__ == "__main__":
8
+ app()
@@ -0,0 +1,20 @@
1
+ """Agent core module."""
2
+
3
+ from viola.agent.context import ContextBuilder
4
+ from viola.agent.hook import AgentHook, AgentHookContext, CompositeHook
5
+ from viola.agent.loop import AgentLoop
6
+ from viola.agent.memory import Dream, MemoryStore
7
+ from viola.agent.skills import SkillsLoader
8
+ from viola.agent.subagent import SubagentManager
9
+
10
+ __all__ = [
11
+ "AgentHook",
12
+ "AgentHookContext",
13
+ "AgentLoop",
14
+ "CompositeHook",
15
+ "ContextBuilder",
16
+ "Dream",
17
+ "MemoryStore",
18
+ "SkillsLoader",
19
+ "SubagentManager",
20
+ ]