File size: 7,315 Bytes
fd5366a 3398b71 fd5366a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | ---
license: mit
tags:
- agent-safety
- world-models
- causal-inference
- reproducibility
- code
---
# CLSA — code for "Causal Latent-State Agents"
This repository is the released code for *Causal Latent-State Agents: Pre-Action
Safety from a World Model You Can Audit* (submitted to *Artificial Intelligence*,
Elsevier). It is a mirror of the repository accompanying the submission, at
commit `d4089a9` (2026-11-25).
It contains the analysis code, the configuration, the tests, the result files and
the figure scripts. The benchmark and the trained artefacts are in two companion
repositories:
| What | Where |
|---|---|
| PreAct-Bench: 4,508 pre-action decision points, images, schema, data card | [fahadhafeezofficial/preact-bench](https://huggingface.co/datasets/fahadhafeezofficial/preact-bench) |
| Trained artefacts for both backbones (transcoder, world model, risk head, monitors) | [fahadhafeezofficial/clsa-artifacts](https://huggingface.co/fahadhafeezofficial/clsa-artifacts) |
## Layout
| Path | Contents |
|---|---|
| `src/clsa/` | Package: sandbox, transcoder, world model, risk head, controller, monitors |
| `experiments/` | E1–E9 and `check_numbers.py`, which traces every table value back to `results/` |
| `tiers/` | Standalone smoke tests for the three adoption tiers |
| `tests/` | Test suite (31 tests) |
| `configs/` | Frozen experiment configuration |
| `results/` | Result JSON/JSONL files behind every number in the paper |
| `figures/`, `paper/` | Figure scripts and LaTeX source |
| `hf/` | Scripts that published these three repositories |
## Running it
```bash
python -m pip install -r requirements.txt
export PYTHONPATH=src
make test # 31 tests
python experiments/check_numbers.py # 103 table values traced to results/
```
Full reproduction of the benchmark and the artefacts needs the two companion
repositories:
```bash
hf download fahadhafeezofficial/preact-bench --repo-type dataset --local-dir data/preact_bench
hf download fahadhafeezofficial/clsa-artifacts --repo-type model --local-dir data/derived
make reproduce # bench + experiments + figures + number check
```
The derived artefacts must sit in `data/derived/<backbone with "/" as "__">`,
which is the layout the artefacts repository already uses and the only layout
`load_model()` resolves; there is no environment variable for that path.
Everything runs on a CPU, with no GPU, no paid API and no vendor SDK.
## Licence and citation
MIT (see `LICENSE`). Citation metadata is in `CITATION.cff`.
---
## Project README
## CLSA — Causal Latent-State Agents
A causal multimodal world model for agent planning, with a benchmark, a
certificate format and an evaluation protocol that can be reproduced on a laptop.
Adoption by any laboratory is not claimed. The work is designed for adoption:
lab-agnostic, open-weight first, and reproducible in one command.
## The problem
Agents act before they understand consequences. A language model can describe a
risk and still take it, because describing is not simulating. CLSA separates the
two: a trajectory transcoder turns the backbone's internal state into a discrete,
auditable latent state; a causal dynamics model predicts what each candidate
action would do to that state; and a controller acts only when a calibrated,
state-verified certificate can be written.
## What is in this repository
| Piece | Path | What it gives you |
|---|---|---|
| Benchmark | `data/preact_bench/` | PreAct-Bench: 4,508 decision points, 120 episodes, 4 tool families, fork-replayable labels |
| Transcoder | `src/clsa/transcoder/` | Top-k sparse transcoder + Tiwari admission rule |
| World model | `src/clsa/world_model/` | Causal dynamics, risk head, four losses, CPU training |
| Controller | `src/clsa/controller/` | Latent MPC, five modes, certificates, charged budget |
| Evaluation | `src/clsa/eval/` | E1–E9, paired and cluster bootstrap, state-verified labels |
| Tiers | `tiers/` | Three adoption tiers, each with install, quickstart and test |
| Paper | `paper/` | LaTeX draft, pre-registration, verified bibliography, JISC venue plan |
## Quickstart
```bash
python -m pip install -r requirements.txt
export PYTHONPATH=src
make bench # rebuild + audit the benchmark
make experiments # run E1-E9 against cached artefacts
make figures # regenerate every figure
make test # test suite
```
Full training from raw model weights (needs ~1.6 GB of open-weight downloads):
```bash
make train
```
One command for the whole path: `make reproduce`.
## Tiers
1. **Drop-in monitor** (`tiers/tier1_dropin_monitor`) — pre-action probe and
calibrated gate. No retraining, no world model. Target: under 0.1% added
latency; the measured value is reported, met or not.
2. **World-model controller** (`tiers/tier2_world_controller`) — latent rollouts,
MPC and certificates. Needs a few hundred trajectories.
3. **Full CLSA** (`tiers/tier3_full_clsa`) — full counterfactual training,
multi-agent beliefs, distillation.
## Scope, stated plainly
- Everything here ran on a **CPU-only laptop** (Ryzen 5 7530U, 15.4 GB RAM, no
CUDA). The primary backbone is `Qwen2.5-0.5B-Instruct`; a second backbone
(`SmolLM2-360M-Instruct`, 200 states) is used for a cross-backbone replication.
The pipeline replicates there (harm 0.000 against 0.290) but the calibrated
threshold does not transfer (probe-score correlation 0.075), so E6 reports both
the transferred and the recalibrated gate. No 7B-class model was run.
- The benchmark is an in-repository deterministic sandbox, not a re-hosted
AgentDojo or τ-bench. Adapters exist; external splits were not executed.
- Every number in the paper traces to a file in `results/`; `make reproduce`
checks that. Unverified citations are marked index-only and never quoted.
- Hypotheses and thresholds were frozen in `PRE_REGISTRATION.md` and committed
at `7d3946a` before the main runs. Deviations are logged there.
See `LIMITATIONS.md` for what this work does not show, and `PROGRESS.md` for the
build log.
## Released artefacts
- **Dataset:** [`fahadhafeezofficial/preact-bench`](https://huggingface.co/datasets/fahadhafeezofficial/preact-bench)
— 4,508 rows, GUI images, schema, data card (MIT).
- **Checkpoints:** [`fahadhafeezofficial/clsa-artifacts`](https://huggingface.co/fahadhafeezofficial/clsa-artifacts)
— transcoder, world model, risk head and monitors for both backbones.
- **Code:** [`fahadhafeezofficial/clsa-code`](https://huggingface.co/datasets/fahadhafeezofficial/clsa-code)
— this repository, mirrored at the commit the paper cites (MIT).
Republish with `python hf/publish.py` (stages from `data/` and pushes to the
account you are logged in as; `--dry-run` builds the folders only, and
`--code-only` refreshes the code mirror alone).
```python
from datasets import load_dataset
ds = load_dataset("fahadhafeezofficial/preact-bench", split="train")
```
## Licence
MIT. See `LICENSE`. Every source file carries an SPDX header.
## Citation
See `CITATION.cff`. Paper: Fahad Hafeez, Newcastle University
(ORCID 0009-0003-7903-7382).
|