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 RulesEngine

From Leeroopedia
Knowledge Sources
Domains Simulation, Validation
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete tool for validating and executing actions against scene config rules, including preconditions, blocking checks, mechanical effects, and DM intent separation.

Description

The RulesEngine processes actions through a validation pipeline: lookup action config, check blocking actions, verify `available_to` filter, validate non-negative number params, evaluate preconditions, then execute mechanical effects and events. Actions requiring DM are separated for async resolution.

Key methods:

  • _validate_action: Shared validation returning `(error_result, ctx)` tuple
  • process_action: Sync action processing (DM skipped)
  • process_mechanical: Async Phase 1 — validate + execute, returns DM intent info
  • resolve_dm_async: Async Phase 2 — resolve DM judgment
  • process_auto_tick: Execute auto_tick effects each tick

Usage

Import this class when building a custom tick engine. In production, it's created by `TickEngine.__init__()` and called during tick processing.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/engine/rules_engine.py

Signature

class RulesEngine:
    def __init__(
        self,
        config: SceneConfig,
        store: StateStore,
        event_log: EventLog,
        dm_provider: DMProvider | None = None,
        dm_builder: DMContextBuilder | None = None,
        recorder: RunRecorder | NullRecorder | None = None,
        inbox_manager: InboxManager | None = None,
    ) -> None: ...

    def _validate_action(
        self, action: ActionSubmission, tick: int,
    ) -> tuple[ActionResult | None, dict[str, Any] | None]: ...

    def process_action(self, action: ActionSubmission, tick: int) -> ActionResult: ...

    async def process_mechanical(
        self, action: ActionSubmission, tick: int,
    ) -> tuple[ActionResult, dict[str, Any] | None]: ...

    async def resolve_dm_async(self, dm_info: dict[str, Any]) -> None: ...

    def process_auto_tick(self, tick: int) -> None: ...

@dataclass
class ActionResult:
    success: bool
    action: ActionSubmission
    reason: str = ""

Import

from worldseed.engine.rules_engine import RulesEngine, ActionResult

I/O Contract

Inputs

Name Type Required Description
action ActionSubmission Yes Action to process
tick int Yes Current tick number

Outputs

Name Type Description
process_action() returns ActionResult Success/failure with reason
process_mechanical() returns None) Result + DM intent if action needs DM

Usage Examples

from worldseed.engine.rules_engine import RulesEngine
from worldseed.models.action import ActionSubmission

rules = RulesEngine(config, store, event_log)

# Process a mechanical action (sync)
action = ActionSubmission(agent_id="agent_1", action_type="move",
                           params={"target": "garden"}, tick_submitted=0)
result = rules.process_action(action, tick=1)
# result.success == True

# Process with async DM support
result, dm_info = await rules.process_mechanical(action, tick=1)
if dm_info is not None:
    await rules.resolve_dm_async(dm_info)

Related Pages

Implements Principle

Requires Environment

Page Connections

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