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 preconditions evaluate

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

Overview

Concrete registry-based DSL precondition evaluator that dispatches declarative condition expressions by operator name, resolving entity paths and arithmetic via the DSL path resolver.

Description

The evaluate function in `dsl/preconditions/__init__.py` dispatches precondition evaluation by operator. Each operator is a handler function registered at module load time.

Registered operators:

  • check: Comparison (`==`, `!=`, `>`, `<`, `>=`, `<=`) on DSL expressions. Uses `_safe_compare` for type-flexible comparison.
  • exists: Checks if an entity exists in the StateStore.
  • not: Negates a nested `condition` precondition.
  • all: All nested `conditions` must pass.
  • any: At least one nested `condition` must pass.

DSL expressions (like `$entity.quantity`, `$param.amount`, `$agent.health`) are resolved by `path_resolver.py`, which handles `$param.*`, `$agent.*`, entity property paths, and arithmetic operations.

Usage

Import this function to evaluate preconditions. Called by `RulesEngine._validate_action()`, `ConsequenceScanner`, `Perceiver` visibility filtering, and effect `when` clauses.

Code Reference

Source Location

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

Signature

def evaluate(
    precondition: PreconditionConfig,
    store: StateStore,
    ctx: dict[str, Any],
) -> bool:
    """Evaluate a precondition, dispatching by operator."""

Import

from worldseed.dsl.preconditions import evaluate

I/O Contract

Inputs

Name Type Required Description
precondition PreconditionConfig Yes DSL precondition with operator and fields
store StateStore Yes Entity store for path resolution
ctx dict Yes Evaluation context (agent_id, action_params, tick, entity)

Outputs

Name Type Description
return bool True if precondition passes

Usage Examples

from worldseed.dsl.preconditions import evaluate
from worldseed.models.config_schema import PreconditionConfig

ctx = {"agent_id": "agent_1", "action_params": {"target": "teapot"},
       "tick": 1}

# Check comparison
precond = PreconditionConfig(
    operator="check", left="$target.quantity", op=">", right="0"
)
if evaluate(precond, store, ctx):
    print("Target has quantity > 0")

# Check existence
precond = PreconditionConfig(
    operator="exists", expression="$param.target"
)
if evaluate(precond, store, ctx):
    print("Target entity exists")

# All conditions
precond = PreconditionConfig(
    operator="all",
    conditions=[
        PreconditionConfig(operator="check", left="$agent.gold", op=">=", right="10"),
        PreconditionConfig(operator="check", left="$agent.energy", op=">", right="0"),
    ]
)
if evaluate(precond, store, ctx):
    print("Can afford and has energy")

Related Pages

Implements Principle

Requires Environment

Page Connections

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