Introduction
While Transformers have revolutionized natural language processing and computer vision, their success in Reinforcement Learning (RL) has been comparatively modest. Existing architectures, such as the Decision Transformer (DT), treat RL primarily as a sequence modeling problem: the model is conditioned on a desired reward and attempts to imitate the actions that led to that reward in the training data.
However, these models exhibit a significant limitation—they cannot effectively learn from failure. If a Decision Transformer is trained on sub-optimal data, it learns a sub-optimal policy. It lacks the "agentic" ability to stitch together different pieces of sub-optimal experience to find a better path, and it cannot dynamically improve its strategy if it fails a task during evaluation. To bridge this gap, researchers have introduced the Agentic Transformer (AT), a novel architecture that leverages a "Chain of Hindsight" to enable trial-and-error learning and in-context improvement directly within a Transformer.
Methodology: Chain of Hindsight
The core innovation of the Agentic Transformer is the application of Chain of Hindsight (CoH) to trajectory data. This approach fundamentally changes how the model processes past experiences:
- Sequence Construction: Instead of training on isolated, single trajectories, AT groups $n$ trajectories together into a continuous "chain."
- Sorting: These grouped trajectories are sorted in ascending order based on their total rewards, meaning the sequence progresses from the worst attempt to the best attempt.
- Hindsight Relabeling: The target return for every trajectory in the chain is relabeled to match the reward of the best (final) trajectory in that sequence. This mechanism teaches the model the evolutionary path of success: "Here are several failed or sub-optimal attempts to reach a high score, and here is the final successful strategy."
- The Completion Token ($d$): A binary "task completion" token is introduced to inform the model whether the current trajectory actually met the desired target return.
- Autoregressive Training: A GPT-style, decoder-only Transformer is trained to predict the next action based on the extensive history of states, actions, rewards, and hindsight tokens across the entire chain of attempts.
At test time, this architecture allows the model to be rolled out multiple times. If it fails on the first attempt, that failure becomes part of the context window for the second attempt, enabling the model to adjust its behavior in-context.
Experimental Setup
The authors evaluated the Agentic Transformer on two prominent offline RL benchmarks to test both imitation and extrapolation capabilities:
- D4RL: A standard benchmark consisting of trajectories from "medium" and "expert" agents, testing the model's ability to imitate high-quality behavior.
- ExoRL: A highly challenging dataset built from unsupervised exploratory data. Because this data is diverse but predominantly sub-optimal, it tests whether a model can extrapolate and synthesize a high-performing policy without relying on perfect examples.
Key Findings and Results
Superior Performance on Sub-optimal Data
The Agentic Transformer demonstrates a profound ability to learn from imperfect data. On the D4RL benchmark, AT achieved a total average score of 85.21, outperforming the Decision Transformer (77.49) and performing competitively with state-of-the-art temporal-difference (TD) learning methods like TD3+BC (84.83).
More impressively, on the sub-optimal ExoRL dataset, AT scored 83.02, vastly outperforming both the Decision Transformer (45.51) and standard Behavior Cloning (36.11). This confirms that AT can successfully "stitch" together poor data to create a robust policy—a capability previously reserved for complex TD-learning algorithms.
In-Context Improvement and Zero-Shot Adaptation
Because AT is trained on sequences of progressively improving attempts, it learns the underlying pattern of improvement. During testing, as the model is allowed more rollouts (attempts), its average score consistently climbs. Even in zero-shot scenarios where the model is only allowed a single attempt, it still outperforms other Transformer-based policies, indicating that CoH training creates a highly robust task representation.
The Importance of the Completion Token
Ablation studies revealed that the task completion token ($d$) is critical to the model's success. Without this token, the model struggles to distinguish between successful and unsuccessful attempts in its context history, leading to a significant drop in performance.
Scaling Laws in RL
A persistent challenge in RL is scaling traditional algorithms to large neural network architectures. Because AT is a pure Transformer, it exhibits the same scaling laws observed in Large Language Models (LLMs). The authors found that increasing the model size (from "Small" to "XLarge") consistently yielded better results.
Limitations and Future Directions
While the Agentic Transformer marks a significant step forward, it comes with notable computational trade-offs:
- Computational Cost: Transformers scale quadratically with sequence length. Processing multiple trajectories simultaneously results in massive context windows (up to 20,000 tokens), requiring substantial VRAM and specialized model parallelism.
- Inference Latency: The autoregressive nature of the model, combined with its reliance on a long history of previous attempts, makes real-time inference slower compared to simple MLP-based policies.
- Data Structuring: AT currently relies on data being explicitly structured into sorted chains. Future research will need to explore how to automatically discover and construct these chains from massive, unorganized datasets.
Ultimately, the Agentic Transformer represents a highly promising step toward "foundation models for RL," demonstrating that with the right sequence modeling techniques, Transformers can master the interactive, trial-and-error nature of agentic AI.
Summary updated