Wispverse README

The project's README from github.com/mufengyuan6/Wispverse. As one markdown file: README.md.

芥子 · Wispverse

一个潜伏者引导微型文明走向辉煌历史的 AI 原生演化模拟游戏。

花园里有 15-20 个拟人化角色自主演化出分工、社会与文化;而玩家是"花园中的第 21 个角色"——伪装成它们同类的潜伏者,在暴露风险之下用极少数"抉择时刻"暗中引导文明,直到最终被它们觉醒指认。

核心特性

架构

graph TD
    subgraph FE[React 前端]
        Prelude[SleepingGarden 沉睡氛围 + 序章] -->|选身份后醒来| Canvas[花园画布 Canvas 2D]
        Canvas --> Store[全局状态 + Flow 状态机 7 态]
        Player[玩家面板 / 行动分层 / 暴露风险条] --> Store
        Guide[FirstDayGuide 首日引导] --> Store
        Overlay[抉择时刻 / 时代过渡覆盖层] --> Store
        Chronicle[花园编年史时间轴] --> Store
        Dev[DevDock 开发者浮层 ?dev=1<br/>U12 工具评测面板<br/>U21 节奏仪表盘] --> Store
    end

    Store -->|HTTP /api| API[FastAPI 网关]

    subgraph BE[后端 · 每 5s tick]
        API --> Scheduler[花园调度器]
        Scheduler --> SM[Agent 状态机]
        Scheduler --> Mem[四层记忆系统<br/>瞬时/短期/长期/文件化]
        Scheduler --> Dec[决策引擎<br/>双轨介入判定]
        Scheduler --> Exp[暴露风险系统<br/>观察/疑点传播]
        Scheduler --> Chron[事件生成 / 编年史]
        Scheduler --> Goal[目标系统 / 生活奖励闭环]
        Scheduler --> Belief[贝叶斯信念引擎<br/>KG-as-Belief-State]
        Scheduler --> Week[周制模拟<br/>Plan/Contact/Activity/Review]
        Scheduler --> Pacing[PacingDirector<br/>三铁律 + A 轨反馈契约]
        Scheduler --> Tools[工具调用层<br/>Registry/Executor/Skills]
    end

    SM -->|关键决策| LLM[LLM 网关<br/>opencode + deepseek-v4-flash]
    Dec --> LLM
    Goal --> LLM
    Belief --> LLM
    Tools --> LLM
    Exp --> Judge[LLM-as-Judge 合规校验]
    Mem --> Retriever[混合检索<br/>知识边界⊕规则⊕BM25⊕向量]
    Retriever --> DB[(PostgreSQL + pgvector<br/>Repository 契约)]
    Belief --> DB
    Chron --> DB
    Tools --> EventLog[(EventLog 审计日志<br/>内存环 + JSONL 落盘)]

技术栈

快速开始

演示模式(零依赖,内存仓储 + 规则模板 LLM)

# 1. 后端
cd backend
pip install fastapi uvicorn
uvicorn api:app --port 42732

# 2. 前端
cd frontend
npm install
npm run dev -- --port 42731

浏览器打开 http://localhost:42731,以第 21 个角色身份进入花园。

生产模式(PostgreSQL 存储 + 真实 LLM)

前置:本机 PostgreSQL 已运行(127.0.0.1:5432);配置 LLM_API_KEY。

cd backend
LLM_API_KEY=sk-... python scripts/run_production.py --port 42732

脚本自动:检查并拉起 PostgreSQL → 创建 wispverse 库 → 注入 DATABASE_URL + LLM 环境变量 → 启动 uvicorn。数据落 PostgreSQL(8 类表:characters / memory_entries / belief_entries / event_log / goals / relationships / player_state / trace_log),向量列在 pgvector 启用环境自动升级为 vector(384) + HNSW 索引。

测试

cd backend
python -m pytest                    # 625 用例(无 DATABASE_URL 时 PG 集成测试自动跳过)
DATABASE_URL="postgresql+psycopg2://postgres:[email protected]:5432/wispverse" \
  python -m pytest tests/test_postgres_integration_v42.py   # PostgreSQL 真实读写
cd frontend && npx playwright test  # E2E 43 用例

主要 API

端点 说明
GET /api/state 完整花园状态(角色/环境/事件/时代/信念/合规/trace)
POST /api/player/select 选择化身 + 自定义名字(可选,回退默认名)
POST /api/player/action A 轨:化身日常行为(经输入污染防御三关过滤)
GET /api/player/state 玩家外部视角 + 暴露风险
GET /api/decision / POST /api/decision/respond B 轨:抉择时刻
GET /api/chronicle 花园编年史
POST /api/reveal 最终揭露对话
GET /api/rewards/status 生活奖励闭环状态
GET /api/beliefs 信念系统 + 信念图谱(KG 力导向图)
GET /api/defense/audit 输入污染防御审计(投毒拦截可视化)
GET /api/trace/diagnostics Trace 诊断 + 记忆装配 + 混合检索四路得分
GET/PUT /api/compliance/settings 合规设置(未成年人模式 / 时长限额 / AI 标识)
GET /api/compliance/session 会话时长监控(≥2h 世界内提醒)
GET /api/content-products 内容商品目录(买叙事 · 免费摘要/付费全量)
GET /api/weekly 周制模拟(NPC 下周计划)
GET /api/pacing/mode / PUT Pacing 档位查询与切换(快速 60s / 标准 / 自定义)
GET /api/pacing/stats / signals 节奏统计 / 信念→信号四信号(试探对话/窃窃私语/眼神回避/编年史措辞)
POST /api/pacing/eval/run 玩家体验评测(with/without Pacing 对照,三指标验收线)
GET /api/v1/tools 工具清单(TP-22,DevDock U12 面板)
POST /api/v1/tools/execute 执行单次工具调用(真实世界变更)
GET /api/v1/tools/eval BFCL 口径评测指标(工具选择/参数合规/执行成功/全链路可追踪)
GET /api/v1/tools/eventlog 工具执行审计日志(行为溯源)

评测

Wispverse (mufengyuan6/Wispverse)

Searching Database…

What is this?Wispverse (芥子) is an AI-native evolution simulation game: 15-20 anthropomorphized characters autonomously develop division of labor, society and culture in a garden, while you play the 21st character — a disguised infiltrator who secretly steers the civilization through rare decision moments until they eventually identify you.
Is this an actual playable game, or more of an AI agents demo?A playable web game: the garden is rendered on Canvas 2D by a React 18 + TypeScript + Vite frontend, backed by a Python FastAPI server where every character runs its own state machine driven by LLM decisions.
How do I get it running?There is a zero-dependency demo mode (in-memory storage plus a rule-template LLM) where you just open the browser and enter the garden as one of 21 identities. Production mode needs a running local PostgreSQL (127.0.0.1:5432) and an LLM_API_KEY; the script then creates the wispverse database, injects the env vars and starts uvicorn.
Do all those NPC thoughts burn expensive LLM calls?No — daily NPC behavior runs on a rule engine with zero LLM calls. An LLM gateway (opencode + deepseek-v4-flash) handles decisions with cost-tiered routing and failure fallback to rule templates, and embeddings (bge-m3) run locally. Production mode does require an LLM API key and PostgreSQL with pgvector.
Can I pick and name my own character?Yes — creation is a single-page flow with 5 avatars (Leaf Shadow, Creek Spirit, Ink Heart, Forest Song, Cloud Wanderer) plus a surprise easter egg, and the 21st character enters the garden under your custom name, falling back to the avatar's default.
Is there anything for safety, like parental controls?Yes — a compliance middleware ships with a minors mode, AI-content labeling and session-length monitoring that nudges you in-world after 2+ hours. Input also passes a three-gate poisoning filter with audit rollback to block prompt-injection attempts.
How well tested is all this agentic machinery?Heavily: 625 pytest cases across 44 modules cover agent state machines, memory, exposure propagation, era transitions and real PostgreSQL reads/writes, plus 11 Playwright E2E specs with 43 cases spanning onboarding, decision moments and the tool panel.
Size
0.5 MB
Stars
132
Updated
CommitAug 17
Age
2mo
Commits · 90 Days