reconstruct_model_object

Source:

Local role: Module-level factory function that reconstructs any ModelObject subclass from its canonical serialized dict.

Big-picture role: Single deserialization entry point used by WorldModelRegistry.from_dict and by AuthorityCommandHandler when replaying serialized state.

Signature:

def reconstruct_model_object(
    raw_object: Mapping[str, Any],
    object_factories: Optional[Mapping[str, ObjectFactory]] = None,
) -> ModelObject

Parameters:

  • raw_object — canonical serialized dict; must contain an "object_type" key matching one of the registered factory keys (case-insensitive)
  • object_factories — optional caller-supplied overrides; merged on top of the default factory table so custom types extend rather than replace the defaults

Default factory table (object_type → class):

object_typeClass
"action"Action
"actor"Actor
"goal"Goal
"generic"GenericObject
"resource"Resource
"space"Space
"strategy"Strategy
"world"World

Notes:

  • Default factories are built once and cached at module level (_DEFAULT_FACTORIES); the cache is initialized lazily to avoid circular import issues.
  • Unknown object_type values fall back to ModelObject.from_dict.
  • When object_factories is provided a shallow copy of the default table is taken so the cache is never mutated.

See also:

Ometeotl

A Python library to build complex multi-agent simulations, wargames, and AI-driven strategies