rlmesh.EnvServer

classfrom rlmesh import EnvServer[source]

Serves an RLMesh-compatible environment.

EnvServer(
    env: EnvLike[Any, Any] | VectorServerEnvLike | Sequence[EnvLike[Any, Any]],
    address: str | None = None,
    *,
    host: str | None = None,
    port: int | None = None,
    path: str | None = None,
    transport: Transport | None = None,
    options: ServeOptions | None = None,
    tags: EnvTags | None = None,
    framework: str | ValueBridge | None = None,
    device: object | None = None,
    close_env_on_shutdown: bool = True,
)

Parameters

NameTypeDescription
envEnvLike[Any, Any] | VectorServerEnvLike | Sequence[EnvLike[Any, Any]]Environment satisfying the RLMesh protocols, or a list of scalar environments to serve as the lanes of one endpoint. Lanes are stepped independently (a runtime keeps one request per lane in flight), so a slow lane never holds the others; a single env is the one-lane case of the same server. A natively vectorized env (the VectorEnvLike shape) is served by the vector server instead.
addressstr | NoneOptional bind address. Supports "tcp://host:port", "host:port", "port", and "unix:///path/to/socket.sock". Defaults to "tcp://127.0.0.1:0" when omitted.
hoststr | NoneTCP host helper used when address is omitted.
portint | NoneTCP port helper used when address is omitted.
pathstr | NoneUnix socket path helper used when address is omitted.
transportTransport | NoneExplicit transport selector.
optionsServeOptions | NoneOptional serve lifecycle options controlling remote shutdown, idle shutdown, drain timeout, close timeout, and the workflow edition this endpoint declares (see :doc:/editions/index). An edition set here is declared verbatim; options without one take RLMESH_WORKFLOW_EDITION, then [tool.rlmesh].
tagsEnvTags | NoneOptional adapter env tags (rlmesh.adapters.EnvTags) to publish for this env. They are validated against the env's spaces and merged into its metadata, so a model client can resolve an adapter from the contract alone (see rlmesh.adapters.resolve_from_contract()).
frameworkstr | ValueBridge | NoneThe framework the env's step requires its *action* as -- "torch", "jax", "numpy" (default), or a pre-resolved value-bridge object (advanced). Only needed for a framework-strict env (one whose step does e.g. action.to(...)); a tolerant env can omit it. *Observations* need no declaration -- a torch/jax obs (GPU included) is auto-detected and encoded either way. The wire stays framework-neutral, so the env's action framework is independent of any consuming model's framework. render() is not bridged: frames pass through as-is and the native layer imports CPU arrays only, so a framework env should return numpy/CPU frames.
deviceobject | NoneDevice to place the incoming action on (torch/jax only), e.g. "cuda:0" or a torch.device. Requires framework=; rejected for numpy/the default.

Examples

>>> from rlmesh import EnvServer, spaces
>>>
>>> class TinyEnv:
...     observation_space = spaces.Discrete(4)
...     action_space = spaces.Discrete(2)
...
...     def reset(self, *, seed=None, options=None):
...         return 0, {}
...
...     def step(self, action):
...         return 0, 0.0, False, False, {}
...
...     def close(self):
...         return None
>>> server = EnvServer(TinyEnv(), "localhost:5555")
>>> server.serve()

close_env_on_shutdown (default True) calls the env’s close() when the server stops; pass False for a server standing in front of an env its caller owns, whose close() stays the caller’s.

address

property[source]
property address: str

Get the bound server address.

env_contract

property[source]
property env_contract: EnvContract

Environment contract served by this endpoint.

serve

function[source]
serve() -> None

Start serving the environment (blocking).

The env keeps this thread: every reset/step/render/close runs here, so an env built on the main thread (a simulator that only works from the thread that created it) is driven from it. On the main thread, Ctrl-C asks the server to stop, which drains and closes the env, and KeyboardInterrupt is raised here afterwards rather than inside an env call; a second Ctrl-C interrupts an env call that will not return (Python code, not a call stuck inside a native library).

start

function[source]
start() -> None

Start serving the environment on a background thread.

wait

function[source]
wait(timeout: float | None = None) -> bool

Wait for a background server to stop.

Parameters

NameTypeDescription
timeoutfloat | NoneOptional timeout in seconds. None waits indefinitely.

Returns

TypeDescription
boolTrue if the server has stopped, or False if the timeout elapsed.

shutdown

function[source]
shutdown() -> None

Stop the server if it is running.