rlmesh
RLMesh Python SDK.
import rlmeshThe top-level package holds the entry points: serve an environment, connect to one, run a model against it, and record what happened. The classes here keep RLMesh-native values; the value backends re-export the same names with NumPy, Torch, or JAX decoding.
Serve and connect
EnvServer owns one environment and exposes it as an endpoint.
Pass a vectorized env (one with num_envs and single_observation_space) and it serves a vector
endpoint; otherwise a single one. It inspects the env once and caches the
EnvContract that every client receives in the handshake.
import rlmesh
server = rlmesh.EnvServer(env, "127.0.0.1:5555")
print(server.env_contract.observation_space.kind)
server.serve()
A client needs only the address: RemoteEnv for single endpoints,
RemoteVectorEnv for vector ones. Both expose reset,
step, render, and close, and build observation_space / action_space from the contract, so
the client never needs a local copy of the env. render() returns None when the env produces no
frame.
When RLMesh serves an env through its bootstrap entrypoint (inside a sandbox container, for example), the bind address comes from the environment:
| Variable | Meaning |
|---|---|
RLMESH_ADDRESS |
Full bind address (host:port, port, tcp://host:port, unix:///...). Wins when set. |
RLMESH_PORT |
Port-only fallback on 0.0.0.0, used when RLMESH_ADDRESS is unset (default 50051). |
Constructing EnvServer yourself ignores both; pass the address explicitly. The transport is
plaintext gRPC and unauthenticated unless a bearer token is configured, so bind 0.0.0.0 only on a
trusted network (exposure and authentication).
Models
Model wraps a prediction function, or you subclass it and implement
load() plus one of the four predict corners (predict, predict_chunk, predict_batch,
predict_chunk_batch); the runtime derives the rest. A model does not have to live in your process:
RemoteModel dials a policy that is already served, and
SandboxModel runs a prebuilt image:// tag in its own
container. The Models guide and Model Reference
cover the corner contract.
Run and evaluate
run() binds a model to an env and pumps whole episodes, returning a
RunResult. session() hands back a
Session you drive by hand with reset / predict / step.
env = rlmesh.RemoteEnv("127.0.0.1:5555")
result = rlmesh.run(model, env, seeds=range(10))
print(result.episodes[0].reward)
Two sentinels change what they do. NO_ADAPTER as a model’s
spec skips adapter resolution, so the model handles raw env values itself.
RANDOM_SAMPLE as the model samples the action space each step:
a random baseline with no spec involved.
Recorder accumulates one or more runs and exports a portable
rlmesh.result.v1 bundle.
Sandboxes
SandboxEnv and
SandboxVectorEnv build or pull an env image, start the
container, connect a client to it, and stop the container on close. Reach for them when an env needs
its own dependencies and process. SandboxBuild groups the
build settings for a gym:// or hf:// source; SandboxRuntime
groups the docker run flags. See Sandboxed Environments.
Error handling
RLMeshException is the base of every RLMesh error and
subclasses RuntimeError, so one except rlmesh.RLMeshException catches them all.
EnvironmentException is raised when an endpoint fails a
reset, step, or render. Transport faults, timeouts, and bad arguments raise the standard
ConnectionError, TimeoutError, and ValueError instead. Troubleshooting
maps each failure to its cause.
Classes
- BuildInfoThe identity of this build of the native core: package version, protocol generation, the workflow edition it advertises, and how that edition was spelled.
- EnvFactoryAuthoring base that *builds* environment(s): set
tagsand implementmake. - EnvServerServes an RLMesh-compatible environment.
- EpisodeResultThe outcome of one evaluation episode.
- ModelDependency-free model over RLMesh-native values.
- ParamExperimentalOne declared construction parameter -- validated, presentable, sweepable.
- ParamSpecExperimentalA factory's/model's declared construction-parameter surface.
- ReaderA resolved, role-addressed read over an env's observations (read-only).
- RecorderAccumulates recorded workloads and exports them as one bundle.
- RemoteEnvDependency-free client for one remote environment endpoint.
- RemoteModelDependency-free client for a model already served on an endpoint.
- RemoteVectorEnvDependency-free client for a remote vector-environment endpoint.
- RunContextWhat a run exposes to its hooks: the connected env, in either loop.
- RunHooksObserver callbacks for a run; every default is a no-op.
- RunResultThe result of a
Model.run()eval. - SandboxBuildExperimentalBuild-from-source infrastructure for a sandbox image.
- SandboxEnvExperimentalOwned Docker-backed session for one environment (experimental).
- SandboxModelExperimentalA model served from an isolated container.
- SandboxRuntimeExperimentalContainer run-time settings for a sandbox --
docker runflags. - SandboxVectorEnvExperimentalOwned Docker-backed session for a vector environment (experimental).
- ServeOptionsServer lifecycle options.
- SessionA model bound to one env: drive it by hand, or pump whole episodes.
- StepEventOne env step of a run, passed to
RunHooks.on_step(). - TelemetryRowOne aggregated metric series from a
Model.run()eval. - TensorNative tensor value used by RLMesh value encoding.
- VariantOne concrete sub-environment in an
EnvFactory's catalog. - VectorExperimentalA fixed-length float-vector
Paramtype, passed asParam(type=Vector(3)). - ViewHow to show a live eval.
- WorkflowEditionWarningAn authored or served participant declared no workflow edition.
Functions
- build_info()This build's identity: the package version, the protocol generation, and the workflow edition it advertises with the cohort behind that spelling.
- current_workflow_edition()The bare
YYYY.MMedition this build runs at -- what to paste into a declaration. - describe()Return an env/model's full metadata envelope as a dict.
- describe_json()Like
describe(), but return the canonical JSON string verbatim. - predict_seed()Per-predict sampling seed mixed from an episode's reset seed and its re-plan ordinal.
- run()Drive
modelagainstenvto completion and return aRunResult. - sanitize_metadata()Coerce an info/metadata mapping into what RLMesh metadata accepts.
- session()Bind a model to an env and return a
Sessionto drive by hand or via run(). - trial_index()The reserved
trial_indexreset option, orNonewhen absent.
Exceptions
- EnvironmentExceptionRaised when an environment endpoint fails a reset, step, or render.
- ProtocolExceptionReserved for protocol-level faults; not raised in 0.1.0.
- RLMeshExceptionBase class for every exception RLMesh raises.
Submodules
- adaptersDeclarative env-to-model adapters: tags, model specs, and contract-based resolution.
- paramsDeclared construction parameters for env factories and models.
- spacesNamed RLMesh-native space wrappers and Gymnasium backends.
- specsNative environment and space spec classes.
- typesStructural protocols and shared value aliases.
Constants
- DESCRIBE_METADATA_KEYMetadata/OCI-label key under which the versioned describe envelope is stored (rlmesh.describe.v1).
- DESCRIBE_SCHEMA_VERSIONSchema version stamped into the envelope emitted by describe/describe_json.
- ENV_RESET_OPTIONS_KEYMetadata key under which an env declares the reserved reset-option keys it wants delivered (rlmesh.env.v1.reset_options).
- NO_ADAPTERPass as
specto explicitly skip RLMesh adapter resolution. - RANDOM_SAMPLEPass as the model to
rlmesh.session()/rlmesh.run()to sample actions. - __build__Deprecated alias for build_info().workflow_edition; removed in 0.2.
- __version__Installed RLMesh package version.