Implementation:AIScientists Dev WorldSeed TickEngine step async
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Concurrency |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for advancing the simulation by one tick with async DM support, processing actions in phases: mechanical effects, parallel DM resolution, GM commands, consequences, perception, and persistence.
Description
The TickEngine.step_async() method is the core tick processing loop. It is structured in phases to balance correctness (sequential mechanical effects) with performance (parallel DM calls):
- Phase 0: Apply queued GM entity mutations (tick boundary)
- Phase 1: Validate and execute mechanical effects for all queued actions (sequential, sub-millisecond each). DM-pending actions are separated.
- Phase 2: DM resolution — in signal mode, DM intents are handed to the director queue. Otherwise, DM calls are grouped by target entity and resolved in parallel via `asyncio.gather`. Rate-limited to `MAX_DM_CALLS_PER_TICK = 10` and budget-constrained by `max_dm_calls`.
- Phase 3: GM resolve commands (sequential, tick boundary)
- Post-actions: Auto-tick effects, consequence scanning (cascade up to 10 passes), highlight scanning, perception delivery, EventLog cleanup, state persistence.
The engine also has a sync `step()` method that skips DM calls (used in tests and sanity checks).
Usage
Import this method via `WorldEngine.step_async()`. The background tick runner calls it in a loop when auto-tick is enabled.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/engine/tick.py
Signature
class TickEngine:
async def step_async(self) -> list[ActionResult]:
"""Process one tick with async DM support.
Three phases:
1. All mechanical effects (sequential, fast)
2. All DM calls (parallel — same tick snapshot)
3. DM results applied (sequential — causal order)
"""
def step(self) -> list[ActionResult]:
"""Process one tick (sync — DM calls skipped)."""
Import
from worldseed.engine.tick import TickEngine
# Or via WorldEngine:
# engine.step_async()
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (internal) | ActionQueue | Queued actions from previous tick | |
| (internal) | StateStore | Current world state | |
| (internal) | EventLog | Event log |
Outputs
| Name | Type | Description |
|---|---|---|
| return | list[ActionResult] | Results of each processed action |
| (mutation) | StateStore | State mutated via effects |
| (mutation) | InboxManager | Perception delivered to agent inboxes |
| (mutation) | RunRecorder | State persisted to disk |
Usage Examples
Basic Tick Stepping
import asyncio
from worldseed.world import WorldEngine
engine = WorldEngine(config_path="configs/teahouse.yaml")
# Step one tick
results = asyncio.run(engine.step_async())
print(f"Tick {engine.tick}: {len(results)} actions processed")
# Step multiple ticks
for _ in range(10):
results = asyncio.run(engine.step_async())
With DM Actions
from worldseed.dm.providers.llm import LiteLLMDMProvider
dm = LiteLLMDMProvider(model="openai/gpt-4o")
engine = WorldEngine(config_path="configs/teahouse.yaml", dm_provider=dm)
# Submit a DM action (queued for next tick)
engine.submit("agent_1", "persuade", {"target": "agent_2", "argument": "..."})
# Step tick — DM action resolved in parallel
results = asyncio.run(engine.step_async())