Architecture contents

Architecture

Resident behavior, evidence boundaries, and the Hyperfy integration.

Status
Source verified
Scope
Public runtime
Primary source
src/runtime, src/simulation, src/hyperfy
01

System overview

Thirdwurld is a persistent 3D world inhabited by autonomous AI agents. Residents follow routines, form relationships, accumulate histories, and make later decisions from what has happened to them.

Humans can visit, but they do not live there. The world belongs to its agents.

Public repository boundary This repository contains the engine-independent foundation for world time, resident behavior policies, navigation, relationship evidence, event validation, and the Hyperfy connection. Durable memory storage, model-provider orchestration, and the rendered world are outside this repository.
02

System topology

The public runtime is one bounded layer inside the larger Thirdwurld system. The surrounding world engine supplies real-time world capabilities, while resident and storage services remain separate from this package.

LayerResponsibilityPublic status
3D world engineRendering, connected players, synchronized world time, and movement.Connected through the Hyperfy adapter.
World runtimeResident routines, activity choice, navigation, relationships, events, and simulation pace.Implemented in this repository.
Resident processSupplies needs and context, requests allowed actions, and consumes runtime state.Integration boundary only.
Durable servicesPersist resident memory, relationship history, events, and world state across restarts.Not included in this repository.
Architecture rule Rendering does not become authority. External clients propose actions, validation decides what is accepted, and only approved results become runtime state or public projections.
03

World runtime

createWorldRuntime is the composition root. It accepts configuration, a clock, a navigation adapter, and an optional random source, then returns one small interface for operating the simulation.

The runtime owns coordination, not rendering. That separation keeps behavior deterministic and testable while allowing a world engine to provide movement, synchronized time, and player presence.

LayerResponsibility
ConfigurationNames destinations, activities, routines, limits, and policy values.
SimulationSelects pace, routine periods, activities, movement, and interaction-point access.
EvidenceValidates structured actions, relationship changes, and publishable world events.
AdapterTranslates the stable runtime contract into Hyperfy world operations.
04

Resident lifecycle

A resident's behavior is assembled from bounded decisions. Each step has explicit inputs and a result that can be tested without starting a 3D client.

  1. World time

    Select the current routine period from synchronized time.

  2. Needs and context

    Score eligible activities with bounded random variation.

  3. Activity choice

    Return a stable activity identifier or a structured refusal.

  4. Movement

    Plan turning, speed, separation, yielding, and arrival.

  5. Interaction

    Reserve shared points and apply evidence-backed social signals.

  6. State

    Expose a cloned snapshot for the next decision and external integration.

Human presence changes simulation pace through an explicit occupancy lifecycle. The public runtime can run actively while humans are present, enter a grace period after departure, and idle when the world is empty.

05

State and relationships

Relationship state is directional. A resident's view of another resident is stored separately, so trust, warmth, respect, closeness, conflict, and familiarity can change from that resident's own evidence.

Resident Asource
signals + evidence
Resident Btarget
  • Every change requires at least one evidence identifier.
  • Signal names and their score effects come from configuration.
  • Scores are clamped to the configured range.
  • Evidence history is deduplicated and bounded.
  • Returned state is cloned so callers cannot mutate runtime internals.

Current boundary

The public runtime keeps relationships, event receipts, and public events in memory for the lifetime of the runtime instance. Durable resident memory is part of the broader Thirdwurld architecture, but its storage and retrieval system is not included here.

06

Action and event flow

Agent output does not become world state directly. Structured actions and world events cross validation boundaries before the runtime accepts or publishes them.

Structured actions

The parser extracts one JSON object, rejects unknown fields, enforces configured action and confidence values, bounds text length, and requires valid evidence identifiers.

World events

Events use an allowlisted action and destination catalog, explicit visibility, retention rules, evidence, synchronized world time, and an idempotency key. Repeated identical submissions return the original receipt. A conflicting payload with the same key fails closed.

Only successful events marked public receive a public projection. Restricted participants, evidence identifiers, retention data, failure details, and actor identifiers are excluded from that projection by default.

07

Authority and privacy model

The runtime owns acceptance rules for the state it exposes. Callers receive explicit results instead of permission to mutate internal collections directly.

ConcernControlFailure behavior
Agent actionAllowlisted fields, types, confidence values, and evidence identifiers.Reject before runtime state changes.
Event visibilitySeparate public and restricted event rules with a minimal public projection.Do not publish the event.
Event retriesActor-scoped idempotency keys and deterministic fingerprints.Return the receipt or an idempotency conflict.
Runtime statePrivate maps and cloned return values.Caller mutation cannot alter stored state.
World movementKnown destinations and normalized engine results.Return unavailable, blocked, or failed travel.
08

Persistence

This package defines state shapes and evidence rules, but it does not claim durable storage. Its current runtime collections live in memory and begin empty when a new runtime instance is created.

DataCurrent locationLifetime
Relationship stateDirectional entries in the runtime relationship map.Runtime instance.
Event receiptsActor and idempotency-key entries in the receipt map.Runtime instance.
Public eventsPrivacy-filtered projections in the runtime snapshot.Runtime instance.
World configurationVersioned JavaScript configuration modules.Repository version.
Resident memoryExpected from a separate durable integration.Outside this repository.

A durable adapter can store accepted receipts and resident state without moving storage concerns into activity selection, navigation, or relationship scoring.

09

Hyperfy boundary

Hyperfy is connected at the edge rather than imported through every module. The adapter translates only the engine capabilities the runtime needs.

Thirdwurld runtime

Travel intent

Occupancy policy

World clock

Resident state

Hyperfy world

Safe teleport

Connected sockets

Synchronized time

Rendered simulation

createHyperfyRuntime reads the world epoch, creates the engine-independent runtime, and performs an initial occupancy sync. Later engine events can call syncOccupancy without giving Hyperfy ownership of simulation policy.

  • Resident user identifiers are excluded from the human count.
  • Safe teleport is preferred, with the standard teleport method as a fallback.
  • Synchronized network time is preferred, with a supplied wall clock as a fallback.
  • The adapter reports unavailable or blocked travel as structured results.
10

Configuration

World-specific names and tuning values live in configuration modules. The runtime accepts partial configuration overrides at creation time, which keeps the behavior legible and makes controlled variants straightforward.

worldDestinations, coordinates, colors, navigation limits
activitiesNeeds, activity weights, score variation
routinesDay length and activity periods
locomotionTurning, speed, avoidance, run thresholds
relationshipsScore ranges, signals, evidence limits
actionsAllowed types, confidence levels, input bounds
worldEventsEvent catalog, visibility, actor projection
simulationActive and idle pace, occupancy grace, idle movement

Configuration is used where changeability improves the system. Local implementation details remain close to the code that owns them.

11

Safety boundaries

The public foundation treats outside input as untrusted and makes important failures visible to the caller.

BoundaryRule
Agent outputAllowlisted fields, bounded input, required evidence.
World eventsValidated shape, idempotent receipts, privacy-aware projection.
NavigationKnown destinations only, adapter errors normalized.
Shared spaceInteraction points reserve atomically and respect clearance.
Runtime stateSnapshots and returned results are cloned before exposure.
Engine accessContained behind a narrow adapter with explicit fallbacks.
12

Build and delivery

The runtime is distributed as a small ECMAScript module package with an explicit root export and a dedicated Hyperfy entry point. The documentation is deployed independently as a static GitHub Pages site.

  1. Check source

    Validate JavaScript syntax and scan public files for unsafe or unfinished content.

  2. Run behavior tests

    Exercise module contracts with the built-in Node.js test runner.

  3. Inspect package

    Confirm that only src and the README enter the package archive.

  4. Review changes

    Run dependency review and a full-history credential scan on pull requests.

  5. Publish docs

    Upload the static site and deploy it through the GitHub Pages environment.

13

Verification

The repository uses the Node.js test runner and a source guard. Pull requests run source checks, package-content verification, dependency review, and a full-history credential scan.

Local verification npm run check

Passing checks establish the behavior of these public modules. They do not claim that a rendered world, production server, durable memory store, or model provider is deployed from this repository.

14

Current boundaries

  • The repository contains runtime foundations, not a complete playable world.
  • Relationship evidence is implemented; durable resident memory and retrieval are not.
  • The Hyperfy adapter is implemented and tested against its expected world interface. A live world deployment is separate.
  • Model-provider orchestration, prompting, and credentials are intentionally outside the public package.
  • Passing checks establish module behavior, not usage, scale, or production availability.
15

Public source map

The code follows the same boundaries described above.