World handle¶
| Package | Value |
|---|---|
| Distribution | archetype-ecs |
| Import package | archetype |
Recommended API. Create entities, run simulations, query history, and manage one world.
RuntimeWorld
¶
Operate one world through an ArchetypeRuntime.
Handles are lazy and safe to create before the world exists. The first operation activates the world. The trusted runtime path is actor-free; authorization belongs to remote adapters at the dispatcher ingress boundary.
active_world_id
property
¶
Return the durable identity without activating this lazy handle.
ingest_artifacts
async
¶
Copy files into the artifact store and index their metadata.
spawn_many
async
¶
Create several entities in one batch.
Each entity's first persisted row contains its supplied components. Processors first apply on the following tick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[list[Component]]
|
Component lists, one for each entity. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
A list of entity IDs in the same order as |
spawn_batch
async
¶
Spawn many copies of one component template.
spawn_batch(foo, 10000) is shorthand for building 10,000
component lists and sending them through the existing gated
spawn_many batch path. The template components are deep-copied
per entity so later mutation of one component instance cannot alias
another spawned row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*components_or_count
|
Component | int
|
Component templates, followed by a positional
count; e.g. |
()
|
count
|
int | None
|
Keyword count for multi-component archetypes; e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
list[int]
|
A list of entity IDs in spawn order. |
reserve_ids
async
¶
Reserve entity identifiers without creating entities.
The returned IDs are drawn from the same monotonic counter as
spawn / spawn_many, so interleaved calls produce disjoint
ranges. Use spawn_reserved() to materialize a reserved ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of identifiers to reserve. Must be at least one. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Reserved identifiers in ascending order. |
spawn_reserved
async
¶
Create an entity with a previously reserved identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
int
|
A previously reserved ID (from |
required |
*components
|
Component
|
Initial component values. |
()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If entity_id is already registered. |
run_episode
async
¶
Run until an episode termination condition or step limit is reached.
grade
async
¶
Run graders against this world's append-only history.
Graders receive one lazy Daft DataFrame. Returned values are ephemeral;
use evaluate() when the outcome needs a durable receipt.
evaluate
async
¶
Persist one evaluation result for an evaluation identity.
The receipt is pinned to the current snapshot and grader contract.
Repeating an evaluation identity returns its original receipt without
grading again. Use a new identity for another nondeterministic trial.
Durable receipts require an Iceberg-backed world; use grade() for
ephemeral scoring on other storage backends.
query
async
¶
Return append-only history for entities with the requested components.
The result contains every matching tick, not only current state.
add_hook
async
¶
Install a hook on an active world.
Hooks needed during activation should be passed to runtime.world().