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 dsl effects execute

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

Overview

Concrete registry-based DSL effect executor that dispatches state mutation operations by operator name, with conditional `when` clause support, provided by the WorldSeed library.

Description

The execute function in `dsl/effects/__init__.py` is the central effect dispatcher. It looks up the effect's `operator` in a module-level registry and calls the handler with a uniform signature: `(effect, store, event_log, ctx, tick)`.

If the effect has a `when` clause (a `PreconditionConfig`), the effect is skipped when the condition evaluates to false — enabling conditional logic within effect lists.

Registered operators (auto-imported at module load):

  • state_ops: `set`, `increment`, `decrement` — property mutations with min/max bounds
  • entity_ops: `create_entity`, `remove_entity` — lifecycle management
  • event_ops: `emit_event` — event emission with scope, TTL, push, highlight
  • list_ops: `list_append`, `list_remove`, `list_pop_random` — collection manipulation
  • relationship_ops: `add_relationship`, `remove_relationship` — entity graph edges
  • rotate_ops: `rotate` — cyclic sequence advancement
  • for_each_ops: `for_each` — iterate over entities, apply nested effects
  • autoresearch_exec: Scene-specific operator for the autoresearch community

Usage

Import this function to execute DSL effects. Called by `RulesEngine` during action processing, `ConsequenceScanner` during reactive triggers, and `apply_dm_response` during DM application.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/dsl/effects/__init__.py

Signature

def execute(
    effect: EffectConfig,
    store: StateStore,
    event_log: EventLog,
    ctx: dict[str, Any],
    tick: int,
) -> None:
    """Execute a DSL effect operator via registry lookup.

    All handlers receive the same args: (effect, store, event_log, ctx, tick).
    If the effect has a `when` clause, the effect is skipped when the
    condition evaluates to false.
    """

Import

from worldseed.dsl.effects import execute

I/O Contract

Inputs

Name Type Required Description
effect EffectConfig Yes DSL effect with operator, target, value
store StateStore Yes Entity store to mutate
event_log EventLog Yes Event log for emit_event
ctx dict Yes Execution context (agent_id, action_params, tick, seq)
tick int Yes Current tick

Outputs

Name Type Description
(mutation) StateStore Entity properties modified
(mutation) EventLog Events appended for emit_event

Usage Examples

Direct Effect Execution

from worldseed.dsl.effects import execute
from worldseed.models.config_schema import EffectConfig

# Set a property
effect = EffectConfig(operator="set", target="teapot.temperature", value=80)
execute(effect, store, event_log, ctx, tick=1)

# Increment with min bound
effect = EffectConfig(operator="increment", target="counter.count",
                       value=1, min=0)
execute(effect, store, event_log, ctx, tick=1)

# Emit an event
effect = EffectConfig(operator="emit_event", type="move",
                       detail="agent_1 moved to garden", scope="global")
execute(effect, store, event_log, ctx, tick=1)

Conditional Effect

from worldseed.models.config_schema import EffectConfig, PreconditionConfig

# Only execute if agent has enough gold
effect = EffectConfig(
    operator="decrement",
    target="agent.gold",
    value=10,
    min=0,
    when=PreconditionConfig(
        operator="check",
        left="$agent.gold",
        op=">=",
        right="10",
    ),
)
execute(effect, store, event_log, ctx, tick=1)

Related Pages

Implements Principle

Requires Environment

Page Connections

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