Principle:AIScientists Dev WorldSeed Precondition Evaluation
| Knowledge Sources | |
|---|---|
| Domains | DSL, Validation |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
A registry-based DSL evaluation engine that checks declarative precondition expressions against world state, enabling scene-agnostic rule enforcement without hardcoded entity types or property names.
Description
Preconditions are declarative expressions in scene config YAML that gate whether an action can execute. They use a registry-based dispatch system: each operator (`check`, `exists`, `not`, `all`, `any`) is a handler function registered at module load time. The `evaluate()` function looks up the operator by name and delegates to the handler.
The DSL supports:
- check: Comparison operators (`==`, `!=`, `>`, `<`, `>=`, `<=`) on DSL expressions (e.g., `$entity.quantity`, `$param.amount`)
- exists: Checks if an entity exists
- not: Negates a nested precondition
- all: All nested conditions must pass
- any: At least one nested condition must pass
DSL expressions are resolved by `path_resolver.py`, which handles `$param.*`, `$agent.*`, entity property paths, and arithmetic.
This registry pattern means new precondition operators can be added by creating a handler and calling `register_precondition()` — no changes to the dispatch code.
Usage
Use this principle to enforce action availability rules. Preconditions are evaluated during action validation in `RulesEngine._validate_action()`, during consequence scanning, and during perception visibility filtering.
Theoretical Basis
The evaluation follows a registry-dispatch pattern:
# Abstract dispatch (NOT real implementation)
def evaluate(precondition, store, ctx):
handler = registry.get(precondition.operator)
if handler is None:
raise ValueError(f"Unknown precondition: {precondition.operator}")
return handler(precondition, store, ctx)
# Example: check operator
def _check(precond, store, ctx):
left = resolve(precond.left, store, ctx)
right = resolve(precond.right, store, ctx)
return compare(left, precond.op, right)
The `ctx` dictionary carries evaluation context: `agent_id`, `action_params`, `tick`, `seq`, and optionally `entity` (for per-entity consequence iteration).
Related Pages
Implemented By
- Implementation:AIScientists_Dev_WorldSeed_dsl_preconditions_evaluate
- Implementation:AIScientists_Dev_WorldSeed_RulesEngine
- Implementation:AIScientists_Dev_WorldSeed_aggregation
- Implementation:AIScientists_Dev_WorldSeed_entities_of
- Implementation:AIScientists_Dev_WorldSeed_dsl_events_fns
- Implementation:AIScientists_Dev_WorldSeed_dsl_functions_helpers
- Implementation:AIScientists_Dev_WorldSeed_relationships_fns
- Implementation:AIScientists_Dev_WorldSeed_check_precondition
- Implementation:AIScientists_Dev_WorldSeed_logic_preconditions
- Implementation:AIScientists_Dev_WorldSeed_nested_dict_path_access