External environments and applications#

Sometimes it doesn’t make sense for RLlib to “step” an RL environment. For example, you might train a policy inside a complex simulator that runs its own execution loop, such as a game engine or a robotics simulation. A natural approach flips this setup around. Instead of RLlib stepping the environment, the agents in the simulation control their own stepping. An external, RLlib-powered service is available to answer queries for individual actions or to accept batched sample data. The service trains the policies but doesn’t restrict when or how often per second the simulation steps.

../_images/external_env_setup_client_inference.svg

External application with client-side inference: An external simulator, such as a game engine, connects to RLlib, which runs as a server through a TCP-capable, custom EnvRunner. The simulator periodically sends batches of data to the server and in turn receives weight updates. For better performance, the client computes actions locally.#

RLlib provides an external messaging protocol called RLlink for this purpose. You can also customize your EnvRunner class to communicate through RLlink with one or more clients. An example TCP-based EnvRunner implementation with RLlink is available. It also contains a dummy CartPole client for testing and as a template for how your external application or simulator should use the RLlink protocol.

Note

External application support is a work in progress on RLlib’s new API stack. The Ray team is developing more examples for custom EnvRunner implementations, beyond the available TCP-based one, along with client-side, non-Python RLlib adapters for popular game engines and other simulation software.

Example: External client connecting to a TCP-based EnvRunner#

An example TCP-based EnvRunner implementation with RLlink is available. See the full end-to-end example.

You can alter the underlying logic of your custom EnvRunner. For example, you could implement a shared-memory communication layer instead of the TCP-based one.