Reward Machines: Exploiting Reward Function Structure in Reinforcement Learning
Rodrigo Toro IcarteToryn Q. KlassenRichard Anthony ValenzanoSheila A. McIlraith
Introduces reward machines, a finite state machine representation that exposes structured, non-Markovian reward functions to reinforcement learning agents to significantly improve sample efficiency through automated reward shaping, task decomposition, and counterfactual reasoning.
Standard reinforcement learning algorithms typically treat reward functions as opaque black boxes, requiring autonomous agents to learn purely through extensive and costly trial-and-error interaction. This design overlooks the fact that developers explicitly program these reward functions and could instead expose their underlying structural logic—such as sequential stages, conditional rules, safety constraints, and iterative loops—to accelerate learning.
The article introduces reward machines, a structured representation based on finite state automata that exposes the internal stages of reward functions, and presents several learning algorithms designed to exploit this structure. It evaluates whether these methods improve data efficiency and overall policy quality across both discrete environments and complex continuous control tasks.
To evaluate this framework, the authors conducted extensive simulated experiments comparing reward-machine-enabled methods against standard reinforcement learning baselines across discrete gridworlds, continuous 2D tracking environments, and continuous robot control benchmarks. The experimental methods included counterfactual experiences for reward machines, which generates synthetic training samples across all possible machine states from a single environmental action; hierarchical reinforcement learning for reward machines, which decomposes tasks into sub-policies corresponding to transitions between machine states; and automated potential-based reward shaping, which derives intermediate guidance rewards directly from the machine structure.
The empirical results show that methods exploiting reward structure consistently and significantly outperform standard baseline approaches. Counterfactual experiences for reward machines achieved optimal policy performance in nearly all benchmarks, demonstrating the largest performance advantages in complex, sparse-reward, and multitask settings. Hierarchical reinforcement learning learned very rapidly in initial phases and excelled in long sequential tasks, although it often converged to slightly suboptimal solutions due to localized, greedy decision-making. In continuous robot control benchmarks where the standard baseline failed to learn even after 30 million training steps, the proposed methods successfully mastered the tasks, with counterfactual reasoning achieving nine target laps per episode. However, automated reward shaping yielded mixed results, improving learning speeds in discrete domains but reducing performance in continuous settings, while both counterfactual and hierarchical approaches incurred higher computational runtime per training step.
These findings indicate that making reward structures visible resolves a major bottleneck in reinforcement learning: sample inefficiency caused by sparse feedback. Exposing reward logic lowers the physical or simulated interaction time needed to train functional policies, mitigating the high operational risks and deployment costs of real-world agent training. When choosing between these methodologies, practitioners face clear trade-offs: counterfactual reasoning is ideal when global optimality and sample efficiency are paramount, whereas hierarchical decomposition provides faster initial progress on long sequential objectives at the expense of slight suboptimality.
Organizations developing complex autonomous systems should consider representing staged or non-Markovian tasks as reward machines rather than monolithic black-box reward functions. Engineering teams can leverage standard parallel computing hardware to mitigate the additional per-step computational overhead observed during training. Because the current framework assumes deterministic and noise-free environmental event detection, future efforts should prioritize evaluating and developing methods resilient to noisy real-world sensors, learning machines directly from imperfect data, and extending these concepts to model-based reinforcement learning.
- Paper: Policy Invariance Under Reward Transformations: Theory and Application to Reward Shaping, Andrew Y. Ng et al. (1999). This foundational paper formalizes potential-based reward shaping, establishing the theoretical guarantees of policy invariance that Reward Machines directly rely on for automated reward shaping.
- Paper: Between MDPs and semi-MDPs: A framework for temporal abstraction in reinforcement learning, Richard S. Sutton et al. (1999). This work introduces the options framework for temporal abstraction and semi-Markov decision processes, providing core conceptual foundations for decomposing tasks and learning over structured transitions as utilized by Reward Machines.
- Paper: Hierarchical Reinforcement Learning with the MAXQ Value Function Decomposition, Thomas G. Dietterich (1999). This paper establishes hierarchical value function decomposition for reinforcement learning, laying groundwork for how Reward Machines decompose complex non-Markovian tasks into modular sub-problems.
- Paper: Hindsight Experience Replay, Marcin Andrychowicz et al. (2017). This work develops goal-relabeling and counterfactual updates in off-policy learning, inspiring the counterfactual reasoning mechanisms used in Reward Machines to train multiple sub-policies simultaneously.
- Paper: Q-learning, CHRISTOPHER J.C.H. WATKINS et al. (1992). This seminal work establishes Q-learning and off-policy value iteration, which serve as the baseline reinforcement learning mechanics augmented by Reward Machines.
- Paper: Automaton-Guided Curriculum Generation for Reinforcement Learning Agents, Yash Shukla et al. (2023). This work builds directly upon formal automaton representations of temporal logic tasks to automatically synthesize structured learning curricula for reinforcement learning agents.
- Paper: Unpacking Reward Shaping: Understanding the Benefits of Reward Engineering on Sample Complexity, Abhishek Gupta et al. (2022). This paper deepens the theoretical understanding of reward engineering by analyzing the exact sample complexity reductions achieved through structured reward shaping.
