rlmesh.adapters.ModelSpec

classfrom rlmesh.adapters import ModelSpec[source]

Declarative description of a model's input payload tree and action output.

ModelSpec(input: InputNode, output: Action)

input is a recursive tree whose container type is the payload container the model’s predict receives: a bare leaf (a single tensor/string), a dict[str, subtree], or a tuple of subtrees. A leaf is an Image, State, Concat, Text, or Custom. Placement (tree position) is the payload position – model leaves carry no key, and a role may be reused across leaves (one env camera can feed several input slots).

input

attribute[source]
input: InputNode

The model input tree.

output

attribute[source]
output: Action

Layout of the action vector produced by the model.

to_dict

function[source]
to_dict()

Return a JSON-compatible dict form of this spec.

A CustomEncoding field serializes to a describe/validate schema ({base, ...}): the platform validates its base against an env and shows it, but never runs the arm. An entrypoint arm travels as its module:callable string; an in-process callable arm has no wire form, so it travels as a non-portable <local> marker.

Raises

TypeDescription
ValueErrorIf a custom *input* cannot be serialized (an in-process callable, or an entrypoint custom at the publish boundary).

to_json

function[source]
to_json()

Return this spec serialized as a JSON string.

to_metadata

function[source]
to_metadata()

Return a metadata mapping fragment carrying this spec.

Merge the result into model contract metadata so remote consumers can recover the spec via from_metadata(). Custom inputs (whole opaque host transforms, whether in-process callables or module:callable entrypoints) cannot be published, because a consumer would have to import code from the contract; resolve such a spec locally instead. A custom encoding is different: it publishes as a describe/validate schema ({base, ...}, in-process arms as a <local> marker) that the platform shows and validates against an env but never runs – execution stays where the callable was defined.

Raises

TypeDescription
ValueErrorIf any input is a custom transform (in-process callable or entrypoint); neither can be safely published in v1.

from_dict

function[source]
from_dict(data: Mapping[str, Any])

Build a spec from to_dict() output.

The input is validated and canonicalized by the Rust codec first, so the Python shape readers below operate on already-valid data.

One canonicalization caveat: a Concat with a single parameterized part serializes identically to the equivalent State (the documented wire equivalence), and reads back as that State – so from_dict(spec.to_dict()) can differ from spec by that leaf class alone, with identical wire form and behavior.

from_json

function[source]
from_json(payload: str)

Build a spec from to_json() output.

from_metadata

function[source]
from_metadata(metadata: Mapping[str, Any])

Extract a spec from model contract metadata, or None when absent.

Reads the single v1 metadata key (rlmesh.adapters.v1.model_spec). When a future v2 format lands it ships a new key and reader, restoring a newest-format-first dual read so a newer build still reads an older peer’s v1 spec; that dispatch moves into the Rust codec (the single source of truth) once the PyO3 normalize door lands.