Intervention type x graph region x density bucket.
Causal Inference via Adversarial Self-Play
An RL agent that doesn't just detect contamination โ it infers the hidden causal intervention behind it. Trained via adversarial self-play where an adversary learns to hide better as the investigator reasons better.
Watch the fine-tuned Qwen2.5-0.5B model investigate a supply-chain contamination in real-time. The model was trained via SFT on 3,500 expert demonstrations using Unsloth + TRL.
Run the deterministic baseline on OpenEnv tasks
The RecallTrace Hugging Face Space operates as a Python-based Gradio application hosting an OpenEnv-compliant causal inference benchmark. At its core, the system runs a two-agent adversarial self-play loop. In this environment, an Investigator must identify and isolate a hidden contamination event within a procedurally generated, partially observable supply graph. An opposing Adversary intelligently places these interventions to maximize the Investigator's failure rate. The environment enforces an ungameable, composable reward function that computes a final score based on Recall (catching unsafe nodes), Precision (sparing safe nodes), Belief Calibration (making confident decisions), and Efficiency (using fewer steps).
The Heuristic Investigator serves as an interpretable, fast-adapting baseline. Instead of neural networks, this agent uses dynamic, rule-based heuristics governed by learnable thresholds (e.g., quarantine confidence limits and "trust" in ambiguous lab results). After every episode, the agent calculates its F1 score (the harmonic mean of its precision and recall accuracy). If the F1 score dips, the agent adjusts its internal thresholds using an Exponential Moving Average (EMA). This allows the heuristic search to continuously tune its exploration and exploitation strategies dynamically, finding optimal paths through the causal graph with a very low computational footprint.
The PyTorch RL Investigator is powered by a Deep Reinforcement Learning policy network. Because the environment's observation space is variable (graphs change size, inventory fluctuates), the architecture utilizes a StateEncoder to map the raw observation dictionaries into a fixed 112-dimensional feature tensor. This tensor is fed into a Multi-Layer Perceptron (MLP) equipped with three distinct output heads: an Action Head (to select one of the 7 tools), a Node Head (to target a specific node), and a Value Head (to predict the baseline reward). The model is trained using the REINFORCE algorithm. To ensure stable learning, the Value Head serves as a learned baseline to reduce variance, while an underlying entropy regularization coefficient forces the model to maintain exploration, preventing it from collapsing into trivial behaviors like quarantining every node immediately.
As the Investigator improves, the training environment shifts with it. The Adversary samples harder scenarios, then backs away from cells the Investigator has already mastered.
Cross-references intervention type, graph region, and density bucket.
Samples attacks probabilistically so the adversary keeps trying fresh patterns.
Expertly solved scenarios become less likely, pushing the curriculum forward.
F1 improves as the policy identifies hidden interventions more precisely.
Successful cells are penalized and unexplored regions gain sampling pressure.
Matplotlib continuously records accuracy, loss, reward, and adversary success.
Tracks the agent's expanding accuracy across episodes.
Compares REINFORCE policy loss against reward.
Shows the arms race: adversary success dips as Investigator capability rises.
Belief state tracking with P(contaminated) per node. Agent maintains probabilistic world model and reasons under uncertainty.
Investigator and Adversary modules share the same environment loop, reward function, telemetry buffer, and PyTorch policy architecture.