ReAgent: Applied Reinforcement Learning Platform for Large-Scale Reasoning

Jul 10, 2025

Introduction

Building production-ready reinforcement learning (RL) systems often requires a fragmented ecosystem of tools for data preprocessing, training, and serving. ReAgent, an open-source platform developed by Meta (formerly Facebook Research) with over 3.7k GitHub stars, simplifies this by providing an end-to-end framework for applied RL and contextual bandits. It replaces the need to build separate pipelines for each stage of the model lifecycle, offering a unified approach to large-scale decision-making systems.

What Is ReAgent?

ReAgent is an open-source end-to-end platform for applied reinforcement learning (RL) and reasoning systems developed by Meta. It is built in Python and leverages PyTorch for modeling and training, and TorchScript for optimized model serving. The platform is designed to handle large-scale, distributed recommendation and optimization tasks, particularly in environments where a simulator is unavailable and training must occur offline on batches of data.

Originally named “Horizon,” the project was renamed to ReAgent to reflect its broader scope in decision-making and reasoning. It is distributed under the BSD License, allowing for flexible integration into commercial and research projects.

Why ReAgent Matters

In traditional machine learning, the gap between a research prototype and a production deployment is often a “valley of death.” For RL, this is even more pronounced because the feedback loop between experimentation and production is complex. ReAgent fills this gap by providing a standardized workflow that integrates data preprocessing, feature transformation, and counterfactual policy evaluation into a single pipeline.

The platform’s ability to perform offline training on batches of data is critical for real-world applications like recommender systems, where deploying a random exploration policy in production would be prohibitively expensive or risky. By utilizing counterfactual evaluation, ReAgent allows developers to estimate the performance of a new policy before it is ever released to users.

With a significant community following and a pedigree from Meta’s own internal systems, ReAgent provides a blueprint for how to build reasoning systems that can scale to millions of users while maintaining stability and performance.

Key Features

  • Comprehensive RL Algorithm Portfolio: ReAgent supports a wide array of algorithms, including classic off-policy algorithms like DQN (Discrete-Action, Parametric-Action, Double, Dueling), Distributional RL (C51, QR-DQN), and Actor-Critic methods like TD3, SAC, and PPO.
  • Contextual Bandit Support: The platform implements essential bandit algorithms such as UCB1, MetricUCB, Thompson Sampling, and LinUCB for efficient exploration-exploitation trade-offs.
  • End-to-End Workflow: It integrates data preprocessing, feature transformation, and distributed training, reducing the overhead of managing multiple disparate tools.
  • Counterfactual Policy Evaluation (CPE): ReAgent includes tools for Doubly Robust estimation (for both bandits and sequential decisions) and MAGIC, allowing for the evaluation of new policies using historical data.
  • Optimized Model Serving: By using TorchScript, ReAgent ensures that models trained in PyTorch can be served with high performance and low latency in production environments.
  • RL for Recommender Systems: Specialized support for algorithms like Seq2Slate and SlateQ, which are specifically designed for slate-based recommendation tasks.
  • Distributed Training: The platform is built to handle large-scale datasets and distributed training workloads, making it suitable for industrial-scale AI.
  • Flexible Modeling: Built on PyTorch, it allows researchers to easily customize and extend the underlying neural network architectures.

How ReAgent Compares

ReAgent differs from general-purpose RL libraries like OpenAI Gym or Stable Baselines3 by focusing on applied RL—specifically the infrastructure required to train on offline data and serve models at scale. While Gym provides the environment, ReAgent provides the entire pipeline from data to production.

Feature ReAgent Stable Baselines3 Ray Rllib
Primary Focus Applied/Production RL Algorithmic Research Distributed Scaling
Offline Training Native Support Limited Strong
Counterfactual Eval Integrated No Partial
Model Serving TorchScript Optimized Generic Flexible
Target User ML Engineers Researchers Enterprise AI Teams

The primary differentiator for ReAgent is its emphasis on the feedback loop. By integrating counterfactual evaluation, it allows engineers to validate policies without the risk of live testing. This makes it far more suitable for high-stakes environments like e-commerce or social media feeds where a bad policy can lead to immediate revenue loss.

However, a significant tradeoff is that ReAgent is now officially archived by Meta. This means that while the code is available and highly educational, it may not receive updates for the latest PyTorch versions or new RL algorithms. For those seeking a maintained production library, Meta recommends Pearl, their newer AI agent library.

Getting Started: Installation

ReAgent requires Python 3.8+ and is designed to be installed manually or via Docker. Because it is an archived project, users should be mindful of dependency versions, particularly PyTorch.

Manual Installation

Clone the repository and install the dependencies. If you do not need the gym dependencies, you can omit the [gym] flag.

git clone https://github.com/facebookresearch/ReAgent.git
cd ReAgent
pip install ".[gym]"

PyTorch Setup

To ensure compatibility with the platform’s modeling capabilities, it is recommended to install a nightly build of PyTorch (or a specific version compatible with the project’s requirements.txt).

pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

Docker Installation

The repository provides Docker support for a more consistent environment, which is highly recommended given the project’s archived status to avoid “dependency hell.”

Detailed instructions are available in the docs/installation.rst file within the repository.

How to Use ReAgent

The ReAgent workflow typically follows a cycle of offline training, evaluation, and serving. Unlike traditional RL where an agent interacts with a live environment, ReAgent is optimized for batch processing.

ReAgent provides both a Command Line Interface (CLI) for launching training jobs and a Python API for programmatic use in scripts or Jupyter Notebooks. The basic workflow involves preparing your data in a format compatible with ReAgent’s preprocessing tools, using the CLI to train a model (e.g., a DQN or LinUCB agent), and then evaluating the policy using counterfactual methods.

Once a model is trained and evaluated, it is exported to TorchScript. This allows the model to be served in a production environment with minimal overhead, bypassing the Python interpreter for inference.

Code Examples

While the repository focuses on large-scale distributed training, the Python API allows for simpler implementations. Below is an example of how a contextual bandit model might be initialized and used within the ReAgent framework.

from reagent.models import DeepRepresentLinUCB

# Initialize the model
model = DeepRepresentLinUCB()

# Train the model with your data
# In a real scenario, this would involve a distributed training job
model.train(training_data)

# Make predictions for the best action to take given a context
predictions = model.predict(test_data)

This example demonstrates the use of DeepRepresentLinUCB, which combines deep learning for representation learning and the LinUCB algorithm for efficient exploration. This is a common pattern in ReAgent for handling high-dimensional context vectors.

Real-World Use Cases

ReAgent shines in scenarios where you have massive amounts of historical interaction data but cannot risk live experimentation.

  • Personalized Content Recommendation: A social media platform can use ReAgent to train a slate-based RL agent (using SlateQ) to optimize for long-term user engagement rather than immediate click-through rate.
  • Dynamic Ad Placement: An advertising network can implement a contextual bandit (using LinUCB) to using a contextual bandit (using LinUCB) to determine the best ad to show a user based on their demographics and current browsing context, optimizing for conversion rates.
  • Dynamic Pricing Optimization: An e-commerce site can use ReAgent to train an RL agent that adjusts prices based on user context and market conditions, evaluating the new policy offline using Doubly Robust estimation before deployment.
  • Adaptive User Interface (UI) Layouts: A product team can use ReAgent to optimize the layout of elements on a page to maximize a specific metric, using the platform’s counterfactual evaluation to ensure the new layout doesn’t negatively impact the user experience.

Contributing to ReAgent

Because ReAgent is an archived repository, the Meta team is no longer actively maintaining it. However, the project remains open-source and the code is available for study and research. Users can still report bugs or submit pull requests through the standard GitHub flow: fork the repository, create a branch, and submit a PR.

The project includes a CONTRIBUTING.md file that outlines the requirements for adding tests and updating documentation when changing APIs. It also emphasizes the importance of the Contributor License Agreement (CLA) to ensure legal clarity for open-source contributions.

Community and Support

Support for ReAgent is primarily found through the GitHub Issues section, where developers have discussed installation challenges and GPU support. Since the project is archived, there is no official Discord or Slack channel. Documentation is provided within the repository’s docs/ folder, specifically in the installation.rst and usage.rst files.

For those looking for the current state of Meta’s RL infrastructure, it is recommended to follow the Meta AI research blog and the facebookresearch GitHub organization to find the rest of their latest tools, such as the Pearl library.

Conclusion

ReAgent is a powerful, albeit archived, platform that provides a comprehensive blueprint for building applied reinforcement learning systems. By unifying the training, evaluation, and serving pipelines, it solves the most critical challenges of scaling RL to production environments.

If you are a researcher or an ML engineer looking to understand how Meta handles large-scale reasoning systems, ReAgent is an invaluable resource. However, for production systems being built today, you should consider the latest maintained libraries or explore Meta’s Pearl library as the direct successor to this framework.

Star the repo to keep it as a reference, explore the quickstart, and study the architecture to implement similar patterns in your modern RL stack.

What is ReAgent and what problem does it solve?

ReAgent is an end-to-end platform for applied reinforcement learning developed by Meta. It solves the problem of fragmented RL pipelines by integrating data preprocessing, training, and optimized serving into a single framework, specifically for large-scale systems where simulators are unavailable.

How do I install ReAgent?

ReAgent can be installed by cloning the GitHub repository and running pip install ".[gym]". It is recommended to use Docker or a specific PyTorch nightly build to ensure compatibility with its archived dependencies.

Can I use ReAgent for real-time RL training?

No, ReAgent is specifically designed for offline RL, where the model is trained on batches of historical data and then deployed as a TorchScript model for high-performance inference.

How does ReAgent compare to Stable Baselines3?

While Stable Baselines3 focuses on algorithmic research and environment interaction, ReAgent focuses on the infrastructure for production RL, including counterfactual evaluation and TorchScript serving.

Can I use ReAgent for contextual bandits?

Yes, ReAgent provides native support for several contextual bandit algorithms, including LinUCB, UCB1, and Thompson Sampling, making it a powerful tool for personalized recommendation systems.

Is ReAgent still actively maintained?

No, ReAgent is officially archived by Meta. For production-ready support, Meta recommends using their newer library, Pearl.

What is the benefit of TorchScript in ReAgent?

TorchScript allows ReAgent models to be served in a production environment without the Python interpreter, which significantly reduces latency and increases throughput for large-scale reasoning systems.