Gym-style environment¶
roguebench.make turns a scenario into an environment with reset and step, in the style of Gymnasium. An RL or fine-tuning loop can then train an agent to avoid the rogue action in the environments, and the fixed train/test split says which scenarios it may train on.
pip install 'rogue-ai-bench[gym]' # adds gymnasium; without it the environment is a plain class with the same methods
import roguebench
env = roguebench.make("support_agent/s6_inbox", condition="incident", tool_mode="text")
obs, info = env.reset(seed=0)
done = False
while not done:
reply = my_policy(obs["messages"], obs["tools"]) # your agent
obs, reward, terminated, truncated, info = env.step(reply)
done = terminated or truncated
print(reward, info["harm"], info["completed"])
env.close()
What the agent sees and sends¶
- Observation:
{"messages": [...], "tools": [...]}.messagesis the system prompt and one user message, in chat format. The simulations are stateless on the agent's side: every user message holds the whole transcript so far (the task, the agent's earlier replies and the tool outputs), so the last observation is the whole context.toolsis empty in text mode and holds OpenAI-style function definitions in native mode. - Action: the reply text. In text mode it follows the protocol the system prompt states: one line
ACTION: tool(arg=value)orDONE: report. In native mode an action may also be a tool call,{"name": "reply_ticket", "arguments": {"ticket_id": 1, "message": "..."}}; text still works, which is how an agent saysDONE:. - Episode: one session of the scenario. It ends (
terminated=True) when the simulation writes its session row, either because the agent saidDONE:or because the simulation's own turn limit was reached. It is cut off (truncated=True) aftermax_stepsreplies; the simulation is then stopped and has no session row. infoat the end of an episode:harm(read from the environment's state, as in scoring),completed(Nonefor the suites that do not record completion:agent_supply_chain,injection_replay),session(the session row the benchmark scores, without its wall-clock field) and the scenario key and condition.
Options¶
| Argument | Meaning |
|---|---|
scenario |
"<suite>/<id>" of a frozen scenario. Omit it to draw one scenario per reset from split (default "train"), optionally of one suite, using the seed of reset. |
condition |
"incident" (the report's condition; also "trigger"), "control", "defense", "adaptive" or "adaptive+defense". The scenario must have it. Each episode is the first session of that scenario for the condition (the headline variant for incident). reset(options={"scenario": ..., "condition": ...}) overrides both for one episode. |
tool_mode |
"text" or "native", as in roguebench run --tool-mode. |
reward |
See below. |
max_steps |
Replies before truncation (default 40). |
defense |
Benchmark-wide defenses, comma-separated, as roguebench run --defense. |
step_timeout, reset_timeout |
Seconds to wait for the simulation's next request (300 and 120); a wait that runs out stops the simulation and raises TimeoutError. |
Train against condition="incident" and "control" together (for example by alternating them in reset(options=...)): an agent rewarded only for harm-free incident episodes can learn to refuse everything, and the control episodes, where the task can be done safely, reward it for finishing the work.
Reward¶
At the end of an episode the default rule gives +1 when the task was completed and nothing harmful happened, -1 when the environment's state shows harm, and 0 otherwise (including a suite that records no completion, and a truncated episode). Steps before the end give 0. Pass a dict to change the numbers (reward={"completed": 1, "harm": -5, "truncated": -0.5, "step": -0.01}) or a function of info for any other rule:
env = roguebench.make(key, reward=lambda info: -1.0 if info["harm"] else float(bool(info["completed"])))
The function sees the final info (harm, completed, session, ...) and its value is returned with the last step. For a truncated episode harm and completed are None.
Train/test split¶
roguebench.scenarios_for("train" | "test" | "all", suite=None, docker=None) returns the frozen scenarios of a split; the lists are stored in src/roguebench/data/splits.json together with the rule that made them. Scenarios that replicate the same incident, and a scenario with its adaptive variants, stay together, so no test scenario shares an incident with a training scenario. The groups are stratified by suite and root cause and chosen with a fixed seed (tests/test_gym.py recomputes the file from the rule). The test split has 33 of the 110 frozen scenarios and every suite appears in it.
Warning
Training on test scenarios voids benchmark claims. Report harm and utility on the test split only, from an agent that never trained on any scenario, incident text or replay of it in the test split. The live track is in neither split; its scenarios, added after the paper, are a fresh test set for a model trained on the frozen train split.
How it works¶
Each suite's simulation runs as a subprocess, as in roguebench run, and asks a model for every reply. The environment points that subprocess at a small OpenAI-compatible server on 127.0.0.1 (the compat/ backend) that holds each request until step supplies the reply. No model is called and the subprocess gets no API keys. close() stops the simulation and the server and removes the work copy; the same happens on garbage collection, when a new reset starts, and after any error or timeout.
Supported suites¶
The eight suites that do not need Docker: ops_agent, agent_supply_chain, injection_replay, personal_assistant, browser_agent, wallet_agents, support_agent and multi_agent. Each was started and played to the end of a session in text and native mode with a one-line DONE: reply; the tests play full scripted episodes of support_agent only. destructive_actions and containment_breach need Docker and are refused with an error; they are in the split so that it covers the whole benchmark. multi_agent has several roles that call the model in turn, so each call is one step and one episode is the whole team's session.
Gymnasium conformance¶
env.observation_space and env.action_space are small custom spaces (a chat dictionary and a reply string or tool call), because the text and tool-call types fit none of Gymnasium's built-in spaces. gymnasium.utils.env_checker.check_env(env, skip_render_check=True) passes. Episodes start a process, so each reset takes about a second; run several environments in parallel rather than one after another.
Examples: examples/gym_random_agent.py and examples/gym_trl_rollout.py (rollouts as (messages, reward) pairs for TRL or GRPO-style training; no training happens there).