Counting Reward Automata: Sample Efficient Reinforcement Learning Through the Exploitation of Reward Function Structure

Tristan Bester, Benjamin Rosman, Steven James, Geraud Nangue Tasse

TL;DR

This paper introduces Counting Reward Automata (CRA), a novel framework that uses counter-augmented finite state machines to model complex, non-regular reward functions in reinforcement learning. By breaking free from the limitations of standard regular languages, CRA allows agents to efficiently solve long-horizon tasks requiring counting and memory without exploding the state space.

What Problem Does This Paper Address?

Reinforcement learning (RL) excels at short-horizon tasks but struggles when a problem requires long-term planning or tracking complex histories. To help, researchers often use Reward Machines (RMs)—finite state machines that expose the internal structure of a reward function.

However, standard RMs are fundamentally limited: they can only represent tasks expressible as regular languages. If a task requires an agent to perform an action an arbitrary number of times ($N$) and then perform a matching action exactly $N$ times (a context-free or context-sensitive language requirement), a standard RM fails. To emulate such behavior, an RM's state space must grow linearly or exponentially with $N$, leading to severe sample inefficiency and complex, unreadable machines.

Methods

The authors propose Counting Reward Automata (CRA) to bridge this gap using a neuro-symbolic approach:

  1. Counting Reward Automata (CRA): A finite state machine variant augmented with $k$ integer counter variables. This allows the machine to transition not just based on environmental events, but also on the status of its counters (e.g., checking if a counter is zero).
  2. Automaton-Augmented MDP (AAMDP): To keep the environment Markovian, the authors cross the underlying environment state space with the CRA's internal configurations (states + counter values).
  3. Counterfactual Q-Learning (CQL): A novel off-policy learning algorithm. Because the CRA explicitly defines the reward structure, the agent can perform counterfactual reasoning—updating its Q-values by simulating what would have happened if it were in any other automaton state or counter configuration during a transition.
  4. LLM Task Specification: The authors demonstrate that a Large Language Model (like ChatGPT) can easily translate natural language instructions into the formal transition functions required by the CRA.

Datasets

The framework was evaluated on two simulated environments designed to test non-regular language tasks:

  • LetterEnv: A custom gridworld environment where the agent must observe a sequence of symbols corresponding to the context-free language $L = \{A^N B C^N : N \in \mathbb{N}\}$.
Figure 1: Illustration of the LetterEnv environment, con- figured for the CFL experiment. The symbol A is replaced with a B after it has been observed N times by the agent.
  • Office Gridworld: A modified version of a classic benchmark. The agent must complete a context-sensitive task: navigate to a mailroom, collect an unknown $N$ number of mail items, brew exactly $N$ coffees, and deliver them to employees at a specific location without breaking any decorations.

Key Insights and Ideas

  • Turing Completeness with Minimal Overhead: By adding just two counters, a counter machine can simulate an arbitrary Turing machine. This elevates the reward modeling capability from simple regular expressions to recursively enumerable languages.
  • Constant Machine Complexity: Unlike standard Reward Machines, which require a unique state for every single step of a counting sequence, a CRA keeps the number of states and edges completely constant regardless of how large $N$ scales.
Figure 2: Illustration of a CCRA used to solve the example CFL task in the LetterEnv environment. The τ symbol is used to represent a tautology (a propositional formula that is always true) which conditions the corresponding transition only on the states of the counters.
  • Counterfactual Data Efficiency: The "aha moment" for sample efficiency comes from CQL. A single real-world step provides data to update the agent's policy across all possible internal counter states simultaneously, preventing the agent from having to relearn the same physical dynamics for different task phases.

Key Results

  • Drastic Reduction in Automaton Size: In the Office Gridworld task, as task complexity (the maximum number of items to count) scaled up to 500, the number of states and edges required by standard RMs exploded exponentially into the millions. In contrast, the CRA maintained a flat, human-readable complexity of just 3 states and under 10 edges.
Figure 5: Comparison between the complexity of the state machines produced by the CRA and RM formulations. The illustration shows the complexity of the machine required to solve a task specification with a fixed upper bound on task-string length (in this case, the maximum number of mail items). RMs were constructed using a general template im- plementation parameterised by the maximum string length required for the task.
  • Superior Sample Efficiency: On the context-free language task in LetterEnv, the CRA agent successfully learned a single policy capable of handling any value of $N$ simultaneously. Standard RM approaches were forced to train entirely separate policies for every individual value of $N$, severely bottlenecking their performance.

Limitations and Future Work

  • Finite-Horizon Assumption: To prevent the counter values from growing infinitely (which would make the state space infinite), the authors restrict their focus to finite-horizon MDPs where the maximum trajectory length $H$ places a natural upper bound on the counters.
  • Pre-defined Structures: The current framework assumes that the CRA structure is provided a priori by a human expert or an LLM. A natural next step for future work is to explore algorithms that can autonomously learn or induce the CRA structure directly from environmental rewards and transitions.

Summary updated

BibTeX
@inproceedings{bester2024counting,
  author = {Tristan Bester and Benjamin Rosman and Steven James and Geraud Nangue Tasse},
  title = {{Counting Reward Automata: Sample Efficient Reinforcement Learning Through the Exploitation of Reward Function Structure}},
  booktitle = {NuCLeaR @ AAAI},
  year = {2024},
  url = {https://openreview.net/forum?id=XfXLM8uIxH},
}
Figure