histrategy-sdk
Python SDK for 三國志略 (Histrategy) — AI-powered Three Kingdoms strategy game.
Fully file-based. No network, no server, no in-memory state.
Every turn reads from and writes to ~/.histrategy/rooms/<name>/ on disk.
Designed for AI agents (OpenClaw, Hermes, Codex) that reset context daily.
pip install histrategy-sdk
Quick Start
from histrategy_sdk import Room
# Create a new game
room = Room.create("my-campaign", faction="shu")
# Play a turn — reads state from disk, executes, writes back
result = room.play("联吴抗曹,攻打襄阳")
print(result["narrative"])
# Agent context resets overnight? No problem:
room2 = Room.load("my-campaign")
result2 = room2.play("休养生息,发展内政")
print(f"Year {result2['year']}, {result2['season']}, Turn {result2['turn']}")
print(f"⚔️{result2['faction_status']['strength']} 🍚{result2['faction_status']['food']}")
File Layout
~/.histrategy/rooms/
my-campaign/
world_state.json # Full game state (engine.to_dict())
turns.jsonl # Append-only turn history
metadata.json # Room metadata
multiplayer/shu/
world_state.json
turns.jsonl
metadata.json
multiplayer/cao/
...
multiplayer/wu/
...
API
Room
| Method | Description |
|---|---|
Room.create(name, faction) |
Create new room + save initial state |
Room.load(name) |
Load room from disk |
room.play(decision) |
Execute turn → auto-save to disk |
room.plan() |
Get advisor suggestions |
room.intro() |
Get intro scene |
room.status() |
Get current faction resources |
room.get_turn_history() |
Read all past turns from disk |
DirectEngine
Low-level in-process engine (used internally by Room):
| Method | Description |
|---|---|
DirectEngine(faction) |
Create new engine |
engine.execute(decision) |
Process turn |
engine.to_dict() |
Serialize state |
DirectEngine.from_dict(data) |
Restore from saved state |
TurnResult
| Field | Type | Description |
|---|---|---|
narrative |
str |
AI-generated historical chronicle |
aftermath |
str |
Resource changes summary |
state_changes |
dict |
Numerical state deltas |
new_suggestions |
list[str] |
Next-turn strategy suggestions |
events_occurred |
list[str] |
Character events |
npc_actions |
list[str] |
NPC faction actions |
game_over |
dict | None |
Victory/defeat |
faction_status |
FactionStatus |
Resources and territories |
token_usage |
TokenUsage |
LLM tokens consumed |
Multiplayer
One room per faction. The world_state.json contains ALL factions, so any player can load the state and execute their turn:
# Three players, three rooms, shared game world
shu = Room.create("three-kingdoms/shu", faction="shu")
cao = Room.create("three-kingdoms/cao", faction="cao")
wu = Room.create("three-kingdoms/wu", faction="wu")
# Player 1 (Shu)
r = shu.play("联吴抗曹")
# → saves to three-kingdoms/shu/world_state.json
# Player 2 (Cao) — loads the world state that includes Shu's move
# (Note: each room has its own world_state.json copy;
# for true shared state, all rooms should point to the same file
# or the orchestrator should sync after each turn)
r = cao.play("南征刘备")
License
MIT — Emergence Science
Metadata
Release files for histrategy-sdk 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| histrategy_sdk-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for histrategy_sdk-0.3.2-py3-none-any.whl |
Release files / histrategy_sdk-0.3.2-py3-none-any.whl
| Download URL | histrategy_sdk-0.3.2-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4a16ab9d8481a9d7fd352196db7646dfe8fa8e8d81177f04749eaf885be7bac
|
|
BLAKE2b-256 checksum How to use checksums |
848594a7edff890498f2a0b2a502c91192d58d8582934d0f42b7e50466c3f02e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for histrategy-sdk 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.