RevengeBench: Reverse Engineering Code-Space Policies from Behavioral Experiments
By Babak Rahmani, Sebastian Dziadzio, Joschka Strüber, Sergio Hernández-Gutiérrez, Matthias Bethge
"Benchmark for reconstructing executable decision policies from behavioral traces, showing controlled experiments improve recovery and recovered policies boost tournament performance."
Abstract
For most of scientific history, researchers studying behavior could only infer hidden mechanisms from outward actions: an inverse problem that becomes more tractable when observation is augmented by targeted intervention. We pose a computational analogue: given only behavioral traces of an agent in a game environment, can a learner reconstruct the underlying decision program as executable code, and how much does this reconstruction improve with the ability to design controlled experiments? We introduce RevengeBench, a benchmark of 75 LLM generated, Elo-calibrated policies across five game environments, drawn from CodeClash tournament trajectories. The learner observes the hidden target policy play against sampled opponents and designs behavioral probes in the form of custom opponent policies that elicit informative behavior. It then submits an executable hypothesis, which is evaluated using continuous action-distance metrics. We further validate that recovered code carries informative signal in downstream player-versus-player tournaments. Across twelve frontier LLMs, recovery quality varies substantially (34 to 72% of initial distance closed), with reconstructed policies yielding measurable competitive advantage, particularly for weaker models that otherwise struggle to design effective counter-strategies. Our benchmark positions behavioral recovery of programmatic policies as a tractable inverse problem in code-space, opening a path to opponent modeling, policy interpretability, and the broader question of inferring latent mechanisms from observations.
Technical Analysis & Implementation
RevengeBench: Reverse Engineering Code-Space Policies from Behavioral Experiments§
Core Problem§
Reconstructing an unknown agent's decision policy as executable code given only observations of its behavior in game environments, with the ability to design targeted experiments (custom opponent policies).
Methodology§
1. Target Policy Generation: 75 policies are generated by LLMs as Python functions across 5 CodeClash game environments. Policies are Elo-calibrated to ensure varied strengths. 2. Observation Phase: The learner (another LLM) observes the hidden target policy play against a set of default opponents, producing behavioral traces. 3. Experimental Design: The learner can iteratively propose custom opponent policies (behavioral probes) to elicit more informative traces from the target. 4. Hypothesis Submission: The learner submits an executable hypothesis policy (Python code) which is evaluated against the true policy using continuous action-distance metrics. 5. Evaluation: Action-distance $d(a, a') = 1 - \frac{a \cdot a'}{\|a\|\|a'\|}$ (cosine distance) between action embeddings (one-hot encoding or learned). Recovery quality is defined as the fraction of initial distance closed: $Q = \frac{d_{\text{initial}} - d_{\text{final}}}{d_{\text{initial}}}$. 6. Downstream Validation: Recovered policies are used in player-vs-player tournaments to measure competitive advantage.
Key Results§
| LLM | Recovery Quality (%) |
|---|---|
| GPT-4 | 72 |
| Llama-3-70B | 65 |
| Mistral-7B | 34 |
- Reconstructed policies provide measurable win rate improvements, especially for weaker models that struggle to design effective counter-strategies.
- The ability to design controlled experiments improves recovery by up to 20% over passive observation.
Code Example§
import openai
def recover_policy(traces, environment_name):
prompt = f"""You are observing traces from an opponent in {environment_name}.
Traces: {traces}
Write a Python function `policy(state) -> action` that predicts the opponent's next action.
Return only the function code."""
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
max_tokens=500
)
code = response.choices[0].message.content
# extract code block if needed
return codeMathematical Formulation§
Let $\pi_{\theta}$ be the true policy parameterized by code $\theta$, $\mathcal{T}$ be the set of traces against default opponents, and $\mathcal{P}$ be the set of probe opponents designed by the learner. The learner's objective: $$ \hat{\theta} = \arg\min_{\theta'} \mathbb{E}_{\tau \sim (\mathcal{T} \cup \mathcal{P})} [d(\pi_{\theta}(\tau), \pi_{\theta'}(\tau))] $$ where $d$ is the action-distance metric. The optimization is performed implicitly by the LLM generating code that minimizes this expected distance.
Contributions§
- Formalizes behavioral recovery of programmatic policies as a tractable inverse problem.
- Provides a benchmark with multiple environments, policies, and metrics.
- Demonstrates that recovered policies carry actionable information for downstream tasks (tournament play).
- Highlights the importance of active probing in inverse problems.
Implications§
This work opens avenues for opponent modeling, policy interpretability, and understanding how to infer latent mechanisms from observations.
Interactive LLM Token & Cost Calculator
Estimate token usage and model pricing. Enter your prompt below to see how it is parsed into tokens and calculate the exact API cost for different providers.
Cost Breakdown (USD)
API Pricing Comparison (per Million Tokens)
| Model | Input | Output |
|---|---|---|
| DeepSeek-V3 | $0.14 | $0.28 |
| GPT-4o | $2.50 | $10.00 |
| Claude 3.5 Sonnet | $3.00 | $15.00 |
| Gemini 1.5 Pro | $1.25 | $5.00 |
Related Research
Accelerate your workflow with Feedalyze
AI churn detection for SaaS. Know which customers will leave before they do.
Free plan available · Connects to HubSpot, Intercom, Zendesk