Skip to main content

ghocentric-ghost-engine

A deterministic state engine for persistent NPC relationships, independent multi-emotion state, social consequences, epistemic state, scenario resolution, and AI-driven game systems.

Ghost is not a language model, a renderer, or a replacement for a game engine.

Ghost provides the authoritative state layer underneath higher-level systems. It tracks what happened, validates what may change, preserves the result, and returns JSON-safe packets that a game, simulation, dialogue layer, or optional LLM can use.

Core principle: models and game code may propose events or decisions. Ghost owns deterministic state mutation and the record of what became true.

Live browser demo: https://ghocentric.github.io/ghost-prototype/ PyPI: https://pypi.org/project/ghocentric-ghost-engine/ Source: https://github.com/GhoCentric/ghost-prototype

Current Release

Package:    ghocentric-ghost-engine
Version:    1.11.0
Python:     3.9+
Runtime dependencies: none
Validation: 2,745 passed, 1 skipped

The actively maintained package is this ghost-engine/ directory.

Installation

pip install ghocentric-ghost-engine

Quick Start

GhostAPI is the recommended integration surface.

from ghost import GhostAPI

ghost = GhostAPI()

packet = ghost.apply_event(
    "player",
    "shopkeeper",
    {
        "type": "betrayal",
        "intensity": 1.0,
    },
)

relationship = ghost.get_relationship(
    "player",
    "shopkeeper",
)

print(packet["relationship"]["state"])
print(relationship["trust"])

Use GhostEngine directly for lower-level engine access, focused tests, or specialized integrations.

What Ghost Owns

Ghost currently provides deterministic systems for:

  • relationship state with separate positive and negative history;
  • independent bounded multi-emotion state with per-channel inertia, salience, and deterministic spotlight hysteresis;
  • maturity, volatility, pressure, transitions, and diagnostics;
  • social propagation and bounded world effects;
  • persistent NPC-specific action interpretation;
  • persistent attention / flow with deterministic breakthrough;
  • a read-only salience bridge across persistent emotion and interpretation state;
  • temperament interpretation;
  • threat-response policy;
  • objective facts, observations, reports, beliefs, evidence, provenance, and explicit belief revision;
  • validated scenario configuration and atomic scenario resolution;
  • fight-level objective packets, initiative state, and recovery-read control;
  • JSON-safe snapshots, strict restoration, and legacy snapshot migration;
  • public packet validation and copy isolation;
  • optional LLM prompt and response adapters.

Ghost does not own:

  • graphics, animation, physics, pathfinding, input, or audio;
  • a game's custom inventory, quest, combat, or economy implementation;
  • unrestricted autonomous NPC control;
  • arbitrary natural-language truth;
  • hidden network calls from the deterministic core.

The Authority Boundary

A normal integration follows this shape:

game event or observation
        ↓
Ghost validates and updates authoritative state
        ↓
Ghost returns copied state, diagnostics, or a bounded policy packet
        ↓
the host game applies that result to its own mechanics and presentation

In v1.11.0, Ghost also provides a registered-agent state boundary. The host registers durable agent identity, capabilities, current affordances, observations, values, goals, and motive configuration; Ghost validates and preserves that state. The host still owns engine-specific execution, animation, pathfinding, and arbitrary action selection.

Registered Agent Runtime

v1.11.0 adds a durable registered-agent layer without turning Ghost into an autonomous action executor. GhostAPI.register_agent(...) creates the identity and GhostAPI.agent(...) returns a bound GhostAgent handle.

The bound handle owns the agent-specific integration surface for:

values
goals and goal transitions
capabilities
current affordances and affordance history
observations and observation history
motive profiles, signals, field evaluation, and history
from ghost import GhostAPI

ghost = GhostAPI()
ghost.register_agent(
    "guard",
    role="gate_guard",
    capabilities=["warn", "call_backup"],
)

guard = ghost.agent("guard")
guard.set_value("duty", 0.9)
guard.add_goal("protect_gate", priority=0.9)
guard.set_affordances([
    {"id": "warn_player", "capability": "warn"},
    {"id": "call_backup", "capability": "call_backup"},
])

print(guard.state())

Capabilities and affordances are host-supplied constraints. Ghost preserves and validates them; it does not discover engine abilities or execute the selected game action for the host.

Continuity Runtime

v1.11.0 also adds deterministic continuity operations that join persistent emotion, interpretation, attention, causal episodes, and recall without replaying the source event.

Public operations are:

continuity_event
recall_episode
recall_dimension
continuity_tick
continuity_state

Continuity history uses lazy logical-time materialization, a sparse hot working set, and lossless deferred cold-history storage. These are implementation strategies for reducing persistence and tick cost; they do not change the host/authority boundary.

Relationship State

Ghost relationships use separate positive and negative reservoirs:

trust = positive reservoir - negative reservoir

This preserves emotional history. A later helpful action does not automatically erase betrayal, repeated abuse, or accumulated hostility.

from ghost import GhostAPI

ghost = GhostAPI()

ghost.apply_event(
    "player",
    "merchant",
    {
        "type": "help",
        "intensity": 1.0,
    },
)

ghost.apply_event(
    "player",
    "merchant",
    {
        "type": "betrayal",
        "intensity": 1.0,
    },
)

relationship = ghost.get_relationship(
    "player",
    "merchant",
)

print(relationship["state"])
print(relationship["diagnostics"])

Public relationship packets can expose:

  • trust;
  • friendly, neutral, or hostile state;
  • transition and trigger data;
  • pressure and near-break state;
  • maturity and volatility;
  • positive and negative volatility;
  • measurable change diagnostics.

Relationship personalities include:

balanced
forgiving
resentful
volatile

Multi-Emotion State

Ghost keeps relationship state and emotional state as separate persistent layers.

The default emotional channels are independently bounded in 0..1:

anger
fear
grief
hope
joy

An emotional level is not an event weight. Ghost distinguishes:

level        = current emotional state
impulse      = signed event input
sensitivity  = per-agent gain
inertia      = persistence toward baseline over time
salience     = current attention pressure
spotlight    = stateful dominant attention

Event outcomes are deterministic. Ghost combines an explicit event impulse with event intensity, per-agent sensitivity, and caller-owned context modifiers. Positive impulses saturate toward 1.0; negative impulses reduce the current level. Each channel later moves toward its own baseline according to its inertia.

from ghost import GhostAPI

ghost = GhostAPI()

ghost.register_emotional_agent(
    "guard",
    sensitivities={
        "anger": 1.0,
        "fear": 1.0,
        "grief": 1.0,
    },
)

packet = ghost.apply_layered_event(
    "player",
    "guard",
    {
        "type": "betrayal",
        "intensity": 1.0,
    },
)

print(packet["layered_state"]["relationship_state"])
print(packet["layered_state"]["trust"])
print(packet["layered_state"]["emotional_levels"])
print(packet["layered_state"]["dominant_emotion"])

The same relationship result can coexist with different emotional vectors when agents have different sensitivities.

Spotlight selection uses deterministic hysteresis. Emotion levels update immediately, but a near-tied raw salience leader does not replace the incumbent spotlight until it clears the configured switch margin. The default margin is 0.05.

raw leader: hope   0.595
incumbent:  anger  0.548
gap:               0.046
margin:            0.050

result: retain anger spotlight

The next tick can still produce a real handoff when another emotion clears the margin.

Ghost exposes emotional state and pressure. It does not turn an emotion directly into an engine-specific action.

Public operations:

register_emotional_agent
emotional_state
emotional_event_profiles
configure_emotional_event
apply_emotional_event
tick_emotions
apply_layered_event

Emotion snapshot sub-schema 1.1 preserves spotlight state and the switch margin. Legacy emotion snapshot sub-schema 1.0 remains restorable.

Run the focused demos:

python -m ghost.examples.emotional_state_demo
python -m ghost.examples.emotional_spotlight_hysteresis_demo

Interpretation, Attention, and Flow

Ghost v1.10.0 adds persistent NPC-specific interpretation and persistent attention / flow without giving either layer authority to invent world facts or choose final NPC actions.

An objective action can carry the same observable features to two agents while their configured histories, sensitivities, rules, and thresholds produce different persistent meanings:

ghost.register_interpretation_agent(
    "sera",
    rules={
        "action:report_evidence": {
            "betrayal": 1.0,
        },
    },
)

packet = ghost.evaluate_action_meaning(
    "sera",
    "report_evidence",
    source="player",
)

Public interpretation operations:

register_interpretation_agent
configure_interpretation_rule
interpretation_state
evaluate_action_meaning

Interpretation state is persistent and deterministic. The host supplies the objective action and observable features; Ghost applies configured agent-specific meaning rules. It does not infer hidden facts, generate dialogue, or select the final behavior.

Attention / flow is a separate persistent layer:

register_attention_agent
attention_state
advance_attention
persistent_salience
advance_attention_from_state

persistent_salience(...) is a read-only bridge over persistent emotional and interpretation state. advance_attention_from_state(...) may compress what reaches the foreground while flow is active, but the underlying source state is not rewritten. Strong novelty, threat, contradiction, or interpretation pressure can break through that compression.

This gives Ghost an explicit separation between:

persistent source state
        ≠
currently attended / foreground state

Interpretation snapshot sub-schema: 1.0.

Attention snapshot sub-schema: 1.0.

The top-level Ghost snapshot schema remains 1.0, and emotion snapshot sub-schema 1.1 remains unchanged.

Social Propagation

A direct event can produce deterministic secondary effects for observers.

packet = ghost.propagate_social_event(
    source="player",
    target="shopkeeper",
    event="betrayal",
    observers=[
        "guard",
        "elder",
        "rival",
    ],
    weights={
        "guard": 1.0,
        "elder": 0.7,
        "rival": 0.25,
    },
)

Propagation packets can contain:

  • the direct relationship result;
  • bounded observer trust changes;
  • social heat;
  • pressure labels;
  • fear, resentment, order, and guard-suspicion deltas;
  • copied relationship and world-state data.

Epistemic State

Ghost separates objective runtime truth from what actors observe, report, believe, and later revise.

objective fact
    ≠ observation
    ≠ spoken report
    ≠ belief

A report does not become truth, and receiving a report does not silently force a belief.

from ghost import GhostAPI

ghost = GhostAPI()

ghost.record_fact(
    fact_id="millcross_food_001",
    source="game_rule",
    subject="royal_guard",
    predicate="confiscated",
    object="millcross_food",
    attributes={
        "quantity": 6,
    },
)

report = ghost.report(
    speaker="villager_3",
    audience="player",
    claim={
        "statement": "They took everything.",
    },
    confidence=0.82,
)

assert ghost.get_belief(
    "player",
    "millcross_food_loss",
) is None

Public epistemic operations include:

record_fact
get_fact
observe
report
add_evidence
evaluate_beliefs
get_belief
propagate_belief

Beliefs are actor-owned, provenance-aware, explicitly evaluated, and linked across revisions. Epistemic state is included in snapshots and deterministic restoration.

Run the public smoke demo:

python -m ghost.examples.epistemic_api_smoke_demo

Threat-Response Policy

Ghost can evaluate a bounded set of deterministic response labels from persistent relationship state, temperament, and explicit caller-owned context.

packet = ghost.evaluate_npc_threat_response(
    npc="merchant",
    source="player",
    target="merchant",
    temperament="anxious",
    context={
        "player_armed": True,
        "player_aiming": True,
        "escape_route": True,
    },
)

print(packet["selected_response"])

Current labels are:

fight
call_guards
confront
surrender
flee
freeze
warn
ignore

The policy is read-only. It returns a recommendation packet; it does not animate or execute the response.

Combat Control

The public core includes small deterministic combat-control contracts:

build_combat_objective
advance_combat_initiative
lock_combat_recovery_read
resolve_combat_recovery

These packets validate objective pressure, initiative transitions, hidden recovery reads, and deterministic resolution without randomness.

They are not a universal combat system. Ghost Revolution uses them as part of a larger game-specific reference implementation.

Scenario Runtime

ScenarioRuntime wraps GhostAPI with validated JSON-safe scenario configuration and atomic action resolution.

A rejected action restores the prior checkpoint instead of leaving partial state behind. This provides a tested boundary for game-specific facades without moving their presentation logic into Ghost core.

Snapshots and Restoration

Use snapshot() for saves and external boundaries.

snapshot = ghost.snapshot()

restored = GhostAPI.from_snapshot(
    snapshot
)

assert restored.snapshot() == snapshot

Snapshots include separate package and schema metadata:

ghost_version
schema_version

Package release numbers and snapshot schema versions are intentionally independent. The current runtime validates complete snapshot structure, rejects unsupported schemas, migrates supported legacy metadata, and restores copied state.

state() is a live mutable view intended for controlled inspection. Do not use it as a save-file or external adapter contract.

Optional LLM Layer

Ghost does not require an LLM.

The package includes optional helpers and the Ghost Revolution reference demo, where an LLM can propose constrained strategy or narration while deterministic game state remains authoritative.

The reference rule is:

LLM proposes
Ghost validates or resolves
the host game presents the result

API keys are caller-owned and read from environment configuration. They are not embedded in the package.

Ghost Revolution Reference Demo

ghost.examples.ghost_revolution is a terminal reference implementation used to exercise Ghost under a larger persistent game loop.

It demonstrates:

  • towns that retain player-history consequences;
  • relationships, social pressure, and epistemic belief state;
  • guarded-town reports, evidence, investigation, and belief revision;
  • raid preparation, recruitment, heat, and kingdom pressure;
  • deterministic snapshots and branch restoration;
  • a king and Champion fight with LLM strategy proposals;
  • separate opponent prediction and physical combat action;
  • symmetric heavy, light, feint, bait, parry, deflect, and dodge options;
  • Ghost-authoritative combat resolution and audit packets;
  • LLM narration conditioned on accumulated game state.

Ghost Revolution is an example and test laboratory. Its towns, king, menus, combat damage, and presentation are not universal Ghost-core concepts.

Local Android launchers included in the repository are:

./run-llm-ai-dev.sh
./run-llm-ai-cinematic.sh

They expect a local .env.local containing OPENAI_API_KEY. Do not commit that file.

Order Coordination Reference Application

ghost.examples.order_coordination is a separate application-layer proof built only on Ghost's public API. Restaurant/order concepts are not part of the Ghost core.

The reference workflow demonstrates:

  • authoritative item state that does not come from model narration;
  • explicit ambiguity when more than one modifier target remains plausible;
  • customer clarification represented as evidence and belief revision;
  • corrections that invalidate stale confirmation;
  • idempotent operation IDs and rollback after failed compound operations;
  • strict snapshot restoration for items, ambiguities, corrections, confirmations, ledger history, and Ghost epistemic references;
  • submission gating that refuses unresolved ambiguity or stale confirmation.

Run the deterministic demo with:

python -m ghost.examples.order_coordination_demo

The companion benchmark modules include a deterministic fault-containment benchmark, a paired live-model benchmark, and an offline report replay. The live benchmark makes one model call per scenario trial and applies the same extracted packet to transcript-only and Ghost-backed modes. Model confidence remains advisory metadata rather than mutation authority.

This reference application is intentionally narrow. It demonstrates transferable state-authority and coordination patterns; it does not claim speech-recognition accuracy, general model intelligence, or production restaurant readiness.

Packaged CLI Demos

The installed package exposes:

ghost-demo
ghost-npc-demo
ghost-shopkeeper-demo
ghost-math-demo
ghost-diagnostics-demo
ghost-social-demo
ghost-temperament-demo
ghost-threat-response-demo
ghost-epistemic-demo
ghost-revolution-demo
ghost-revolution-dev
ghost-revolution-llm-dev
ghost-order-coordination-demo

Ghost Revolution is a playable reference prototype and systems demonstration, not a finished game.

  • ghost-revolution-demo starts the normal campaign from Day 1.
  • ghost-revolution-dev opens the developer shortcut panel so later-game states, siege routes, champion combat, and the king fight can be reached directly.
  • ghost-revolution-llm-dev opens the same developer panel with the real LLM opponent and real LLM fight narration enabled. It requests the user's own OpenAI API key with hidden terminal input for that process only. The launcher does not read .env.local or write the entered key to disk. Live mode uses the optional httpx package; if it is missing, the command prints the exact install instruction.

Ghost remains authoritative over deterministic state and combat resolution; the LLM layers propose opponent intent and narration around that resolved state.

Each demo exercises a different public layer without requiring a cloned repository.

Controlled Benchmark

BENCHMARK_RESULTS.md records a deterministic 42-trial Ghost Revolution benchmark that compares a naive “reports are truth” policy with Ghost's provenance-aware policy under equal two-action budgets.

The benchmark is deliberately narrow. It demonstrates that separating reports, evidence, and belief revision changes actual game decisions and their heat/fear consequences. It is not a claim of general intelligence or a general-purpose truth detector.

Reproduce it with:

python -m ghost.examples.ghost_revolution.benchmarks.epistemic_scenario_matrix_benchmark

Quality Lanes

See QUALITY.md for exact commands.

pytest -q
pytest -q -m performance

Coverage is separated into three maintained branch-coverage lanes:

  • reusable Ghost core;
  • the complete Ghost Revolution package;
  • the Order Coordination reference application.

Performance checks remain uninstrumented so coverage tracing does not distort throughput floors. Fresh human-readable and machine-readable results are published in COVERAGE.md.

Current synchronized release regression:

2,745 passed
1 skipped

Project Layout

ghost/
    api.py
    engine.py
    relationships.py
    emotions.py
    interpretation.py
    attention.py
    salience_bridge.py
    agent.py
    affordances.py
    motives.py
    perception.py
    continuity.py
    continuity_history.py
    continuity_optimization.py
    epistemic.py
    threat_response.py
    combat.py
    objectives.py
    scenario.py
    scenario_runtime.py
    examples/

tests/
    ghost_revolution/
    integration/
    performance/
    property/
    regression/

BENCHMARK_RESULTS.md
QUALITY.md
coverage.core.ini
coverage.revolution.ini
pyproject.toml

Design Guarantees

Ghost is built around:

  • deterministic runtime behavior;
  • explicit mutation;
  • bounded numerical state;
  • validated public inputs;
  • copied public outputs;
  • JSON-safe packet contracts;
  • atomic compound operations;
  • strict snapshot restoration;
  • package-version and schema-version separation;
  • no silent conversion of reports into truth;
  • no arbitrary LLM mutation of authoritative state.

Current Limits

Ghost v1.11.0 is still an alpha package.

Current limitations include:

  • Python is the authoritative implementation;
  • Unreal and Godot adapters do not exist yet;
  • registered agents do not autonomously discover or execute engine-specific actions;
  • host games still own engine-specific execution;
  • Ghost Revolution is a terminal reference demo rather than a finished commercial game;
  • benchmark scenarios are controlled and intentionally narrow.

Roadmap Direction

The v1.11 registered-agent and continuity contracts are engine-neutral foundations. The next integration direction is to test thin Unreal/Godot-facing adapters and measure whether the added continuity state produces better long-horizon NPC consistency than simpler baselines. Host games remain responsible for concrete action execution and presentation.

Development Note

Ghost was designed by Shane Heckathorn and built through an AI-assisted, Android-first development workflow using extensive deterministic tests, audits, backups, and reproducible terminal patches.

The implementation workflow is AI-assisted. The architecture, product direction, state contracts, testing decisions, and acceptance criteria are human-directed.

License

MIT. See the repository license.

Release files for ghocentric-ghost-engine 1.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghocentric-ghost-engine 1.11.0
File Size Uploaded
ghocentric_ghost_engine-1.11.0.tar.gz 504.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ghocentric-ghost-engine 1.11.0
File Interpreter ABI Platform
ghocentric_ghost_engine-1.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 863.5 kB

Release files / ghocentric_ghost_engine-1.11.0.tar.gz

Download URL ghocentric_ghost_engine-1.11.0.tar.gz
Size 504.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9f65f1021ae61b47ec3add4fbad71a594753d8da17e86529d31dd7a5fccfaab0
BLAKE2b-256 checksum
How to use checksums
23f2cc26af1fe7c5bc94e3301a061bbeb15c466038f060fb0765a2830763320b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / ghocentric_ghost_engine-1.11.0-py3-none-any.whl

Download URL ghocentric_ghost_engine-1.11.0-py3-none-any.whl
Size 359.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eacceea81c11f921d5bbceef3e454b6d4994bd006c00c478f390496155ef9e2c
BLAKE2b-256 checksum
How to use checksums
e54d7eaa2d8849a6adcecdc2dcbccb891d714dc079972fd24489b2c4dab9d159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.11.0 This release

2 release files

1.10.0

2 release files

1.9.2

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.5

2 release files

1.7.4

2 release files

1.7.3

2 release files

1.7.2

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page