agent-supra 1.0.0__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.
- agent_supra-1.0.0/.env.example +33 -0
- agent_supra-1.0.0/Dockerfile +19 -0
- agent_supra-1.0.0/LICENSE +21 -0
- agent_supra-1.0.0/MANIFEST.in +4 -0
- agent_supra-1.0.0/PKG-INFO +171 -0
- agent_supra-1.0.0/README.md +138 -0
- agent_supra-1.0.0/agent_supra/__init__.py +27 -0
- agent_supra-1.0.0/agent_supra/cli.py +88 -0
- agent_supra-1.0.0/agent_supra/client.py +240 -0
- agent_supra-1.0.0/agent_supra/demo.py +202 -0
- agent_supra-1.0.0/agent_supra/detector.py +246 -0
- agent_supra-1.0.0/agent_supra/integrations.py +292 -0
- agent_supra-1.0.0/agent_supra/present.py +65 -0
- agent_supra-1.0.0/agent_supra/pricing.py +121 -0
- agent_supra-1.0.0/agent_supra/report.py +97 -0
- agent_supra-1.0.0/agent_supra/sdk.py +189 -0
- agent_supra-1.0.0/agent_supra/server/__init__.py +10 -0
- agent_supra-1.0.0/agent_supra/server/accounts.py +268 -0
- agent_supra-1.0.0/agent_supra/server/alerts.py +127 -0
- agent_supra-1.0.0/agent_supra/server/api.py +122 -0
- agent_supra-1.0.0/agent_supra/server/app.py +154 -0
- agent_supra-1.0.0/agent_supra/server/core.py +467 -0
- agent_supra-1.0.0/agent_supra/server/db.py +212 -0
- agent_supra-1.0.0/agent_supra/server/errors.py +112 -0
- agent_supra-1.0.0/agent_supra/server/ratelimit.py +33 -0
- agent_supra-1.0.0/agent_supra/server/settings.py +64 -0
- agent_supra-1.0.0/agent_supra/server/static/app.css +413 -0
- agent_supra-1.0.0/agent_supra/server/static/refresh.js +6 -0
- agent_supra-1.0.0/agent_supra/server/templates/auth.html +25 -0
- agent_supra-1.0.0/agent_supra/server/templates/base.html +57 -0
- agent_supra-1.0.0/agent_supra/server/templates/error.html +9 -0
- agent_supra-1.0.0/agent_supra/server/templates/errors.html +26 -0
- agent_supra-1.0.0/agent_supra/server/templates/keys.html +53 -0
- agent_supra-1.0.0/agent_supra/server/templates/landing.html +105 -0
- agent_supra-1.0.0/agent_supra/server/templates/password_reset.html +36 -0
- agent_supra-1.0.0/agent_supra/server/templates/privacy.html +36 -0
- agent_supra-1.0.0/agent_supra/server/templates/quickstart.html +69 -0
- agent_supra-1.0.0/agent_supra/server/templates/run.html +111 -0
- agent_supra-1.0.0/agent_supra/server/templates/runs.html +62 -0
- agent_supra-1.0.0/agent_supra/server/templates/settings.html +94 -0
- agent_supra-1.0.0/agent_supra/server/templates/terms.html +30 -0
- agent_supra-1.0.0/agent_supra/server/web.py +504 -0
- agent_supra-1.0.0/agent_supra.egg-info/PKG-INFO +171 -0
- agent_supra-1.0.0/agent_supra.egg-info/SOURCES.txt +74 -0
- agent_supra-1.0.0/agent_supra.egg-info/dependency_links.txt +1 -0
- agent_supra-1.0.0/agent_supra.egg-info/entry_points.txt +2 -0
- agent_supra-1.0.0/agent_supra.egg-info/requires.txt +16 -0
- agent_supra-1.0.0/agent_supra.egg-info/top_level.txt +1 -0
- agent_supra-1.0.0/docker-compose.yml +32 -0
- agent_supra-1.0.0/docs/beta-plan.md +53 -0
- agent_supra-1.0.0/docs/database-backups.md +57 -0
- agent_supra-1.0.0/docs/deploying.md +147 -0
- agent_supra-1.0.0/docs/launch-checklist.md +58 -0
- agent_supra-1.0.0/docs/launch-test-report.md +115 -0
- agent_supra-1.0.0/docs/pypi-release.md +44 -0
- agent_supra-1.0.0/docs/setup-status.md +33 -0
- agent_supra-1.0.0/docs/testing-with-gemini.md +111 -0
- agent_supra-1.0.0/docs/windows-local.md +69 -0
- agent_supra-1.0.0/examples/gemini_agent.py +110 -0
- agent_supra-1.0.0/pyproject.toml +58 -0
- agent_supra-1.0.0/render.yaml +40 -0
- agent_supra-1.0.0/scripts/backup_archive.py +100 -0
- agent_supra-1.0.0/scripts/live_gemini_wrappers.py +97 -0
- agent_supra-1.0.0/scripts/local.py +44 -0
- agent_supra-1.0.0/setup.cfg +4 -0
- agent_supra-1.0.0/tests/test_app.py +359 -0
- agent_supra-1.0.0/tests/test_backup_archive.py +41 -0
- agent_supra-1.0.0/tests/test_client.py +106 -0
- agent_supra-1.0.0/tests/test_concurrency.py +42 -0
- agent_supra-1.0.0/tests/test_detector.py +215 -0
- agent_supra-1.0.0/tests/test_error_monitor.py +131 -0
- agent_supra-1.0.0/tests/test_integrations.py +160 -0
- agent_supra-1.0.0/tests/test_password_reset.py +71 -0
- agent_supra-1.0.0/tests/test_pricing_and_demo.py +54 -0
- agent_supra-1.0.0/tests/test_serverless.py +114 -0
- agent_supra-1.0.0/tests/test_supervisor.py +191 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copy to .env and fill in. Everything except DATABASE_URL and BASE_URL is optional.
|
|
2
|
+
|
|
3
|
+
# Postgres in production. Hosting providers' postgres:// URLs work as-is.
|
|
4
|
+
DATABASE_URL=sqlite:///supervisor.db
|
|
5
|
+
# The public URL people and agents use. https:// turns on secure cookies and HSTS.
|
|
6
|
+
BASE_URL=http://localhost:8000
|
|
7
|
+
APP_NAME=Agent Supra
|
|
8
|
+
CONTACT_EMAIL=sanchitp498@gmail.com
|
|
9
|
+
|
|
10
|
+
# Set to false after launch if you want invite-only (create users with `agent-supra create-user`).
|
|
11
|
+
ALLOW_SIGNUP=true
|
|
12
|
+
# Delete runs older than this many days (0 = keep forever).
|
|
13
|
+
RETENTION_DAYS=30
|
|
14
|
+
|
|
15
|
+
# Required for the Vercel retention cron. Use a random value of at least 16 characters.
|
|
16
|
+
CRON_SECRET=
|
|
17
|
+
|
|
18
|
+
# Rate limits (per server process).
|
|
19
|
+
RATE_LIMIT_EVENTS_PER_MIN=1200
|
|
20
|
+
RATE_LIMIT_AUTH_PER_MIN=10
|
|
21
|
+
|
|
22
|
+
# Server processes. 2 is fine for a small launch.
|
|
23
|
+
WEB_CONCURRENCY=2
|
|
24
|
+
|
|
25
|
+
# Email alerts (any SMTP provider: Resend, Postmark, SES, Gmail app password...).
|
|
26
|
+
SMTP_HOST=
|
|
27
|
+
SMTP_PORT=587
|
|
28
|
+
SMTP_USER=
|
|
29
|
+
SMTP_PASSWORD=
|
|
30
|
+
SMTP_FROM=
|
|
31
|
+
|
|
32
|
+
# Extra model prices, USD per million tokens: {"model-name": [input, output]}
|
|
33
|
+
AGENT_SUPRA_PRICES=
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
FROM python:3.12-slim
|
|
2
|
+
|
|
3
|
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
4
|
+
PYTHONUNBUFFERED=1 \
|
|
5
|
+
PIP_NO_CACHE_DIR=1 \
|
|
6
|
+
PORT=8000
|
|
7
|
+
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
10
|
+
COPY agent_supra ./agent_supra
|
|
11
|
+
RUN pip install ".[server]" && useradd --create-home --uid 10001 app
|
|
12
|
+
USER app
|
|
13
|
+
|
|
14
|
+
EXPOSE 8000
|
|
15
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
|
16
|
+
CMD python -c "import urllib.request,os; urllib.request.urlopen(f'http://127.0.0.1:{os.environ.get(\"PORT\",\"8000\")}/healthz', timeout=4)"
|
|
17
|
+
|
|
18
|
+
# Runs migrations, then the server. Configure with environment variables (see .env.example).
|
|
19
|
+
CMD ["agent-supra", "serve"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sanchit
|
|
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,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-supra
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Notice when an unattended AI agent is stuck, pause it, and show why.
|
|
5
|
+
Author: Sanchit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://agentsupra.in
|
|
8
|
+
Project-URL: Documentation, https://agentsupra.in/docs/quickstart
|
|
9
|
+
Project-URL: Repository, https://github.com/voidpusher/agent-supra
|
|
10
|
+
Project-URL: Issues, https://github.com/voidpusher/agent-supra/issues
|
|
11
|
+
Keywords: ai agents,llm,gemini,monitoring,cost control,observability
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: server
|
|
19
|
+
Requires-Dist: fastapi>=0.110; extra == "server"
|
|
20
|
+
Requires-Dist: uvicorn[standard]>=0.29; extra == "server"
|
|
21
|
+
Requires-Dist: sqlalchemy>=2.0; extra == "server"
|
|
22
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == "server"
|
|
23
|
+
Requires-Dist: jinja2>=3.1; extra == "server"
|
|
24
|
+
Requires-Dist: python-multipart>=0.0.9; extra == "server"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: agent-supra[server]; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
28
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
29
|
+
Requires-Dist: google-genai>=1.0; extra == "dev"
|
|
30
|
+
Requires-Dist: python-dotenv>=1.0; extra == "dev"
|
|
31
|
+
Requires-Dist: cryptography>=42; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Agent Supra
|
|
35
|
+
|
|
36
|
+
Notice when an unattended AI agent is stuck, pause it before more money goes into a loop, and show exactly why.
|
|
37
|
+
|
|
38
|
+
A spend cap can't tell a stuck agent from one working hard on a tough bug. Agent Supra watches **progress**: if an agent keeps changing code while its failing tests don't get any fewer, the run is flagged (or paused, once you opt in) with the evidence.
|
|
39
|
+
|
|
40
|
+
- **SDK** (`pip install agent-supra`): no dependencies. Wraps Gemini, OpenAI and Anthropic clients.
|
|
41
|
+
- **Hosted service**: dashboard, API keys, alerts to Slack and email, Postgres-backed. One Docker image.
|
|
42
|
+
|
|
43
|
+
## Try it in two minutes (no accounts, no API keys)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install -e ".[dev]"
|
|
47
|
+
agent-supra demo # or: python -m agent_supra.demo
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Two scripted agents fix a real bug in a tiny repo, running real pytest. One edits the code four times while the same tests fail and gets **paused**. The other fails twice, changes approach, passes, and is **left alone**. A timeline report is written to `supervisor_report.html`.
|
|
51
|
+
|
|
52
|
+
## Run the service locally
|
|
53
|
+
|
|
54
|
+
On Windows, see [the local PowerShell guide](docs/windows-local.md). The helper
|
|
55
|
+
`python scripts/local.py serve` loads the repository's `.env` file; the bare
|
|
56
|
+
`agent-supra serve` command reads exported environment variables.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cp .env.example .env
|
|
60
|
+
agent-supra serve # SQLite by default; http://localhost:8000
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or with Postgres, the way production runs:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
docker compose up --build
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Sign up, create an API key, then follow the quickstart at `/docs/quickstart`.
|
|
70
|
+
|
|
71
|
+
## Connect an agent
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from google import genai
|
|
75
|
+
from agent_supra import Client, SupervisedRun, SupervisorPaused
|
|
76
|
+
|
|
77
|
+
sup = Client() # AGENT_SUPRA_API_KEY and AGENT_SUPRA_URL from the environment
|
|
78
|
+
task = sup.create_task("Fix failing checkout tests", budget_usd=3)
|
|
79
|
+
|
|
80
|
+
with SupervisedRun(sup, task) as run:
|
|
81
|
+
gemini = run.wrap_gemini(genai.Client())
|
|
82
|
+
try:
|
|
83
|
+
while True:
|
|
84
|
+
run.check() # raises SupervisorPaused when paused
|
|
85
|
+
reply = gemini.models.generate_content(model="gemini-3.5-flash-lite", contents=prompt)
|
|
86
|
+
run.tool("edit_file", apply_fix, reply.text, rev=git_rev())
|
|
87
|
+
result = run.tool("run_tests", run_tests, rev=git_rev())
|
|
88
|
+
run.report_tests(result.all_ids, result.failing_ids, rev=git_rev())
|
|
89
|
+
if not result.failing_ids:
|
|
90
|
+
run.finish("success")
|
|
91
|
+
break
|
|
92
|
+
except SupervisorPaused as paused:
|
|
93
|
+
print("Paused:", paused.reason) # don't retry; review it in the dashboard
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| Call | What it does |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `Client(fail_mode="open")` | Hosted backend. If the service is down, `"open"` keeps the agent running and buffers events; `"closed"` treats it as paused |
|
|
99
|
+
| `run.wrap_gemini(client)` | `google.genai.Client()`: `models.generate_content`, `generate_content_stream`, `chats`, `aio`. Also the older `GenerativeModel` |
|
|
100
|
+
| `run.wrap_openai(client)` | `chat.completions.create` and `responses.create`. Streaming needs `stream_options={"include_usage": True}` |
|
|
101
|
+
| `run.wrap_anthropic(client)` | `messages.create`, including streams |
|
|
102
|
+
| `run.record_model_call(model, in, out)` | Any other model |
|
|
103
|
+
| `run.check()` | Refuses the next step if the run is paused or stopped |
|
|
104
|
+
| `run.tool(name, fn, ..., rev=)` | Runs a tool and records success or failure (fingerprints only, not the raw arguments or errors) |
|
|
105
|
+
| `run.report_tests(suite, failing, rev=)` | The main progress signal |
|
|
106
|
+
| `run.child()` | A sub-agent run sharing the task's budget |
|
|
107
|
+
| `run.finish("success" / "failed" / "unknown")` | Final outcome |
|
|
108
|
+
|
|
109
|
+
Wrapped clients check with the supervisor **before** each model call, so a paused run never reaches the provider.
|
|
110
|
+
|
|
111
|
+
A complete, runnable Gemini agent is in [`examples/gemini_agent.py`](examples/gemini_agent.py). See [docs/testing-with-gemini.md](docs/testing-with-gemini.md).
|
|
112
|
+
|
|
113
|
+
## Detection rules
|
|
114
|
+
|
|
115
|
+
| Rule | Fires when | Default |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| No progress | 4 attempts in a row without the number of failing tests reaching a new low, while the code changes. Swapping one failure for another doesn't count as progress | Pause, once observation mode is off |
|
|
118
|
+
| Exact repeat | The same failure with no code change, or a tool failing with the same arguments and error | Pause, once observation mode is off |
|
|
119
|
+
| Going in circles | Flipping between two versions of the code with the same failures | Flag |
|
|
120
|
+
| Context running away | Input tokens rising call after call (2x over 5 calls) with no progress, or over a ceiling you set | Flag |
|
|
121
|
+
| Budget | Estimated task spend reaches the budget, across all runs and sub-agents | Always enforced |
|
|
122
|
+
| Call cap | The next model call would exceed the task's cap | Always enforced |
|
|
123
|
+
|
|
124
|
+
Safeguards: deleting a failing test isn't progress; network and rate-limit errors never count; if events go missing, the run is only flagged, never paused. New workspaces start in **observation mode** (flag only) so people can check the rules on their own agents before anything gets paused.
|
|
125
|
+
|
|
126
|
+
## Configuration
|
|
127
|
+
|
|
128
|
+
All server settings are environment variables. See [`.env.example`](.env.example).
|
|
129
|
+
|
|
130
|
+
| Variable | Default | Purpose |
|
|
131
|
+
| --- | --- | --- |
|
|
132
|
+
| `DATABASE_URL` | `sqlite:///supervisor.db` | Postgres in production (`postgres://` URLs work) |
|
|
133
|
+
| `BASE_URL` | `http://localhost:8000` | Public URL; `https://` turns on secure cookies and HSTS |
|
|
134
|
+
| `APP_NAME` | `Agent Supra` | Product name shown everywhere |
|
|
135
|
+
| `ALLOW_SIGNUP` | `true` | `false` for invite-only (`agent-supra create-user`) |
|
|
136
|
+
| `RETENTION_DAYS` | `30` | Run and server-error data older than this is deleted every 6 hours or by the daily cron |
|
|
137
|
+
| `SMTP_*` | unset | Email alerts |
|
|
138
|
+
| `AGENT_SUPRA_PRICES` | unset | Extra model prices, `{"model": [input, output]}` USD per 1M tokens |
|
|
139
|
+
|
|
140
|
+
## Deploying
|
|
141
|
+
|
|
142
|
+
See [docs/deploying.md](docs/deploying.md). Short version: push to GitHub, create a Render Blueprint from `render.yaml`, set `BASE_URL`.
|
|
143
|
+
|
|
144
|
+
## Security
|
|
145
|
+
|
|
146
|
+
- Passwords: scrypt. API keys and sessions: stored only as SHA-256 hashes; keys are shown once.
|
|
147
|
+
- Every API request is scoped to the key's workspace; another workspace's runs return 404.
|
|
148
|
+
- Dashboard forms are CSRF-protected; cookies are HttpOnly and SameSite.
|
|
149
|
+
- Rate limits on events and on login/sign-up; request size limits; strict security headers.
|
|
150
|
+
- Slack webhooks must point at `hooks.slack.com`, so the setting can't be used to reach internal URLs.
|
|
151
|
+
- Prompts, model replies and code are never sent; tool arguments and errors are sent only as keyed fingerprints. Set `AGENT_SUPRA_FP_KEY` in your agents to make them unguessable.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pip install -e ".[dev]"
|
|
157
|
+
python -m pytest # 84 tests on SQLite
|
|
158
|
+
TEST_DATABASE_URL=postgresql+psycopg://user:pass@localhost/test python -m pytest # on Postgres
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
CI (`.github/workflows/tests.yml`) runs both.
|
|
162
|
+
|
|
163
|
+
## Limits worth knowing
|
|
164
|
+
|
|
165
|
+
- **Costs are estimates** from token counts and the price table (Gemini prices built in, checked 13 Oct 2026). Not your invoice.
|
|
166
|
+
- **Pausing is cooperative**: in-flight calls and tools finish. Agents that call the provider directly, bypassing the wrapper, are not stopped.
|
|
167
|
+
- **Budgets are checked, not reserved**: several sub-agents running in parallel can each make one more call after the budget is crossed.
|
|
168
|
+
- Rate limits are per server process.
|
|
169
|
+
- Thresholds are starting points. Tune them in observation mode on real runs.
|
|
170
|
+
|
|
171
|
+
MIT licensed.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Agent Supra
|
|
2
|
+
|
|
3
|
+
Notice when an unattended AI agent is stuck, pause it before more money goes into a loop, and show exactly why.
|
|
4
|
+
|
|
5
|
+
A spend cap can't tell a stuck agent from one working hard on a tough bug. Agent Supra watches **progress**: if an agent keeps changing code while its failing tests don't get any fewer, the run is flagged (or paused, once you opt in) with the evidence.
|
|
6
|
+
|
|
7
|
+
- **SDK** (`pip install agent-supra`): no dependencies. Wraps Gemini, OpenAI and Anthropic clients.
|
|
8
|
+
- **Hosted service**: dashboard, API keys, alerts to Slack and email, Postgres-backed. One Docker image.
|
|
9
|
+
|
|
10
|
+
## Try it in two minutes (no accounts, no API keys)
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
agent-supra demo # or: python -m agent_supra.demo
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Two scripted agents fix a real bug in a tiny repo, running real pytest. One edits the code four times while the same tests fail and gets **paused**. The other fails twice, changes approach, passes, and is **left alone**. A timeline report is written to `supervisor_report.html`.
|
|
18
|
+
|
|
19
|
+
## Run the service locally
|
|
20
|
+
|
|
21
|
+
On Windows, see [the local PowerShell guide](docs/windows-local.md). The helper
|
|
22
|
+
`python scripts/local.py serve` loads the repository's `.env` file; the bare
|
|
23
|
+
`agent-supra serve` command reads exported environment variables.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cp .env.example .env
|
|
27
|
+
agent-supra serve # SQLite by default; http://localhost:8000
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or with Postgres, the way production runs:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
docker compose up --build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Sign up, create an API key, then follow the quickstart at `/docs/quickstart`.
|
|
37
|
+
|
|
38
|
+
## Connect an agent
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from google import genai
|
|
42
|
+
from agent_supra import Client, SupervisedRun, SupervisorPaused
|
|
43
|
+
|
|
44
|
+
sup = Client() # AGENT_SUPRA_API_KEY and AGENT_SUPRA_URL from the environment
|
|
45
|
+
task = sup.create_task("Fix failing checkout tests", budget_usd=3)
|
|
46
|
+
|
|
47
|
+
with SupervisedRun(sup, task) as run:
|
|
48
|
+
gemini = run.wrap_gemini(genai.Client())
|
|
49
|
+
try:
|
|
50
|
+
while True:
|
|
51
|
+
run.check() # raises SupervisorPaused when paused
|
|
52
|
+
reply = gemini.models.generate_content(model="gemini-3.5-flash-lite", contents=prompt)
|
|
53
|
+
run.tool("edit_file", apply_fix, reply.text, rev=git_rev())
|
|
54
|
+
result = run.tool("run_tests", run_tests, rev=git_rev())
|
|
55
|
+
run.report_tests(result.all_ids, result.failing_ids, rev=git_rev())
|
|
56
|
+
if not result.failing_ids:
|
|
57
|
+
run.finish("success")
|
|
58
|
+
break
|
|
59
|
+
except SupervisorPaused as paused:
|
|
60
|
+
print("Paused:", paused.reason) # don't retry; review it in the dashboard
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
| Call | What it does |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `Client(fail_mode="open")` | Hosted backend. If the service is down, `"open"` keeps the agent running and buffers events; `"closed"` treats it as paused |
|
|
66
|
+
| `run.wrap_gemini(client)` | `google.genai.Client()`: `models.generate_content`, `generate_content_stream`, `chats`, `aio`. Also the older `GenerativeModel` |
|
|
67
|
+
| `run.wrap_openai(client)` | `chat.completions.create` and `responses.create`. Streaming needs `stream_options={"include_usage": True}` |
|
|
68
|
+
| `run.wrap_anthropic(client)` | `messages.create`, including streams |
|
|
69
|
+
| `run.record_model_call(model, in, out)` | Any other model |
|
|
70
|
+
| `run.check()` | Refuses the next step if the run is paused or stopped |
|
|
71
|
+
| `run.tool(name, fn, ..., rev=)` | Runs a tool and records success or failure (fingerprints only, not the raw arguments or errors) |
|
|
72
|
+
| `run.report_tests(suite, failing, rev=)` | The main progress signal |
|
|
73
|
+
| `run.child()` | A sub-agent run sharing the task's budget |
|
|
74
|
+
| `run.finish("success" / "failed" / "unknown")` | Final outcome |
|
|
75
|
+
|
|
76
|
+
Wrapped clients check with the supervisor **before** each model call, so a paused run never reaches the provider.
|
|
77
|
+
|
|
78
|
+
A complete, runnable Gemini agent is in [`examples/gemini_agent.py`](examples/gemini_agent.py). See [docs/testing-with-gemini.md](docs/testing-with-gemini.md).
|
|
79
|
+
|
|
80
|
+
## Detection rules
|
|
81
|
+
|
|
82
|
+
| Rule | Fires when | Default |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| No progress | 4 attempts in a row without the number of failing tests reaching a new low, while the code changes. Swapping one failure for another doesn't count as progress | Pause, once observation mode is off |
|
|
85
|
+
| Exact repeat | The same failure with no code change, or a tool failing with the same arguments and error | Pause, once observation mode is off |
|
|
86
|
+
| Going in circles | Flipping between two versions of the code with the same failures | Flag |
|
|
87
|
+
| Context running away | Input tokens rising call after call (2x over 5 calls) with no progress, or over a ceiling you set | Flag |
|
|
88
|
+
| Budget | Estimated task spend reaches the budget, across all runs and sub-agents | Always enforced |
|
|
89
|
+
| Call cap | The next model call would exceed the task's cap | Always enforced |
|
|
90
|
+
|
|
91
|
+
Safeguards: deleting a failing test isn't progress; network and rate-limit errors never count; if events go missing, the run is only flagged, never paused. New workspaces start in **observation mode** (flag only) so people can check the rules on their own agents before anything gets paused.
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
All server settings are environment variables. See [`.env.example`](.env.example).
|
|
96
|
+
|
|
97
|
+
| Variable | Default | Purpose |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `DATABASE_URL` | `sqlite:///supervisor.db` | Postgres in production (`postgres://` URLs work) |
|
|
100
|
+
| `BASE_URL` | `http://localhost:8000` | Public URL; `https://` turns on secure cookies and HSTS |
|
|
101
|
+
| `APP_NAME` | `Agent Supra` | Product name shown everywhere |
|
|
102
|
+
| `ALLOW_SIGNUP` | `true` | `false` for invite-only (`agent-supra create-user`) |
|
|
103
|
+
| `RETENTION_DAYS` | `30` | Run and server-error data older than this is deleted every 6 hours or by the daily cron |
|
|
104
|
+
| `SMTP_*` | unset | Email alerts |
|
|
105
|
+
| `AGENT_SUPRA_PRICES` | unset | Extra model prices, `{"model": [input, output]}` USD per 1M tokens |
|
|
106
|
+
|
|
107
|
+
## Deploying
|
|
108
|
+
|
|
109
|
+
See [docs/deploying.md](docs/deploying.md). Short version: push to GitHub, create a Render Blueprint from `render.yaml`, set `BASE_URL`.
|
|
110
|
+
|
|
111
|
+
## Security
|
|
112
|
+
|
|
113
|
+
- Passwords: scrypt. API keys and sessions: stored only as SHA-256 hashes; keys are shown once.
|
|
114
|
+
- Every API request is scoped to the key's workspace; another workspace's runs return 404.
|
|
115
|
+
- Dashboard forms are CSRF-protected; cookies are HttpOnly and SameSite.
|
|
116
|
+
- Rate limits on events and on login/sign-up; request size limits; strict security headers.
|
|
117
|
+
- Slack webhooks must point at `hooks.slack.com`, so the setting can't be used to reach internal URLs.
|
|
118
|
+
- Prompts, model replies and code are never sent; tool arguments and errors are sent only as keyed fingerprints. Set `AGENT_SUPRA_FP_KEY` in your agents to make them unguessable.
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install -e ".[dev]"
|
|
124
|
+
python -m pytest # 84 tests on SQLite
|
|
125
|
+
TEST_DATABASE_URL=postgresql+psycopg://user:pass@localhost/test python -m pytest # on Postgres
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
CI (`.github/workflows/tests.yml`) runs both.
|
|
129
|
+
|
|
130
|
+
## Limits worth knowing
|
|
131
|
+
|
|
132
|
+
- **Costs are estimates** from token counts and the price table (Gemini prices built in, checked 13 Oct 2026). Not your invoice.
|
|
133
|
+
- **Pausing is cooperative**: in-flight calls and tools finish. Agents that call the provider directly, bypassing the wrapper, are not stopped.
|
|
134
|
+
- **Budgets are checked, not reserved**: several sub-agents running in parallel can each make one more call after the budget is crossed.
|
|
135
|
+
- Rate limits are per server process.
|
|
136
|
+
- Thresholds are starting points. Tune them in observation mode on real runs.
|
|
137
|
+
|
|
138
|
+
MIT licensed.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Agent Supra: notice when an unattended agent is stuck, pause it, show why.
|
|
2
|
+
|
|
3
|
+
The SDK (this package's top level) has no dependencies. The server lives in
|
|
4
|
+
``agent_supra.server`` and needs ``pip install 'agent-supra[server]'``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "1.0.0"
|
|
8
|
+
|
|
9
|
+
from .client import Client, SupervisorAPIError, SupervisorUnavailable # noqa: E402
|
|
10
|
+
from .detector import DEFAULT_POLICY, Finding, evaluate # noqa: E402
|
|
11
|
+
from .pricing import estimate_cost_micros, register_price # noqa: E402
|
|
12
|
+
from .sdk import SupervisedRun, SupervisorPaused, error_fingerprint, fingerprint # noqa: E402
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Client", "SupervisedRun", "SupervisorPaused", "SupervisorAPIError", "SupervisorUnavailable",
|
|
16
|
+
"DEFAULT_POLICY", "Finding", "evaluate", "estimate_cost_micros", "register_price",
|
|
17
|
+
"error_fingerprint", "fingerprint", "Supervisor", "SupervisorError",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __getattr__(name):
|
|
22
|
+
# Local, in-process supervisor (needs the server extra). Imported lazily so the
|
|
23
|
+
# SDK stays dependency-free.
|
|
24
|
+
if name in ("Supervisor", "SupervisorError"):
|
|
25
|
+
from . import server
|
|
26
|
+
return getattr(server, name)
|
|
27
|
+
raise AttributeError(name)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Command line: ``agent-supra serve | migrate | create-user | prune | demo``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import getpass
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _settings():
|
|
12
|
+
from .server.settings import Settings
|
|
13
|
+
return Settings.from_env()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def cmd_serve(args) -> int:
|
|
17
|
+
import uvicorn
|
|
18
|
+
from .server import db
|
|
19
|
+
db.migrate(db.make_engine(_settings().database_url)) # once, before workers start
|
|
20
|
+
uvicorn.run("agent_supra.server.app:create_app", factory=True, host=args.host, port=args.port,
|
|
21
|
+
workers=args.workers, proxy_headers=True, forwarded_allow_ips=os.environ.get("FORWARDED_ALLOW_IPS", "*"),
|
|
22
|
+
log_level="info")
|
|
23
|
+
return 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def cmd_migrate(_args) -> int:
|
|
27
|
+
from .server import db
|
|
28
|
+
version = db.migrate(db.make_engine(_settings().database_url))
|
|
29
|
+
print(f"Database is at schema version {version}.")
|
|
30
|
+
return 0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cmd_create_user(args) -> int:
|
|
34
|
+
from .server.accounts import Accounts
|
|
35
|
+
from .server.core import Supervisor, SupervisorError
|
|
36
|
+
sup = Supervisor(_settings().database_url)
|
|
37
|
+
password = os.environ.get("AGENT_SUPRA_NEW_PASSWORD") or getpass.getpass("Password (10+ characters): ")
|
|
38
|
+
try:
|
|
39
|
+
_, workspace = Accounts(sup.engine).signup(args.email, password, args.workspace)
|
|
40
|
+
except SupervisorError as exc:
|
|
41
|
+
print(f"Couldn't create the user: {exc}", file=sys.stderr)
|
|
42
|
+
return 1
|
|
43
|
+
print(f"Created {args.email} with workspace {workspace}.")
|
|
44
|
+
return 0
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def cmd_prune(args) -> int:
|
|
48
|
+
from .server.core import Supervisor
|
|
49
|
+
days = args.days if args.days is not None else _settings().retention_days
|
|
50
|
+
removed = Supervisor(_settings().database_url).prune(days)
|
|
51
|
+
print(f"Removed {removed} run(s) older than {days} days.")
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main(argv: list[str] | None = None) -> int:
|
|
56
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
57
|
+
if argv[:1] == ["demo"]:
|
|
58
|
+
# Hand everything after "demo" to the demo's own parser (--observe, --report, ...).
|
|
59
|
+
from .demo import main as demo_main
|
|
60
|
+
return demo_main(argv[1:])
|
|
61
|
+
parser = argparse.ArgumentParser(prog="agent-supra", description="Agent Supra server tools")
|
|
62
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
63
|
+
|
|
64
|
+
serve = sub.add_parser("serve", help="run the web server (reads DATABASE_URL, BASE_URL, ...)")
|
|
65
|
+
serve.add_argument("--host", default=os.environ.get("HOST", "0.0.0.0"))
|
|
66
|
+
serve.add_argument("--port", type=int, default=int(os.environ.get("PORT", "8000")))
|
|
67
|
+
serve.add_argument("--workers", type=int, default=int(os.environ.get("WEB_CONCURRENCY", "2")))
|
|
68
|
+
serve.set_defaults(fn=cmd_serve)
|
|
69
|
+
|
|
70
|
+
sub.add_parser("migrate", help="create or upgrade database tables").set_defaults(fn=cmd_migrate)
|
|
71
|
+
|
|
72
|
+
user = sub.add_parser("create-user", help="create an account (useful with ALLOW_SIGNUP=false)")
|
|
73
|
+
user.add_argument("email")
|
|
74
|
+
user.add_argument("--workspace", help="workspace name")
|
|
75
|
+
user.set_defaults(fn=cmd_create_user)
|
|
76
|
+
|
|
77
|
+
prune = sub.add_parser("prune", help="delete runs older than the retention window")
|
|
78
|
+
prune.add_argument("--days", type=int)
|
|
79
|
+
prune.set_defaults(fn=cmd_prune)
|
|
80
|
+
|
|
81
|
+
sub.add_parser("demo", help="run the two-agent demo locally (try: agent-supra demo --help)")
|
|
82
|
+
|
|
83
|
+
args = parser.parse_args(argv)
|
|
84
|
+
return args.fn(args)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
raise SystemExit(main())
|