Using Reward Machines for High-Level Task Specification and Decomposition in Reinforcement Learning

Rodrigo Toro Icarte, Toryn Q. Klassen, Richard Anthony Valenzano, Sheila A. McIlraith

This paper, originally presented at ICML 2018, introduces a powerful framework for structured reinforcement learning (RL). By moving away from traditional "black-box" reward models, the authors propose a more transparent, state-based representation of tasks that significantly improves learning efficiency and policy optimality.

The Problem with Black-Box Rewards

In standard reinforcement learning, the reward function is typically treated as an opaque black box: the agent performs an action, and the environment returns a scalar value. This approach ignores the reality that most complex tasks possess an inherent structure (e.g., "first do A, then do B, but avoid C").

While Hierarchical Reinforcement Learning (HRL) attempts to address this by breaking tasks into sub-goals, it suffers from two major flaws:

  1. Suboptimality: HRL often prunes the search space too aggressively. This causes the agent to settle for "good enough" local policies rather than finding the global optimum.
  2. Sample Inefficiency: Agents typically only learn about the specific sub-goal they are currently pursuing. This wastes valuable experience that could otherwise help solve other parts of the overall task.

Introducing Reward Machines (RMs)

To overcome these limitations, the authors introduce Reward Machines (RMs). A Reward Machine is a finite state machine that sits on top of the environment, encoding the structure of the reward function.

Examples of Reward Machines for patrolling and delivery tasks.

The RM transitions between states based on high-level events (e.g., "agent picked up coffee"). Each transition within the RM can define a different reward function, allowing researchers to program complex logic like loops, sequences, and conditionals (e.g., "If you have the mail, go to the office; otherwise, go to the mailroom"). RMs are highly expressive, capable of rewarding behaviors to varying degrees rather than just providing a binary success or failure signal.

Q-Learning for Reward Machines (QRM)

To exploit the structure provided by RMs, the authors developed Q-Learning for Reward Machines (QRM). The core innovation of QRM is parallel off-policy learning.

Instead of only learning a policy for the current RM state, the agent uses every experience tuple $(s, a, r, s')$ to update the Q-values for every possible state in the Reward Machine. Essentially, the agent asks: "If I had been in a different stage of the task, how much would this action have helped me?"

This counterfactual learning—learning from "what if" scenarios—dramatically improves sample efficiency because one step in the environment provides training data for multiple sub-tasks simultaneously. By treating the task as a Markov Decision Process (MDP) defined over the cross-product of the environment states and the RM states, the problem becomes Markovian again. In the tabular case, QRM is mathematically guaranteed to converge to the optimal policy, a feat standard HRL cannot claim.

The authors also extend this to Deep QRM (DQRM) using Double DQN and prioritized experience replay for continuous state spaces.

Experimental Setup and Key Findings

The researchers evaluated their approach across three distinct environments:

  • Office World: A discrete gridworld where an agent must navigate to locations in specific orders, deliver items, and avoid obstacles.
  • Minecraft-like World: A gridworld requiring the agent to collect raw materials and use a factory to craft items, testing complex sequential logic.
  • Water World: A continuous state space environment where an agent must touch colored balls in specific sequences, testing the algorithm's ability to scale using neural networks.
The Office Gridworld environment demonstrating the optimal blue path found by QRM versus the suboptimal red path from HRL baselines.

Key Results

  • Guaranteed Optimality: In the Office World, QRM consistently found the globally optimal path (the "blue path"), whereas HRL baselines frequently got stuck in sub-optimal routines (the "red path").
  • Learning Speed: In the Minecraft-like world, QRM learned to solve 10 different complex tasks significantly faster than standard Q-learning or HRL methods.
  • Continuous Scaling: In the Water World, DQRM significantly outperformed Deep HRL and standard DDQN, demonstrating that this structured approach translates effectively to function approximation and high-dimensional spaces.

Limitations and Future Work

While powerful, the RM framework has a few limitations:

  • The Labeling Function: The system relies on a predefined labeling function that identifies high-level events (e.g., "at location A"). If this function is noisy or difficult to define, the RM will struggle.
  • Manual Specification: Currently, the Reward Machine must be designed by a human. Future work could involve learning the RM structure directly from experience or natural language instructions.
  • State Explosion: While parallel updates are highly efficient, a massive RM with hundreds of states could introduce significant computational overhead during the learning loop.

Reference: Toro Icarte, R., Klassen, T. Q., Valenzano, R., & McIlraith, S. A. (2018). Using Reward Machines for High-Level Task Specification and Decomposition in Reinforcement Learning. Proceedings of the 35th International Conference on Machine Learning (ICML).

Summary updated

BibTeX
@inproceedings{icarte2018using,
  author = {Rodrigo Toro Icarte and Toryn Q. Klassen and Richard Anthony Valenzano and Sheila A. McIlraith},
  title = {{Using Reward Machines for High-Level Task Specification and Decomposition in Reinforcement Learning}},
  booktitle = {International Conference on Machine Learning},
  year = {2018},
}
Figure