A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物
Go to file
liyizhouAI 1fef01d979 feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button
This is the v0.3 milestone commit before the v0.4 big version push.
Major themes: process replay, runtime stability, cost observability.

## New Features

- **Manus-style process replay** (frontend + backend)
  - `GET /api/simulation/<id>/replay` returns full workflow + agents + rounds + aggregate
  - `frontend/src/views/SimulationReplayView.vue` 3-column layout (workflow / actions / stats)
  - bottom scrubber with play/pause/step + 5 speed levels (0.5x-10x)
  - filters out stale actions from previous runs via latest simulation_start timestamp

- **Token usage tracking** (`backend/app/utils/token_tracker.py`)
  - process-wide stage→model→tokens counter
  - LLMClient auto-records prompt/completion tokens after each call
  - stages tagged at API entry: step1_ontology, step2_graph_build, step3_prepare, step5_report
  - `GET /api/usage/summary` for live stats + CNY cost estimate
  - `GET /api/usage/estimate-simulation` for OASIS subprocess estimation
  - pricing table for GLM/SiliconFlow/MiniMax/OpenAI/Anthropic models
  - documented as internal-use, removed from customer-facing builds

- **Step 2 "Skip & Continue" button**
  - lets user stop profile generation early and proceed with what's already generated
  - `simulation_manager.request_accelerate()` + cancel_check in oasis_profile_generator
  - new endpoint `POST /api/simulation/prepare/accelerate`

## Critical Bug Fix

- **SIGTERM no longer kills running simulation subprocess**
  - root cause: `SimulationRunner.register_cleanup()` registered SIGTERM/SIGINT/SIGHUP handlers
    that called `os.killpg` on every tracked sim child, even though spawn already used
    `start_new_session=True` to give children isolated sessions
  - fix: neutered `register_cleanup` to a no-op; `cleanup_all_simulations` itself preserved
    for explicit stop_simulation paths
  - validated: killed Flask backend twice, simulation subprocess kept running
  - impact: hot-reload backend code without interrupting in-flight simulations

## Performance & Tuning

- semaphore 30 → 100 (twitter + reddit) for higher LLM concurrency
- discovered 200 agents as memory/cost/statistical sweet spot for 8G server
  (503 agents OOMs both platforms; 200 agents fits cleanly with 95% confidence margin)

## Documentation

- **PRD.md** rewritten as v0.3 baseline (10 chapters + 2 appendices, 639 lines)
  - product positioning across 3 usage modes (one-shot / model-reuse / SaaS)
  - v0.4 roadmap: domestic platforms (douyin/wechat/xiaohongshu/weibo), fork sim, multi-tenant
  - operational lessons: HF mirror, Tencent PyPI mirror, GLM-4-Flash choice, agent count
  - decision log with dates
  - per-stage token/cost breakdown for typical 200-agent run
- **README.md / README-ZH.md** updated with replay step + Graphiti+Neo4j

## Files Touched

19 files changed, 1105 insertions(+), 246 deletions(-)
2026-04-15 09:37:22 +08:00
.github/workflows feat(docker): add Docker support with Dockerfile, docker-compose.yml, and .dockerignore; update README for Docker deployment instructions 2026-01-22 14:35:41 +08:00
backend feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
frontend feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
locales feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
static/image feat(README): add demo video sections for Wuhan University Public Opinion and Dream of the Red Chamber simulations; include new image asset 2026-01-20 11:17:11 +08:00
.dockerignore feat(docker): add Docker support with Dockerfile, docker-compose.yml, and .dockerignore; update README for Docker deployment instructions 2026-01-22 14:35:41 +08:00
.env.example refactor(.env.example): update LLM API configuration comments for clarity and add usage note 2026-01-20 18:05:36 +08:00
.gitignore fix: CORS duplicate header + Neo4j query + DateTime serialization 2026-04-14 13:53:47 +08:00
Dockerfile feat(docker): add Docker support with Dockerfile, docker-compose.yml, and .dockerignore; update README for Docker deployment instructions 2026-01-22 14:35:41 +08:00
LICENSE Add GNU AGPL v3 License 2025-12-19 15:24:16 +08:00
PRD.md feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
README-ZH.md feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
README.md feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button 2026-04-15 09:37:22 +08:00
docker-compose.yml feat(docker): add Docker support with Dockerfile, docker-compose.yml, and .dockerignore; update README for Docker deployment instructions 2026-01-22 14:35:41 +08:00
package-lock.json feat: merge upstream i18n + rebrand MiroFish → Foresight 先见之明 2026-04-11 16:40:13 +08:00
package.json feat: merge upstream i18n + rebrand MiroFish → Foresight 先见之明 2026-04-11 16:40:13 +08:00

README.md

Foresight Logo

666ghj%2FForesight | Trendshift

简洁通用的群体智能引擎,预测万物
A Simple and Universal Swarm Intelligence Engine, Predicting Anything

666ghj%2Foresight | Shanda

GitHub Stars GitHub Watchers GitHub Forks Docker Ask DeepWiki

Discord X Instagram

English | 中文文档

Overview

Foresight is a next-generation AI prediction engine powered by multi-agent technology. By extracting seed information from the real world (such as breaking news, policy drafts, or financial signals), it automatically constructs a high-fidelity parallel digital world. Within this space, thousands of intelligent agents with independent personalities, long-term memory, and behavioral logic freely interact and undergo social evolution. You can inject variables dynamically from a "God's-eye view" to precisely deduce future trajectories — rehearse the future in a digital sandbox, and win decisions after countless simulations.

You only need to: Upload seed materials (data analysis reports or interesting novel stories) and describe your prediction requirements in natural language
Foresight will return: A detailed prediction report and a deeply interactive high-fidelity digital world

Our Vision

Foresight is dedicated to creating a swarm intelligence mirror that maps reality. By capturing the collective emergence triggered by individual interactions, we break through the limitations of traditional prediction:

  • At the Macro Level: We are a rehearsal laboratory for decision-makers, allowing policies and public relations to be tested at zero risk
  • At the Micro Level: We are a creative sandbox for individual users — whether deducing novel endings or exploring imaginative scenarios, everything can be fun, playful, and accessible

From serious predictions to playful simulations, we let every "what if" see its outcome, making it possible to predict anything.

🌐 Live Demo

Welcome to visit our online demo environment and experience a prediction simulation on trending public opinion events we've prepared for you: foresight-live-demo

📸 Screenshots

Screenshot 1 Screenshot 2
Screenshot 3 Screenshot 4
Screenshot 5 Screenshot 6

🎬 Demo Videos

1. Wuhan University Public Opinion Simulation + Foresight Project Introduction

Foresight Demo Video

Click the image to watch the complete demo video for prediction using BettaFish-generated "Wuhan University Public Opinion Report"

2. Dream of the Red Chamber Lost Ending Simulation

Foresight Demo Video

Click the image to watch Foresight's deep prediction of the lost ending based on hundreds of thousands of words from the first 80 chapters of "Dream of the Red Chamber"

Financial Prediction, Political News Prediction and more examples coming soon...

🔄 Workflow

  1. Graph Building: Seed extraction & Individual/collective memory injection & GraphRAG construction (Graphiti + Neo4j)
  2. Environment Setup: Entity relationship extraction & Persona generation & Agent configuration injection (with "Skip & Continue" button)
  3. Simulation: Dual-platform parallel simulation (Twitter + Reddit) & Auto-parse prediction requirements & Dynamic temporal memory updates
  4. Report Generation: ReportAgent with rich toolset for deep interaction with post-simulation environment
  5. Deep Interaction: Chat with any agent in the simulated world & Interact with ReportAgent
  6. Process Replay (v0.3 New): Manus-style draggable timeline to replay the entire workflow and every round of agent actions — perfect for retros and demos

🚀 Quick Start

Prerequisites

Tool Version Description Check Installation
Node.js 18+ Frontend runtime, includes npm node -v
Python ≥3.11, ≤3.12 Backend runtime python --version
uv Latest Python package manager uv --version

1. Configure Environment Variables

# Copy the example configuration file
cp .env.example .env

# Edit the .env file and fill in the required API keys

Required Environment Variables:

# LLM API Configuration (supports any LLM API with OpenAI SDK format)
# Recommended: Alibaba Qwen-plus model via Bailian Platform: https://bailian.console.aliyun.com/
# High consumption, try simulations with fewer than 40 rounds first
LLM_API_KEY=your_api_key
LLM_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
LLM_MODEL_NAME=qwen-plus

# Zep Cloud Configuration
# Free monthly quota is sufficient for simple usage: https://app.getzep.com/
ZEP_API_KEY=your_zep_api_key

2. Install Dependencies

# One-click installation of all dependencies (root + frontend + backend)
npm run setup:all

Or install step by step:

# Install Node dependencies (root + frontend)
npm run setup

# Install Python dependencies (backend, auto-creates virtual environment)
npm run setup:backend

3. Start Services

# Start both frontend and backend (run from project root)
npm run dev

Service URLs:

  • Frontend: http://localhost:3000
  • Backend API: http://localhost:5001

Start Individually:

npm run backend   # Start backend only
npm run frontend  # Start frontend only

Option 2: Docker Deployment

# 1. Configure environment variables (same as source deployment)
cp .env.example .env

# 2. Pull image and start
docker compose up -d

Reads .env from root directory by default, maps ports 3000 (frontend) / 5001 (backend)

Mirror address for faster pulling is provided as comments in docker-compose.yml, replace if needed.

📬 Join the Conversation

QQ Group

 

The Foresight team is recruiting full-time/internship positions. If you're interested in multi-agent simulation and LLM applications, feel free to send your resume to: foresight@shanda.com

📄 Acknowledgments

Foresight has received strategic support and incubation from Shanda Group!

Foresight's simulation engine is powered by OASIS (Open Agent Social Interaction Simulations), We sincerely thank the CAMEL-AI team for their open-source contributions!

📈 Project Statistics

Star History Chart