rlmesh.EnvServer
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
| Name | Type | Description |
|---|---|---|
env | EnvLike[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. |
address | str | None | Optional 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. |
host | str | None | TCP host helper used when address is omitted. |
port | int | None | TCP port helper used when address is omitted. |
path | str | None | Unix socket path helper used when address is omitted. |
transport | Transport | None | Explicit transport selector. |
options | ServeOptions | None | Optional 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]. |
tags | EnvTags | None | Optional 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()). |
framework | str | ValueBridge | None | The 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. |
device | object | None | Device 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.
Attributes
Methods
address
property[source]property address: strGet the bound server address.
env_contract
property[source]property env_contract: EnvContractEnvironment contract served by this endpoint.
serve
function[source]serve() -> NoneStart 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() -> NoneStart serving the environment on a background thread.
wait
function[source]wait(timeout: float | None = None) -> boolWait for a background server to stop.
Parameters
| Name | Type | Description |
|---|---|---|
timeout | float | None | Optional timeout in seconds. None waits indefinitely. |
Returns
| Type | Description |
|---|---|
bool | True if the server has stopped, or False if the timeout elapsed. |
shutdown
function[source]shutdown() -> NoneStop the server if it is running.