Files
ai-town/engine-python/app/main.py
empty 1fd318c9e3 feat(engine): add faction power system with event triggers
- Add FactionData model with power and members fields
- Add FactionEventResult model for faction event responses
- Add faction field to AgentState
- Implement faction classification based on emotion
- Add faction event triggers (festival/panic) when power >= 5
- Update StepResponse to include triggered_faction_event
- Add tests for new faction system

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

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

43 lines
1.1 KiB
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
from .factions import check_and_trigger_faction_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)
# 检查并触发阵营事件
faction_event_result = check_and_trigger_faction_event(state)
# 生成 agent 行动
actions = generate_actions(state)
# 保存状态
save_state(state)
return StepResponse(
world_state=state,
actions=actions,
global_event=global_event_result,
triggered_faction_event=faction_event_result
)
@app.get("/health")
def health():
"""健康检查"""
return {"status": "ok"}