babylon.data.models

Data models for Babylon.

This package re-exports models from the canonical locations: - Entity models are in babylon.models.entities - Database models (SQLAlchemy) are local

For new code, prefer importing directly from babylon.models.

class babylon.data.models.Contradiction(**data)[source]

Bases: BaseModel

Full contradiction model with entities and resolution methods.

This is a more detailed model for contradictions that includes references to entities and resolution mechanics. Used for game content definition.

Parameters:
  • id (str)

  • name (str)

  • description (str)

  • entity_ids (list[str])

  • principal_aspect_id (str | None)

  • secondary_aspect_id (str | None)

  • principal_contradiction_id (str | None)

  • universality (str)

  • particularity (str)

  • antagonism (str)

  • intensity (IntensityLevel)

  • state (str)

  • potential_for_transformation (IntensityLevel)

  • conditions_for_transformation (list[str])

  • resolution_methods (dict[str, list[Effect]])

  • intensity_history (list[Annotated[float, FieldInfo(annotation=NoneType, required=True, description='Contradiction intensity from dormant (0) to rupture (1)', metadata=[Ge(ge=0.0), Le(le=1.0)])]])

id

Unique identifier

name

Human-readable name

description

Detailed explanation

entity_ids

IDs of entities involved in this contradiction

universality

Universal or Particular

particularity

Domain (Economic, Political, etc.)

principal_contradiction_id

ID of the principal contradiction (if this is secondary)

principal_aspect_id

ID of the entity representing the principal aspect

secondary_aspect_id

ID of the entity representing the secondary aspect

antagonism

Primary or Secondary antagonism

intensity

Current intensity level

state

Active, Resolved, or Latent

potential_for_transformation

How likely to transform

conditions_for_transformation

What conditions must be met

resolution_methods

Mapping of method names to Effects

property intensity_value: float

Get numerical value for intensity.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

record_intensity()[source]

Record current intensity in history.

Return type:

None

id: str
name: str
description: str
entity_ids: list[str]
principal_aspect_id: str | None
secondary_aspect_id: str | None
principal_contradiction_id: str | None
universality: str
particularity: str
antagonism: str
intensity: IntensityLevel
state: str
potential_for_transformation: IntensityLevel
conditions_for_transformation: list[str]
resolution_methods: dict[str, list[Effect]]
intensity_history: list[Annotated[float]]
class babylon.data.models.Effect(**data)[source]

Bases: BaseModel

A modification to game state.

Effects are the atoms of change - they modify single attributes on single targets by specific amounts. Every state change in the simulation should be expressible as one or more Effects.

Parameters:
  • target_id (str)

  • attribute (str)

  • operation (Literal['increase', 'decrease', 'set', 'multiply'])

  • magnitude (float)

  • description (str)

target_id

ID of the entity to modify

attribute

Name of the attribute to change

operation

How to modify the value

magnitude

Amount of change (interpretation depends on operation)

description

Human-readable explanation of why this effect occurs

apply_to(current_value)[source]

Calculate the new value after applying this effect.

Parameters:

current_value (float) – The current value of the attribute

Return type:

float

Returns:

The new value after the effect is applied

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

target_id: str
attribute: str
operation: Literal['increase', 'decrease', 'set', 'multiply']
magnitude: float
description: str
class babylon.data.models.Event(**kwargs)[source]

Bases: Base

Represents a game event that can occur based on certain conditions.

Events can have effects, triggers, and consequences.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

apply_effects(game_state)[source]

Apply all effects of this event to the game state.

Parameters:

game_state (dict[str, Any]) – Current game state to modify

Return type:

None

check_triggers(game_state)[source]

Check if this event’s triggers are met in the current game state.

Parameters:

game_state (dict[str, Any]) – Current game state to check against

Returns:

True if all triggers are met, False otherwise

Return type:

bool

consequences: Mapped[list[dict[str, Any]] | None]
description: Mapped[str | None]
effects: Mapped[list[dict[str, Any]] | None]
escalation_paths: Mapped[list[dict[str, Any]] | None]
id: Mapped[int]
name: Mapped[str]
triggers: Mapped[list[dict[str, Any]] | None]
type: Mapped[str | None]
class babylon.data.models.LogEntry(**kwargs)[source]

Bases: Base

SQLAlchemy model for log entries.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

correlation_id: Mapped[str | None]
id: Mapped[int]
level: Mapped[str | None]
message: Mapped[str | None]
module: Mapped[str | None]
timestamp: Mapped[datetime]
class babylon.data.models.Trigger(**data)[source]

Bases: BaseModel

A condition that can trigger game events.

Triggers define when events should occur based on game state. They can have multiple conditions that must all be met (AND logic) or any one met (OR logic).

Parameters:
id

Unique identifier

description

Human-readable description

trigger_type

Category of trigger (economic, political, social, etc.)

conditions

List of conditions to evaluate

logic

How to combine conditions (all must pass or any must pass)

parameters

Optional parameters for condition evaluation

cooldown_turns

Minimum turns between activations (0 = no cooldown)

last_triggered_turn

Turn when this was last triggered

evaluate(game_state, current_turn=0)[source]

Evaluate if the trigger condition is met.

Parameters:
  • game_state (dict[str, Any]) – The current game state to evaluate against

  • current_turn (int) – The current turn number (for cooldown checking)

Return type:

bool

Returns:

True if the trigger condition is met, False otherwise

mark_triggered(current_turn)[source]

Mark this trigger as having been triggered.

Parameters:

current_turn (int) – The current turn number

Return type:

None

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: str
description: str
trigger_type: str | None
conditions: list[TriggerCondition]
logic: Literal['all', 'any']
parameters: dict[str, Any]
cooldown_turns: int
last_triggered_turn: int | None

Modules

event

Event model for handling game events and their effects.

log_entry

Log entry model for database logging.