Implementation:AIScientists Dev WorldSeed logic preconditions
| Knowledge Sources | |
|---|---|
| Domains | DSL, Simulation |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete DSL precondition operators for logical composition — exists, not, all, any — provided by the WorldSeed library.
Description
The logic module registers four precondition operators: `exists` checks if an expression resolves to a truthy value (empty lists/strings are falsy); `not` negates a single nested condition; `all` requires all nested conditions to be true (empty = True, vacuous truth); `any` requires at least one nested condition to be true (empty = False). The `not`/`all`/`any` operators import `evaluate` lazily from the preconditions `__init__` to avoid circular imports, and each delegates to the dispatcher for nested condition evaluation.
Usage
Use these operators in scene YAML preconditions to compose boolean logic — e.g., requiring an entity to exist, negating a guard, or combining multiple conditions with AND/OR semantics.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/dsl/preconditions/logic.py
Signature
def _eval_exists(p: PreconditionConfig, store: StateStore, ctx: dict[str, Any]) -> bool:
"""Check if expression resolves to a truthy value."""
def _eval_not(p: PreconditionConfig, store: StateStore, ctx: dict[str, Any]) -> bool:
"""Negate a nested condition."""
def _eval_all(p: PreconditionConfig, store: StateStore, ctx: dict[str, Any]) -> bool:
"""All conditions must be true (AND). Empty = True."""
def _eval_any(p: PreconditionConfig, store: StateStore, ctx: dict[str, Any]) -> bool:
"""At least one condition must be true (OR). Empty = False."""
Import
# Auto-registered on import of the preconditions package:
# import worldseed.dsl.preconditions # registers "exists", "not", "all", "any"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| p.expression | str | Yes (exists) | DSL expression to resolve and check truthiness |
| p.condition | PreconditionConfig | No (not) | Single nested condition to negate |
| p.conditions | list[PreconditionConfig] | Yes (all/any) | List of nested conditions |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | bool | Result of the logical evaluation |
Usage Examples
# Entity must exist
preconditions:
- operator: exists
expression: "game.current_quest"
# NOT: agent must not be frozen
preconditions:
- operator: not
condition:
operator: check
left: "$agent.status"
op: "=="
right: "'frozen'"
# ALL: must have gold AND be in town
preconditions:
- operator: all
conditions:
- { operator: check, left: "$agent.gold", op: ">=", right: 10 }
- { operator: check, left: "$agent.location", op: "==", right: "'town'" }
# ANY: must be in town OR market
preconditions:
- operator: any
conditions:
- { operator: check, left: "$agent.location", op: "==", right: "'town'" }
- { operator: check, left: "$agent.location", op: "==", right: "'market'" }