Files
ai-town/engine-python/app/main.py
empty 8b90d55f02 feat: AI Town MVP - 完整三层架构实现
- Python FastAPI 引擎:世界状态模拟、全局能量条、世界事件系统
- Node.js WebSocket 服务器:实时通信、事件队列批处理
- 前端仪表盘:世界状态可视化、行动日志、事件展示

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 10:29:35 +08:00

38 lines
953 B
Python

from fastapi import FastAPI
from .models import StepRequest, StepResponse
from .state import load_state, save_state
from .engine import process_events, generate_actions, check_and_trigger_global_event
app = FastAPI(title="AI Town Engine", version="0.1.0")
@app.post("/step", response_model=StepResponse)
def step(request: StepRequest) -> StepResponse:
"""执行一个模拟步骤"""
# 加载当前状态
state = load_state()
# 处理事件并更新状态
state = process_events(state, request.events)
# 检查并触发世界级事件
state, global_event_result = check_and_trigger_global_event(state)
# 生成 agent 行动
actions = generate_actions(state)
# 保存状态
save_state(state)
return StepResponse(
world_state=state,
actions=actions,
global_event=global_event_result
)
@app.get("/health")
def health():
"""健康检查"""
return {"status": "ok"}