Implementation:AIScientists Dev WorldSeed relationships fns
| Knowledge Sources | |
|---|---|
| Domains | DSL, Query |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete DSL functions for querying entity relationships — relationships_of and relationship_value — provided by the WorldSeed library.
Description
The relationships module registers the `relationships_of` DSL function, which supports three modes via its argument parser: listing all target IDs from a relationship property (list → IDs, dict → keys), checking a specific target's membership, or retrieving a specific target's value. The underlying `relationships_of(entity_id, rel_type, store)` returns target IDs from a list or dict relationship property, while `relationship_value(entity_id, rel_type, target, store)` gets a specific target's value from a dict or checks membership in a list. The DSL wrapper resolves entity paths and optional `to` and `value` flags from the argument string.
Usage
Use this function in scene YAML DSL expressions when you need to traverse entity relationships — e.g., listing an agent's allies, checking if two entities are connected, or retrieving the strength of a bond.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/dsl/functions/relationships.py
Signature
def relationships_of(entity_id: str, rel_type: str, store: StateStore) -> list[str]:
"""Return target IDs from a relationship property."""
def relationship_value(entity_id: str, rel_type: str, target: str, store: StateStore) -> object:
"""Get a specific relationship target's value, or check membership."""
def _call_relationships_of(args_str: str, store: StateStore, ctx: dict[str, Any]) -> list[str] | object:
"""Parse and call relationships_of(entity_path, type=X[, to=Y[, value]])."""
Import
# Auto-registered on import of the functions package:
# import worldseed.dsl.functions # registers "relationships_of"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| entity_path | str | Yes | DSL path to the source entity |
| type | str | Yes | Relationship property name |
| to | str | No | Target entity to check or retrieve |
| value | flag | No | If present with `to`, return the value instead of membership |
Outputs
| Name | Type | Description |
|---|---|---|
| returns (no `to`) | list[str] | All target IDs from the relationship |
| returns (with `to`, no `value`) | list[str] | `[target]` if member, `[]` otherwise |
| returns (with `to` + `value`) | object | The relationship value or None |
Usage Examples
# List all allies of an agent
preconditions:
- operator: check
left: "length(relationships_of($agent, type='allies'))"
op: ">="
right: 1
# Check if two agents are bonded
preconditions:
- operator: check
left: "length(relationships_of($agent, type='bond', to=$target))"
op: "=="
right: 1
# Get bond strength value
effects:
- operator: set
target: "$agent.bond_strength"
value: "relationships_of($agent, type='bond', to=$target, value)"