World handle¶
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. A handle also carries the identity used for
authorization; as_actor() creates another view with a different
identity while sharing the same world lifecycle.
ingest
async
¶
Persist an external fact exactly once per external identity.
Facts become durable immediately and do not join the active simulation. Repeating an identity with the same payload returns the original receipt; repeating it with a different payload raises an error.
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.
autoresearch
async
¶
Run an autoresearch loop with this world as the base save state.
Each iteration prepares an optional candidate, runs a rollout, and
compares its score with the persisted incumbent. This base world is
never mutated. Reusing config.experiment_id resumes the loop, and
episode worlds remain available for inspection by default.
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 receipt 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.
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().