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 check precondition

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

Overview

Concrete DSL precondition operator for comparison-based checks (==, !=, >, <, >=, <=, in, contains), provided by the WorldSeed library.

Description

The check precondition operator registers via `register_precondition("check", _eval_check)`. It resolves both `left` and `right` operands via the DSL path resolver, then applies the comparison operator. Numeric comparisons (`>`, `<`, `>=`, `<=`) use `_safe_compare`, which returns `False` on `None` or type errors rather than raising. The `in` operator tests membership of left in a list right; `contains` tests membership of right in a list left.

Usage

Use this operator in scene YAML preconditions to gate actions on state comparisons — e.g., requiring a minimum resource count, checking equality, or testing list membership.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/dsl/preconditions/check.py

Signature

def _eval_check(p: PreconditionConfig, store: StateStore, ctx: dict[str, Any]) -> bool:
    """Evaluate check: left op right."""

def _safe_compare(left: Any, right: Any, op: str) -> bool:
    """Numeric comparison that returns False on None/type errors."""

Import

# Auto-registered on import of the preconditions package:
# import worldseed.dsl.preconditions  # registers "check" operator

I/O Contract

Inputs

Name Type Required Description
p.left str Yes DSL expression for left operand
p.op str Yes One of: ==, !=, >, <, >=, <=, in, contains
p.right str Yes DSL expression for right operand

Outputs

Name Type Description
returns bool Result of the comparison

Usage Examples

# Require minimum gold
preconditions:
  - operator: check
    left: "$agent.gold"
    op: ">="
    right: 10

# Check list membership
preconditions:
  - operator: check
    left: "$agent.location"
    op: "in"
    right: "['town', 'market']"

# Check if agent's inventory contains an item
preconditions:
  - operator: check
    left: "$agent.inventory"
    op: "contains"
    right: "key"

Related Pages

Implements Principle

Requires Environment

Page Connections

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