Env Server¶
EnvServer owns a Python environment object and exposes it as an RLMesh environment endpoint. The
served endpoint supports both local loopback use and process boundaries where a model or evaluator
connects through RemoteEnv or RemoteVectorEnv.
Environment Contract¶
The server inspects the environment once during construction and caches an
EnvContract. The contract describes the endpoint id, spaces, render mode,
metadata, and number of environments. EnvServer.spec is an alias for EnvServer.env_contract so
code that expects a Gymnasium-style spec field can still reach the same RLMesh contract.
server = rlmesh.EnvServer(env, "127.0.0.1:5555")
print(server.env_contract.id)
print(server.env_contract.observation_space.kind)
print(server.spec.action_space.kind)
See Contracts and Specs for contract fields.
Bind Address Environment Variables¶
When RLMesh serves an environment through its bootstrap entrypoint (for example inside a sandbox container), the bind address follows a single canonical contract so that hosts and downstream images agree on where the environment listens:
Variable |
Meaning |
|---|---|
|
Full bind address ( |
|
Port-only fallback, bound on |
|
Deprecated alias for |
|
Deprecated alias for |
RLMESH_ADDRESS is the preferred knob; it accepts the same forms as the EnvServer address
argument, so a non-default host or a Unix socket can be selected without code changes.
RLMESH_ENV_ADDRESS / RLMESH_ENV_PORT are deprecated aliases kept for backward compatibility.
Constructing EnvServer directly in your own process ignores these variables. Pass
address/host/port explicitly.
API¶
- class rlmesh.EnvServer[source]¶
Bases:
objectServes an RLMesh-compatible environment.
- Parameters:
env – Environment satisfying the RLMesh protocols.
address – 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 – TCP host helper used when
addressis omitted.port – TCP port helper used when
addressis omitted.path – Unix socket path helper used when
addressis omitted.transport – Explicit transport selector.
options – Optional serve lifecycle options controlling remote shutdown, idle shutdown, drain timeout, and close timeout.
tags – 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 (seerlmesh.adapters.resolve_from_contract()).
Examples
>>> from rlmesh import EnvServer, spaces >>> >>> class TinyEnv: ... observation_space = spaces.from_gymnasium_space( ... __import__("gymnasium").spaces.Discrete(4) ... ) ... action_space = spaces.from_gymnasium_space( ... __import__("gymnasium").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()
- __init__(env, address=None, *, host=None, port=None, path=None, transport=None, options=None, tags=None)[source]¶
- Parameters:
env (EnvLike)
address (str | None)
host (str | None)
port (int | None)
path (str | None)
transport (Transport | None)
options (ServeOptions | None)
tags (EnvTags | None)
- Return type:
None