Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIScientists Dev WorldSeed TickEngine step async

From Leeroopedia
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):

  1. Phase 0: Apply queued GM entity mutations (tick boundary)
  2. Phase 1: Validate and execute mechanical effects for all queued actions (sequential, sub-millisecond each). DM-pending actions are separated.
  3. 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`.
  4. Phase 3: GM resolve commands (sequential, tick boundary)
  5. 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())

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment