RLang: A Declarative Language for Describing Partial World Knowledge to Reinforcement Learning Agents

Rafael Rodríguez-Sánchez, Benjamin Adin Spiegel, Jennifer Wang, Roma Patel, Stefanie Tellex, George Konidaris

Introduction

Reinforcement Learning (RL) agents are notoriously "stubborn." Most are designed to learn tabula rasa—from a completely blank slate. This means an agent might have to fall into a pit of lava hundreds of times before it realizes the danger. While this trial-and-error approach is robust, it is incredibly sample-inefficient. Humans, by contrast, rely heavily on prior knowledge: we know that lava is hot and that jumping helps clear gaps before we ever attempt a task.

To bridge this gap, researchers have introduced RLang, a domain-specific language (DSL) designed to allow humans to communicate partial world knowledge to RL agents. RLang provides a human-readable, algorithm-agnostic medium to give agents a "head start," dramatically accelerating the learning process across a wide variety of tasks.

The Challenge of Blank-Slate Learning

The central challenge in modern RL is the sample inefficiency of learning from scratch. While there have been previous attempts to provide agents with human advice, these methods typically suffer from two major flaws:

  1. Narrow Scope: Most existing languages only allow developers to describe a single element of the environment, such as the reward function or a specific policy constraint.
  2. Algorithm Coupling: Advice is often hard-coded into a specific agent's architecture. This makes it nearly impossible to reuse that knowledge if a developer switches from a Q-learning agent to a Policy Gradient agent.

A unified, "complete" language is needed—one that can describe any part of a Markov Decision Process (MDP) while remaining flexible enough to let the agent fill in the gaps where human knowledge is missing or imperfect.

The RLang Framework

The core contribution of this research is the RLang DSL and its associated compiler, which translate human knowledge into actionable RL components.

  • A Comprehensive Language: RLang uses a syntax that blends formal logic and programming. It allows users to define Factors (specific parts of the state), Propositions (logical truths about the state), Effects (how actions change the world), and Policies (recommended actions).
  • Support for Partial Knowledge: Crucially, RLang supports partial specifications. If a user does not know the exact transition probability for an action, they simply leave it undefined. The RLang interpreter returns an "unknown" flag, signaling to the agent that it must learn that specific dynamic through experience.
  • Algorithm-Agnostic Grounding: The RLang compiler transforms high-level descriptions into "grounded" Python objects. These objects provide a standardized interface that any RL algorithm can query (e.g., "What is the expected reward here?" or "Does the human have a suggested action for this state?").
  • Vocabulary Files: To handle complex, high-dimensional inputs like pixels, RLang allows users to link "vocabulary" files (in JSON or Python). These files map raw data to high-level concepts, such as an object detector identifying "lava" in a camera feed, which the RLang program can then reason about.

Experimental Evaluation

The researchers evaluated RLang across several classic and complex RL benchmarks to test its versatility:

  • Gridworlds: Lava-Gap (navigation with high penalties) and Taxi (both flat and object-oriented versions).
  • Classic Control: Environments like CartPole, Mountain Car, and Lunar Lander.
  • Hierarchical Tasks: A 2D Minecraft-inspired crafting environment where agents must collect materials and use workbenches to create complex items.

Key Insights and Results

The results across all environments demonstrated that RLang-informed agents significantly outperformed their tabula rasa counterparts.

  • The "Jump-Start" Effect: Providing even a non-optimal policy in RLang gives agents an immediate jump-start. They achieve high rewards almost instantly and continue to refine their behavior over time, eventually outperforming the human's initial advice.
  • Completeness is Key: Because RLang can describe every component of an MDP, developers can provide an agent with a partial map of transitions, a sense of "good" and "bad" rewards, and a rough strategy all at once. In the Lava-Gap environment, informed agents avoided lava pits from the very first episode, whereas uninformed agents spent hundreds of episodes dying.
  • Algorithm Agnosticism in Practice: The same RLang program successfully boosted the performance of vastly different agents, including tabular Q-Learning, Deep Q-Networks (DDQN), and Proximal Policy Optimization (PPO).
  • Solving Complex Hierarchies: In the 2D Minecraft task, the uninformed agent failed to learn anything meaningful. However, the RLang agent, provided with the structure of "options" (e.g., "go to the workbench"), successfully learned to craft complex items. In Mountain Car, a concise RLang policy of just five lines allowed the agent to solve the task almost instantly, achieving a near-optimal return of -119.

Limitations and Future Directions

While RLang is a powerful tool for researchers and engineers, it currently requires users to write code in a specific syntax. The authors note that the ultimate goal is Natural Language Grounding—allowing a user to simply say "Don't fall in the lava" in English, with a system automatically translating that instruction into RLang.

Additionally, while RLang can interface with learned classifiers (like a "lava detector"), the current framework assumes these low-level groundings are provided a priori. Future research will explore how agents might learn the RLang "vocabulary" itself from scratch while simultaneously leveraging the language's high-level logic.

Summary updated

BibTeX
@inproceedings{rodriguezsanchez2023rlang,
  author = {Rafael Rodríguez-Sánchez and Benjamin Adin Spiegel and Jennifer Wang and Roma Patel and Stefanie Tellex and George Konidaris},
  title = {{RLang: A Declarative Language for Describing Partial World Knowledge to Reinforcement Learning Agents}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=UlhLY6hWOl},
}
Figure