PARACOSM AGENTOS | API Reference v0.9.1202
Home Simulation API Docs GitHub npm
Home Simulation API Docs GitHub npm AgentOS Discord
paracosm - v0.9.1202
    Preparing search index...

    Class SimulationKernel

    Index
    • get yearsPerUnit(): number

      Years in one unit of the run's time. A state saved before units had lengths carries none, and its ages were written as if a unit were a year, so it reads 1.

      Returns number

    • Advance to the next turn. Runs between-turn progression.

      Parameters

      • nextTurn: number
      • nextTime: number
      • OptionalprogressionHook: (ctx: ProgressionHookContext) => void

      Returns SimulationState

    • Apply updates to living people: the featured colonist updates of the department reports, and the memory the reaction step writes. A report's psych score moves the person at most 0.15 toward the value it writes (PSYCH_STEP); its conditions are set as written. A memory write is held by writeMemory; it moves no number the dice read.

      Parameters

      • updates: {
            agentId: string;
            career?: Partial<AgentCareer>;
            health?: Partial<AgentHealth>;
            memory?: AgentMemory;
            narrativeEvent?: string;
        }[]

      Returns void

    • Add each delta to wherever the run holds its key, metrics first, then politics; a key the run holds in neither is dropped. Returns the change each key made.

      Parameters

      • deltas: Record<string, number>

      Returns Record<string, number>

    • Apply a policy effect from the commander's decision: its patches set values outright, then its deltas add to them. Returns the change each delta made, and logs it.

      Parameters

      • effect: PolicyEffect

      Returns Record<string, number>

    • Apply additive deltas to world politics; one for a field the run does not carry is dropped. Returns the change each field made, within the range its scenario declares.

      Parameters

      Returns Record<string, number>

    • Apply additive deltas to world systems (not absolute values). A delta for a metric the run does not carry is dropped. A population delta moves whole people on and off the roster; see movePeople. A morale gain adds in full up to 0.9 and eases above it, so no gain stops at 1 (moraleAfterGain). Returns the change each metric made, which is what the run reports: the delta itself, or less where a floor or ceiling stopped it (power at 0, a hull a scenario keeps at or under 100) or a morale gain eased.

      Parameters

      Returns Record<string, number>

    • Find an agent by an id a model wrote. An exact id wins; otherwise the id is compared with punctuation dropped on both sides, then also without a leading title (see agentIdKeys). A loose match counts only when it names exactly one agent.

      Parameters

      • agentId: string

      Returns Agent | undefined

    • Get top N candidates for a department role, scored by trait fit. The living adults with no department to head: a fork's roster holds the people born since the start, and the score does not read age.

      Parameters

      • dept: string
      • topN: number = 5

      Returns Agent[]

    • Parameters

      • dept: string

      Returns {
          avgBoneDensity: number;
          avgMorale: number;
          avgRadiation: number;
          count: number;
      }

    • Promote a colonist to a department head role. Returns the roster id the promotion resolved to, which can differ from agentId in punctuation or a dropped title.

      Parameters

      • agentId: string
      • dept: string
      • role: string
      • promotedBy: string

      Returns string

    • Capture a KernelSnapshot bundle. The returned object is plain JSON-safe data: JSON.stringify(snap) + JSON.parse + SimulationKernel.fromSnapshot(parsed, scenarioId) round-trips to a new kernel in the same state. Used by WorldModel.snapshot() + fork() for mid-run counterfactuals.

      Parameters

      • scenarioId: string

        Scenario id the snapshot is being taken against. Stamped into the snapshot so fromSnapshot can verify the target WorldModel's scenario matches.

      Returns KernelSnapshot

    • Reverse of SimulationKernel.toSnapshot. Constructs a fresh kernel positioned at the snapshot's turn, with simulation state + PRNG state + metadata fully restored. The returned kernel is indistinguishable from the one that produced the snapshot as far as subsequent advanceTurn calls are concerned.

      Parameters

      • snap: KernelSnapshot

        The captured snapshot.

      • expectedScenarioId: string

        Scenario id the caller expects the snapshot to match. Throws when they differ; this is the gate against accidental cross-scenario forks.

      • Optionalscenario: ScenarioPackage

        The scenario the kernel goes on running, for its declared floors and ceilings, which a snapshot does not hold. Without it the restored kernel keeps only its built-in ones.

      Returns SimulationKernel

      Error when snap.snapshotVersion !== 1 or when snap.scenarioId !== expectedScenarioId.