Robust In-Context Reinforcement Learning Under Reward Poisoning Attacks

Paulius Sasnauskas†,1,2, Yiğit Yalın3, Goran Radanović3

This work was done as a part of an internship project at MPI-SWS.
1Department of Computing Science, University of Alberta, Edmonton, Canada.
2Alberta Machine Intelligence Institute (Amii), Edmonton, Canada.
3MPI-SWS, Saarbrücken, Germany

PDF: arxiv.org/pdf/2506.06891

Published at ICML 2026. Code: github.com/PauliusSasnauskas/AT-DPT

Conference page: icml.cc/virtual/2026/poster/61251

TL;DR

In-context RL agents like the Decision-Pretrained Transformer (DPT) learn a learning algorithm from the rewards in their context – which means an attacker can steer them at test time just by poisoning those rewards. We introduce AT-DPT (Adversarially-Trained DPT), which trains a population of attackers to corrupt rewards while the agent learns to recover. AT-DPT stays robust across a wide range of attacks – including ones it never saw during training – and substantially outperforms standard and corruption-robust bandit/RL baselines.

Abstract

We study the corruption-robustness of in-context reinforcement learning (ICRL), focusing on the Decision-Pretrained Transformer (Lee et al., 2023). To address the challenge of reward poisoning attacks targeting the DPT, we propose a novel adversarial training framework, called Adversarially Trained DPT (AT-DPT). Our method simultaneously trains a population of attackers to minimize the true reward of the DPT by poisoning environment rewards, and a DPT model to infer optimal actions from the poisoned data. We evaluate the effectiveness of our approach against standard bandit algorithms, including robust baselines designed to handle reward contamination. Our results show that AT-DPT significantly outperforms them in bandit settings under a learned attacker, and generalizes to more complex environments such as adaptive attackers and MDPs. It shows promise in ICRL as a meta-RL approach to learning effective corruption-robust algorithms.

Problem: Poisoning the Learning Algorithm, Not the Policy

Most prior work on reward poisoning attacks targets the canonical RL setting: an attacker corrupts rewards during training to change the fixed policy an agent eventually adopts. These are training-time attacks, and they assume the agent's test-time behavior no longer depends on rewards.

In-context RL breaks that assumption. An ICRL agent implements a learning algorithm in-context: its context encodes past interactions, including rewards, and it adapts its behavior on the fly. So an adversary who corrupts rewards at test time can still influence the agent – effectively attacking the learning algorithm running inside the transformer's context. To our knowledge, this is the first study of reward poisoning in meta-RL.

Attack Model

We use Huber's ε-contamination model: at each timestep, with probability ε the agent observes a corrupted reward produced by the attacker instead of the true reward. The attacker sees the true reward (and, if adaptive, the agent's recent interactions) and aims to minimize the agent's true return under a soft budget constraint (a penalty term, with budget B). We focus on non-behavior-targeted attacks – the attacker wants to hurt return, not force a specific policy.

Method: AT-DPT

Overview of the AT-DPT training procedure: the AT-DPT agent and a population of per-task attackers are trained simultaneously. Attackers corrupt the rewards the agent sees, while the agent learns to predict optimal actions from the poisoned data.
We use adversarial training to optimize the parameters θ of a transformer model, which is our learning agent. In each round, we first collect data by deploying the agent in m environments. In environment i, the agent observes rewards corrupted by an adversary defined by parameters φi. We collect clean () and corrupted (D) datasets containing trajectories with clean and corrupted rewards, respectively. The agent is trained to predict an optimal action for a query state given a context sampled from a corrupted dataset. The adversary is trained to minimize the agent's return under a soft budget constraint, expressed as a penalty term. During the test phase, the agent is deployed in a new corrupted environment.

AT-DPT combines in-context learning with adversarial training. Building on DPT (a GPT-2-style transformer trained to predict optimal actions from context), we add an adversarial training stage between pretraining and deployment. We frame robust ICRL as approximately solving a bi-level game and search for a Nash equilibrium between the agent and a per-task attacker.

Training proceeds in three phases:

  1. Pretraining. A GPT-2 model is trained by supervised learning to predict an oracle's optimal action from a context dataset and a query state (the original DPT objective).
  2. Adversarial training. For each of M sampled tasks, a dedicated attacker is trained with REINFORCE to minimize the agent's true return under the budget penalty, while the agent is simultaneously trained to predict optimal actions from the poisoned context. The agent sees corrupted rewards; the attacker sees clean rewards. This repeats for N rounds.
  3. In-context deployment. The frozen agent is deployed in a new, corrupted environment. Unlike the original DPT, context is updated after every timestep (not just per-episode), which supports robustness against adaptive attackers.

We consider direct-parameterized non-adaptive attackers (per-arm or per-state-action reward shifts) and adaptive attackers that use the same transformer architecture as the victim to react to its defenses.

Results

We evaluate on multi-armed bandits, linear bandits, and MDPs (Darkroom2 and the 3D Miniworld navigation environment), comparing against standard and corruption-robust baselines. To avoid testing on the exact attack seen during training, attackers are cross-validated across seeds. All numbers are mean ± 95% confidence interval (2×SEM) over 10 replications, at ε = 0.4.

Bandit Setting – Cumulative Regret (lower is better)

Each column is the algorithm the attacker was trained against (the "attacker target"). AT-DPT keeps low regret no matter which method the attack was tuned for – including attacks targeting other algorithms – while the baselines blow up under a learned attack. Budget B = 3.

Cumulative regret per round over 20 rounds of adversarial training. AT-DPT's regret first spikes then steadily falls as it learns to recover from the attack, while frozen DPT and Thompson sampling stay high.
Adversarial training makes DPT robust. Comparison of the cumulative regret per round (lower is better) of different methods throughout 20 rounds of adversarial training (simultaneously learning AT-DPT and attackers) in the bandit setting. Mean and 95% CI over 10 experiment replications. Attack budget B = 3, ε = 0.4.
Algorithm Attacker Target Unif. Rand.
Attack
Clean Env.
AT-DPT DPT TS RTS* UCB crUCB*
AT-DPT 24.2 24.8 29.8 28.3 24.5 23.8 38.7 13.0
AT-DPT (sub. 30%) 41.2 41.9 45.7 43.6 41.6 41.0 47.8 25.9
DPT 63.6 59.4 62.0 59.1 55.4 58.8 37.2 11.5
TS 106.3 97.7 94.3 93.1 89.6 92.6 34.2 8.7
RTS* 102.9 97.0 90.4 92.5 89.2 89.0 33.9 10.2
UCB 104.1 95.8 90.6 90.0 88.1 91.2 38.1 16.0
crUCB* 86.0 85.0 82.0 82.4 79.4 82.5 31.8 15.8

*We use tuned versions of RTS and crUCB which outperform base versions

Linear Bandit Setting – Cumulative Regret (lower is better)

Here the gap is dramatic: under a learned attack AT-DPT reaches regret around 2–3 while every baseline sits at 35–70 – an improvement of more than 90% – and AT-DPT still matches the corruption-robust CRLinUCB in the clean case. Budget B = 3.

Algorithm Attacker Target Unif. Rand.
Attack
Clean Env.
AT-DPT DPT LinUCB CRLinUCB*
AT-DPT 2.49 2.50 2.83 1.79 5.33 3.89
DPT 70.29 71.42 70.83 63.84 6.62 3.35
LinUCB 37.69 35.93 35.22 34.82 5.21 3.51
CRLinUCB* 37.45 33.03 35.56 35.36 5.12 2.94

MDP Setting – Darkroom2, Average Episode Reward (higher is better)

In a sparse-reward 2D gridworld with two goals, AT-DPT stays robust across attackers, with the task-specific NPG coming closest. Note that NPG and Q-learning are run for 100 episodes per task before evaluation, whereas AT-DPT infers the task in-context almost immediately. Budget B = 10.

Algorithm Attacker Target Unif. Rand.
Attack
Clean Env.
AT-DPT DPT NPG Q-learning
AT-DPT 242.2 267.5 241.7 239.1 258.2 267.4
AT-DPT (sub. 10%) 225.2 245.5 226.1 222.7 241.3 250.2
DPT 216.1 143.5 202.6 205.9 266.2 306.8
NPG§ 237.2 243.7 228.9 228.1 235.3 241.7
Q-learning§ 198.1 238.6 215.4 224.7 229.0 225.6

§NPG and Q-learning need multiple episodes of learning to converge to a stable policy; we run them for 100 episodes before evaluating performance.

AT-DPT also displays similar results in the 3D Miniworld visual-navigation environment, where it again stays more robust than DPT and a trained PPO agent.

Why It Works

Why It Matters

Robustness to test-time poisoning is increasingly important for any agent that learns in-context. A prime example is LLM-based agents, whose context can be poisoned through external tools or retrieval (RAG) – and LLMs have themselves been shown to exhibit ICRL behavior. By learning a learning algorithm that is inherently robust and that exploits prior knowledge of the task distribution, AT-DPT points toward more efficient, corruption-robust decision-making agents.

Limitations and Future Work

Acknowledgements

This research was, in part, funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – project number 467367360. We acknowledge the use of computing resources generously provided by MPI-SWS.