Implementation:AIScientists Dev WorldSeed check precondition
| 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"