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 helpers

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

Overview

Concrete helper utilities for DSL effect operators, providing target parsing, entity reference resolution, and template interpolation provided by the WorldSeed library.

Description

The _helpers module supplies three core utilities used by every effect operator: `parse_target` splits an `entity.property` dot-path into `(entity_id, prop_path)` after resolving `$param` references; `resolve_entity_ref` maps a `$param` or bare ID to an entity ID string; and `interpolate` performs two-pass string template substitution — first resolving `$entity.property` paths via the state store, then resolving remaining `$param` references. The two-pass ordering is critical: `$entity.votes_received` must resolve as a whole path before `$entity` alone is replaced with the entity ID.

Usage

Import these helpers when implementing a new DSL effect operator that needs to resolve targets, entity references, or string templates against the current execution context.

Code Reference

Source Location

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

Signature

def parse_target(target: str, store: StateStore, ctx: dict[str, Any]) -> tuple[str, str]:
    """Parse 'entity.key' into (entity_id, prop_dotpath). Resolves $param refs."""

def resolve_entity_ref(value: str | None, ctx: dict[str, Any]) -> str | None:
    """Resolve a $param or bare entity_id to an entity_id string."""

def get_entity_or_warn(store: StateStore, entity_id: str, operator: str) -> Entity | None:
    """Get an entity from store, logging a warning if not found."""

def interpolate(template: str, ctx: dict[str, Any], store: StateStore | None = None) -> str:
    """Replace $references in a string template (two-pass: entity paths then params)."""

Import

from worldseed.dsl.effects._helpers import parse_target, resolve_entity_ref, get_entity_or_warn, interpolate

I/O Contract

Inputs

Name Type Required Description
target str Yes Dot-path like `entity.key` or `$param.key`
store StateStore Yes In-memory entity store
ctx dict[str, Any] Yes Execution context with $param values
template str Yes (interpolate) String with $references to substitute

Outputs

Name Type Description
parse_target returns tuple[str, str] (entity_id, prop_dotpath)
resolve_entity_ref returns None Resolved entity ID or None
interpolate returns str Template with all $references replaced

Usage Examples

from worldseed.dsl.effects._helpers import parse_target, interpolate

# Parse a target with $param reference
entity_id, prop_path = parse_target("$agent.location", store, ctx)
# entity_id = "old_chen", prop_path = "location"

# Interpolate a template with entity path + param
result = interpolate("$entity.votes_received votes for $agent", ctx, store)
# First pass: $entity.votes_received → 5
# Second pass: $agent → "old_chen"
# result = "5 votes for old_chen"

Related Pages

Implements Principle

Requires Environment

Page Connections

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