Implementation:AIScientists Dev WorldSeed WorldEngine
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Agent_Systems |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete top-level facade for loading scene config, registering agents, submitting actions, stepping ticks, delivering perception, and persisting state — coordinating all engine subsystems through a single entry point.
Description
The WorldEngine class is the central orchestrator of WorldSeed. It delegates to specialized components — `StateStore` for entity CRUD, `EventLog` for events, `TickEngine` for tick orchestration, `AgentRegistry` for agent lifecycle, `DirectorRuntime` for attention signals, `Perceiver` for perception delivery, and `RunRecorder` for persistence.
WorldEngine is used in multiple contexts:
- World initialization: Load config, populate entities, setup narrator
- Agent registration: Create agent entities and profiles
- Action submission: Mechanical actions execute immediately; DM actions queue
- Tick stepping: Advance simulation via `step_async()`
- Perception: Agents perceive the world via `perceive()`
- Director signals: External agents observe and resolve via the director facade
- State persistence: Save/resume via `save_state()` / `load_state()`
Usage
- World lifecycle: Construct with a config path or pre-loaded `SceneConfig`, optionally with a `DMProvider` and `RunRecorder`.
- Agent registration: Call `register_agent()` for each agent entering the world.
- Action submission: Call `submit()` with agent_id, action_type, and params.
- Tick stepping: Call `step_async()` to advance one tick.
- Perception: Call `perceive(agent_id)` for an agent's view.
- Director signals: Call `peek_director_signals()`, `ack_director_signal()`, `resolve_director_dm_request()`.
- Pause/resume: Call `save_state()` then `load_state()`.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/world.py
Signature
class WorldEngine:
def __init__(
self,
config_path: str | Path | None = None,
dm_provider: DMProvider | None = None,
*,
config: SceneConfig | None = None,
recorder: RunRecorder | NullRecorder | None = None,
language: str = "",
) -> None: ...
def register_agent(
self,
agent_id: str,
properties: dict[str, Any] | None = None,
character: dict[str, Any] | None = None,
*,
omniscient: bool = False,
system: bool = False,
wake_on_push: bool = True,
) -> None: ...
def submit(
self,
agent_id: str,
action_type: str,
params: dict[str, Any] | None = None,
) -> str | ActionResult | None: ...
async def step_async(self) -> list[ActionResult]: ...
def perceive(self, agent_id: str) -> AgentPerception: ...
def resolve_director_dm_request(
self,
request_id: str,
narrative: str,
effects_raw: list[dict[str, Any]],
) -> tuple[bool, str]: ...
def save_state(self) -> None: ...
def load_state(
self,
entities: list[dict[str, Any]],
tick: int,
*,
characters: dict[str, dict[str, Any]] | None = None,
) -> None: ...
Import
from worldseed.world import WorldEngine
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config_path | Path | No | Path to scene YAML file |
| config | SceneConfig | No | Pre-loaded scene config (alternative to config_path) |
| dm_provider | DMProvider | No | Async DM judge provider |
| recorder | NullRecorder | No | Persistence recorder (defaults to NullRecorder) |
| language | str | No | ISO language code for DM prompts |
Outputs
| Name | Type | Description |
|---|---|---|
| self.state | StateStore | In-memory entity store |
| self.event_log | EventLog | Event log with TTL |
| self.registry | AgentRegistry | Agent lifecycle + profiles |
| step_async() returns | list[ActionResult] | Results of each processed action |
| perceive() returns | AgentPerception | Typed perception for an agent |
Usage Examples
Basic World Launch
from worldseed.world import WorldEngine
from worldseed.persistence import RunRecorder
# 1. Create engine from config
recorder = RunRecorder(
run_id="run_001",
config_path=Path("configs/teahouse.yaml"),
scene_id="teahouse",
dm_model="gpt-4o",
)
engine = WorldEngine(
config_path="configs/teahouse.yaml",
recorder=recorder,
)
# 2. Register agents (or wait for external registration)
engine.prepopulate_agents()
# 3. Step ticks
import asyncio
results = asyncio.run(engine.step_async())
# 4. Agents perceive
perception = engine.perceive("agent_1")
# 5. Save state for pause/resume
engine.save_state()
With DM Provider
from worldseed.dm.providers.llm import LiteLLMDMProvider
dm = LiteLLMDMProvider(model="openai/gpt-4o", timeout=15.0)
engine = WorldEngine(
config_path="configs/teahouse.yaml",
dm_provider=dm,
language="en",
)
Director Signal Resolution
# External DM resolves a pending request
ok, reason = engine.resolve_director_dm_request(
request_id="abc123",
narrative="The tea was perfectly brewed.",
effects_raw=[
{"operator": "set", "target": "teapot.temperature", "value": 80},
],
)
Related Pages
Implements Principle
- Principle:AIScientists_Dev_WorldSeed_World_Population
- Principle:AIScientists_Dev_WorldSeed_Agent_Registration
- Principle:AIScientists_Dev_WorldSeed_Tick_Execution