English | 简体中文
Foresee every possible future.
Ask it anything unresolved — Bitcoin's trajectory, the next World Cup winner, AI's next milestone, or your own job offer. Five analyst agents with complementary cognitive biases debate independently, ten thousand worldlines are simulated in parallel, and a superforecasting-grade calibration layer converges everything into one actionable probability — all streamed live with cinematic motion design.
The built-in UI is currently in Chinese (Simplified). The engine, API, and all documentation work regardless of language.
pip install -r requirements.txt
python run.pyOpen http://127.0.0.1:8712 in your browser. No API key required — the built-in local inference core works out of the box.
Click Model Settings in the navigation bar, pick a provider preset (OpenAI / DeepSeek / Kimi / Qwen / OpenRouter), paste your API key, hit Test Connection, then save — takes effect immediately, no restart needed. The configuration is stored locally in data/settings.json, and the key is always masked when read back through the API.
Environment variables are also supported (useful for server deployments; UI settings take precedence):
PRESAGE_LLM_API_KEY=sk-xxxx
PRESAGE_LLM_BASE_URL=https://api.deepseek.com/v1
PRESAGE_LLM_MODEL=deepseek-chatWith an LLM connected, the question restatement, evidence drivers, and the five agents' arguments are generated by the real model, while the numerical layer (simulation and calibration) still runs through the same local pipeline. If the LLM call fails, the engine degrades seamlessly to the local core — the service never goes down.
| Stage | What happens |
|---|---|
| Ⅰ Question Parsing | Domain fingerprinting (9 domains), time-horizon extraction, proposition-type detection |
| Ⅱ Base-Rate Anchoring | Domain historical base rates (Beta priors) + evidence-weighted drivers → anchor probability |
| Ⅲ Panel Debate | Five agents rule independently: the Archivist ◭ · the Trend Hunter ◮ · the Skeptic ◬ · the Signal Analyst ◈ · the Black-Swan Watcher ◉ |
| Ⅳ Worldline Simulation | 10,000 log-odds random walks seeded from the panel's belief distribution, with domain volatility injected |
| Ⅴ Superforecasting Calibration | Confidence-weighted log-odds pooling + mild extremization (d = 1.18, per Satopää / Baron et al.); once ≥40 resolved outcomes exist, empirical recalibration kicks in automatically (a single-parameter logistic recalibration: grid search minimizing historical Brier score, with shrinkage) |
| Ⅵ Oracle Verdict | Final probability, confidence, P10–P90 interval, three-scenario projection, catalysts & risk list |
Reproducibility: the same question asked on the same day uses the same random seed — results are fully reproducible (audit-friendly).
A forecast should be tested, not just emitted:
- Mark due predictions as Hit / Miss in the archive drawer (reversible)
- The engine computes the Brier score and a five-bucket calibration curve (
GET /api/stats) - The home page shows a live calibration score (0–100, higher is better) and the number of resolved cases
- The archive drawer includes a track-record strip: per-bucket "average predicted probability vs. actual hit rate" in two colors — calibration quality at a glance
- Outcomes feed back into the engine: with ≥40 resolved samples, every new prediction learns a recalibration factor from your own track record, correcting systematic bias — the more you predict and resolve, the sharper the engine gets
- Archive replay: click any history item to fully restore its verdict page (gauge, scenarios, evidence balance) and re-export the share card
One-click share card export from the verdict page: a 1200×630 oracle-styled PNG rendered on Canvas (question + probability + P10–P90 interval + the five-agent spectrum), sized for every major social platform.
Interactive docs at http://127.0.0.1:8712/api/docs (auto-generated by FastAPI).
| Endpoint | Method | Description |
|---|---|---|
/api/stream?question=… |
GET | SSE streaming prediction (stage / thought / driver / persona / mc_* / final / done) |
/api/history?limit=40 |
GET | Prediction archive list |
/api/prediction/{id} |
GET | Full verdict data for one archived prediction (replay) |
/api/resolve/{id}?outcome=1|0|-1 |
POST | Outcome resolution: hit / miss / revoke † |
/api/stats |
GET | Global stats (incl. Brier score & calibration buckets) |
/api/settings |
GET / POST | LLM config read (key masked) / save † |
/api/settings/test |
POST | LLM connectivity test † |
/api/health |
GET | Health check |
† Write endpoints require the X-Presage-Token header once an admin token is configured.
- Local use (default): the server binds to
127.0.0.1; nothing to configure. - Before exposing to LAN / the internet, you must:
- Set an admin token:
PRESAGE_ADMIN_TOKEN=<strong random string>— protects write endpoints (model config, outcome resolution); - Terminate TLS behind a reverse proxy (Nginx / Caddy) and narrow CORS to your actual domain;
- Note that the API key in
data/settings.jsonis stored in plaintext — keep host disk access controlled.
- Set an admin token:
- All dynamic frontend content (user input, LLM output) is rendered through a single HTML-escaping helper to prevent injection.
docker build -t presage .
docker run -p 8712:8712 -v presage-data:/app/data presageThe image ships with a health check; the /app/data volume persists the prediction archive and model settings.
pip install -r requirements-dev.txt
pytest tests -q # 41 unit/API tests: classifier, Monte Carlo (both paths), calibration & recalibration, storage, auth, SSE heartbeat
ruff check . # static analysis (E/W/F/I/B/UP rule set), zero warnings- Dual-path Monte Carlo: numpy-vectorized by default (~9× faster for 10k runs), with a pure-Python fallback when numpy is unavailable; both paths are deterministic under the same seed and statistically equivalent (locked by tests).
- Production-grade SSE: comment-line heartbeats are injected whenever the event gap exceeds a threshold (keeps reverse proxies / load balancers from killing "idle" connections; tune via
PRESAGE_SSE_HEARTBEAT), plusno-transformandX-Accel-Buffering: noresponse headers. - SQLite WAL mode: concurrent reads during writes +
busy_timeout, stronger crash recovery. - CI: GitHub Actions runs lint + tests + Docker build on Python 3.11 / 3.12 (
.github/workflows/ci.yml). - E2E:
verify_api.py(27 endpoint assertions + live SSE event integrity),verify_final.py(full prediction flow / track-record strip / archive replay / mobile), plusverify_ui.py/verify_round3.py/verify_settings.py/verify_console.py.
- Backend: FastAPI + SSE streaming + SQLite archive, fully async
- Frontend: zero-build vanilla HTML/CSS/JS — Canvas starfield, SVG oracle gauge, worldline fan chart, typewriter reasoning stream, all hand-written
- Engine: domain knowledge base + multi-agent pooling + Monte Carlo simulation (numpy-vectorized) + extremized calibration
presage/
├── run.py # one-command launcher (auto port fallback)
├── requirements.txt / requirements-dev.txt
├── Dockerfile / .dockerignore
├── pyproject.toml # ruff / pytest config
├── .github/workflows/ci.yml
├── backend/
│ ├── main.py # FastAPI + SSE
│ ├── config.py / models.py / storage.py
│ └── engine/
│ ├── orchestrator.py # six-stage pipeline orchestration
│ ├── classifier.py # domain / horizon / type parsing
│ ├── knowledge.py # nine-domain knowledge base
│ ├── personas.py # the five agents
│ ├── montecarlo.py # worldline simulation (numpy / pure-Python)
│ ├── calibration.py # pooling & extremization
│ └── llm.py # optional LLM enhancement (OpenAI-compatible)
├── tests/ # pytest unit & API tests
└── frontend/
├── index.html
├── css/style.css
└── js/ (starfield / gauge / charts / app)
The architecture draws on publicly documented design patterns (multi-agent debate, consensus pooling, research→reasoning→calibration pipelines, SSE reasoning panels) from the following permissively licensed open-source projects. All code in this repository is an original implementation — no source code was copied:
- Metaculus/forecasting-tools (MIT)
- Alchemist-X/predict-raven (MIT)
- defidaddydavid/polyswarm (MIT)
- codebyollie/forecast-agents (MIT)
All of the above are MIT-licensed, permitting study, modification, and commercial use.
Disclaimer: PRESAGE produces structured probabilistic assessments for decision support only. Nothing it outputs constitutes investment, legal, or medical advice.