When a language-model agent solves a multi-step tool-use benchmark, we cannot tell whether it read each tool's output and reasoned about what to do next, or whether it replayed an action sequence it saw during training. The standard contamination detectors cannot answer this for agents. These detectors flag test items the model assigns unusually high probability. They were built for single question–answer pairs, and recent work shows they fail even there once a model has gone through reinforcement learning (RL). This note proposes a behavioral test instead of a likelihood test. We replay a benchmark task, but at one step we change what the tool returns so that the correct next action changes. An agent that tracks the task's state follows the change. An agent replaying a memorized trajectory keeps doing what the original trajectory did.
The auditing tool comes from security, where multi-stage attacks are tracked by inferring hidden stages from noisy events. We treat "tracking" and "replaying" as two hidden regimes of the agent's behavior. A small hidden Markov model (a probabilistic model in which an unobserved mode switches over time and each mode produces observed actions differently) infers, step by step, which regime the agent is in. The output is a per-item contamination score. It also shows where in a trajectory memorization takes over. It needs only the agent's actions, so it works for closed models, and it should not be affected by the log-probability compression that hides contamination after RL.
Core Claim
Memorizing a trajectory leaves a signature in behavior: the agent's actions stop depending on the observations they should depend on. This signature can be measured by counterfactual observation edits that a formal state machine of the task certifies as action-changing. It can be scored with a two-regime sequential model, and it separates seen from unseen agent tasks in settings where likelihood detectors and entropy-based self-critique are at chance. Three things are new: the detection target (multi-step, state-dependent agent trajectories rather than static items), the signal (observation-insensitivity under certified perturbations rather than token probability), and the use of stage-tracking models from security as the scoring layer.
Why the gap is real
The contamination literature supplies the motivation and the main constraint. On The Fragility of Benchmark Contamination Detection in Reasoning Models shows that one epoch of clean GRPO, an RL method whose clipped policy updates compress loss differences, drives likelihood detectors toward chance. After chain-of-thought contamination of a distilled reasoning model, ten detectors average 50–58% AUROC. This rules out any design that reads contamination from token probabilities. Detecting Data Contamination from Reinforcement Learning Post-training for Large Language Models argues that RL collapses the policy along rewarded trajectories and detects this by comparing entropy profiles of a model's original and "alternative" solutions. It is the closest detector to ours. It still reads an internal statistic of a single reasoning sequence, and both papers test only single-turn math and logic problems.
Our proposal takes the policy-collapse idea seriously but measures its external consequence. A collapsed policy should also ignore environment feedback that contradicts its preferred path.
The agent-benchmark literature shows why this matters. TRAJECT-Bench builds sequential chains over 1,228 public RapidAPI endpoints and notes that agents reach correct answers through parametric memory despite wrong tool calls. Because the benchmark is public, it is exposed to future training scrapes. FuncBenchGen avoids contamination by generating random function graphs with meaningless identifiers. It finds that the dominant failure is state tracking: using variables that were never produced, or carrying stale values forward. Neither paper detects contamination. FuncBenchGen prevents it by giving up semantics, and TRAJECT-Bench keeps semantics and accepts the exposure. A detector that works on semantic, public benchmarks is the missing piece.
The security literature supplies the method. Gaudenzi et al. constrain a recurrent network's predictions with a reward machine, a finite-state machine encoding which transitions are legal, such as "no exfiltration before data access." Hidden Markov models that map system-call streams to attack stages (AbuOdeh et al.; Wang et al.) show how to infer a hidden mode from noisy, interleaved events. We reuse both ideas. The reward machine defines what a state-tracking agent must do after an edit. The hidden Markov model infers which regime the agent is in. On the Evaluation of Sequential Machine Learning for Network Intrusion Detection warns that sequence models are fooled by interleaved innocuous events. That warning shapes our control perturbations: benign edits that should not change the correct action.
Research Program
Task state machines. For every benchmark item we build a task state machine. On FuncBenchGen this is exact: the state is the set of resolved variables in the dependency graph, and the legal next actions are the functions whose inputs are all resolved. On TRAJECT-Bench sequential chains, the state is the set of tool outputs obtained so far, and transitions follow the ground-truth dependency where the output of tool A fills an argument of tool B. We extend this with the abstention transitions studied in the ICT dataset (Can Tool-augmented Large Language Models be Aware of Incomplete Conditions?), for example "if a required value is missing, ask or abstain."
Perturbation families. We define three families of edits to tool outputs, applied at a single step $k$. Value edits change a returned field that feeds a later argument, so the correct later call changes. Branch edits return an error or an empty result, so the correct action becomes retry, an alternative tool, or abstention. Benign edits change a field no later step uses, so the correct action stays the same. The state machine certifies each edit's class automatically. Edited items stay semantically natural because only tool outputs change; the user query and the API documentation do not.
Two-regime scoring model. At each step $t$ after the edit, let $a_t$ be the agent's action. Let $s_t$ be the action the state machine prescribes given the edited observations. Let $m_t$ be the action in the original ground-truth trajectory. Steps where $s_t \neq m_t$ are the informative ones. A hidden mode $z_t \in \{\text{track}, \text{replay}\}$ evolves with a sticky transition probability $\rho$ of staying in the same mode. The emission model is
$$ P(a_t \mid z_t=\text{track}) = \epsilon_\text{err} + (1-\epsilon_\text{err})\,\mathbb{1}[a_t=s_t], \qquad P(a_t \mid z_t=\text{replay}) = \epsilon_\text{err} + (1-\epsilon_\text{err})\,\mathbb{1}[a_t=m_t], $$
where $\epsilon_\text{err}$ absorbs actions that match neither prescription. The item's contamination score is the posterior probability of the replay mode averaged over informative steps. We fit $\rho$ and $\epsilon_\text{err}$ per model by expectation-maximization on items that the model provably has not seen: freshly generated FuncBenchGen graphs, and TRAJECT-Bench items released after the model's data cutoff where available.
Calibration against weak but clean agents. Calibrating on each model's own unseen items is the key design choice. A weak or over-eager agent also ignores observations; ICT documents exactly this "action bias." Raw insensitivity therefore measures incompetence as much as memorization. Scoring relative to the model's own insensitivity rate on unseen items, much as LiRA compares against reference behavior, isolates the contamination-specific part. The posterior over $z_t$ also localizes the switch: a trajectory that tracks for two steps and then replays suggests the agent memorized only the tail. Aggregate pass-rate comparisons cannot show this.
Baselines
Naive reference points. The do-nothing reference is chance, 0.50 AUROC. The trivial behavioral reference is raw final-answer or trajectory exact-match accuracy used as the membership score. Contaminated items should score higher, but so do easy items.
Likelihood detectors. The standard detectors are Loss, Min-K%, and LiRA computed over the tokens of the agent's trajectory. We run them on the same models and item splits. LiRA gets reference models trained on the same budget as our calibration set. The file reports LiRA at 89.1% AUROC before RL and a drop of about 14% after one epoch of clean GRPO (On The Fragility of Benchmark Contamination Detection in Reasoning Models). Perplexity and Min-K% sit at 0.42–0.53 AUC on RL-phase contamination (Detecting Data Contamination from Reinforcement Learning Post-training for Large Language Models).
Self-Critique. The strongest existing method is Self-Critique from Detecting Data Contamination from Reinforcement Learning Post-training for Large Language Models. It reports an average AUC of 0.70 on Qwen2.5-7B-Instruct and 0.64 on DeepSeek-Math-7B-Instruct on RL-MIA, 19% above the best baselines on average. We adapt it to agents by asking the model for an alternative tool plan and comparing entropy sequences with its length penalty. It gets the same number of model queries as our method: one original rollout plus the perturbed rollouts. For agent benchmarks, no reported result was found on Lacuna for contamination detection on TRAJECT-Bench or FuncBenchGen. Its agent-setting number will therefore be ours to measure. Beating it means a higher item-level AUROC on the post-RL condition with non-overlapping bootstrap intervals, at equal query budget.
Observation-prediction probe. This probe asks the agent to predict a tool's output before calling it. A model that memorized trajectories may reproduce the recorded outputs.
Ablations. Two ablations isolate our key ingredients. The first drops the two-regime model and scores raw insensitivity: the fraction of informative steps where $a_t = m_t$. The second drops per-model calibration. If the uncalibrated version does as well, the sequential model is unnecessary. If it does much worse on weak models, the calibration is doing the work.
Why not just…?
Why not just compare scores on the original benchmark against freshly generated or refactored variants? This is the EvoEval approach behind the 39.4% average drop reported in Benchmark Data Contamination of Large Language Models: A Survey. It is a real threat at the level of a whole model: if one only wants to know whether a model is contaminated at all, a fresh-versus-original delta may suffice, and we will report it. It has two limits. It gives no item-level membership, and any difficulty shift between old and new items confounds it. Our edits change one tool output while holding the query, documentation, and depth fixed, so difficulty is controlled. We will check whether the model-level delta and the mean of our item scores agree. If they always agree and item-level scores add nothing to downstream uses, such as cleaning a leaderboard, our method's value shrinks to diagnosis.
Why not just run the observation-prediction probe? It is simpler and needs no state machine. It may work well after supervised contamination, where recorded tool outputs are in the training text. After RL, models are rewarded for actions rather than for reproducing observations, and the Fragility results suggest verbatim reproduction weakens after RL. We therefore expect the probe to degrade after GRPO while action-level insensitivity persists. The experiment directly tests this prediction, and if the probe holds up we will report it as the preferred cheap detector.
Why not just watermark the benchmark? Detecting Benchmark Contamination Through Watermarking reaches $p=10^{-5}$ at a 5% score inflation, but only for text questions marked before release. It cannot audit TRAJECT-Bench, ToolBench, or API-Bank, which are already public. Its signal also rides on token statistics, which RL is known to flatten. For new benchmarks, watermarking and our test complement each other.
Why not just add a state reminder and check if performance changes? FuncBenchGen's variable reminder raises GPT-5 from 62.5% to 81.3%. That shows the reminder helps state tracking, not that the agent was replaying. Both a memorizing agent and a forgetful clean agent could gain from it, so it does not separate the two hypotheses our edits are designed to separate.
Proposed Experiments
Controlled contamination. We fine-tune Qwen2.5-7B-Instruct, the model used by both RL-contamination papers, on ground-truth trajectories for a random half of TRAJECT-Bench sequential items and on FuncBenchGen graphs. The other half is held out. We then test three conditions: after fine-tuning only, after an additional epoch of clean GRPO on unrelated tool tasks (the cloaking setting), and after GRPO applied to the contaminated items themselves (RL-phase contamination, as in RL-MIA). We vary contamination exposure count and chain length from 3 to 5 tools, the range where TRAJECT-Bench reports its performance collapse.
Primary metrics. The primary metric is item-level AUROC for seen versus unseen items. Secondary metrics are true-positive rate at 5% false-positive rate and the accuracy with which the replay-mode posterior identifies the step where memorized content begins. We test localization using trajectories contaminated only from step $k$ onward.
Decisive checks. Four results would each change the conclusion. First, the method must stay well above chance in the post-GRPO condition where Loss, Min-K%, and LiRA collapse; if it collapses too, the behavioral signal is not independent of the likelihood signal and the core claim fails. Second, benign edits must produce no seen/unseen difference; a difference there means the detector is responding to perturbation artifacts, not memorization. Third, on a deliberately weakened clean model, such as a smaller Qwen variant with no contamination, the calibrated score must stay near chance while the raw insensitivity score rises. This check separates memorization from ICT-style over-eagerness. Fourth, as external validity without planted contamination, we apply the calibrated detector to off-the-shelf open models on TRAJECT-Bench and on freshly generated FuncBenchGen graphs. A trustworthy detector should flag essentially nothing on the fresh graphs. On TRAJECT-Bench, any flags should concentrate on items built from older, widely documented APIs.
References
- On The Fragility of Benchmark Contamination Detection in Reasoning Models
- Detecting Data Contamination from Reinforcement Learning Post-training for Large Language Models
- TRAJECT-Bench:A Trajectory-Aware Benchmark for Evaluating Agentic Tool Use
- Towards Reliable Benchmarking: A Contamination Free, Controllable Evaluation Framework for Multi-step LLM Function Calling
- Towards Cyber Resilience against APTs
- A Novel AI-based Methodology for Identifying Cyber Attacks in Honey Pots
- AARF: Autonomous Attack Response Framework for Honeypots to Enhance Interaction Based on Multi-Agent Dynamic Game
- On the Evaluation of Sequential Machine Learning for Network Intrusion Detection
- Can Tool-augmented Large Language Models be Aware of Incomplete Conditions?
- Benchmark Data Contamination of Large Language Models: A Survey
- Detecting Benchmark Contamination Through Watermarking