File size: 5,527 Bytes
608ecfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52bd961
608ecfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52bd961
 
 
608ecfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52bd961
 
 
 
 
 
 
 
 
608ecfa
 
 
 
 
 
 
 
 
52bd961
 
608ecfa
 
52bd961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608ecfa
 
 
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
---
license: apache-2.0
pretty_name: ContextBench
language:
- en
tags:
- agents
- long-context
- context-management
- benchmark
size_categories:
- n<1K
configs:
- config_name: all
  default: true
  data_files:
  - split: test
    path: data/*.parquet
- config_name: kv_store
  data_files:
  - split: test
    path: data/kv_store.parquet
- config_name: log_triage
  data_files:
  - split: test
    path: data/log_triage.parquet
- config_name: needle_retention
  data_files:
  - split: test
    path: data/needle_retention.parquet
- config_name: sudoku_sketchpad
  data_files:
  - split: test
    path: data/sudoku_sketchpad.parquet
---

# ContextBench

ContextBench measures what an agent keeps, updates, and offloads when its input does
not fit in its context window. Each task streams a sequence of operations as ordinary
user turns, more than the context budget holds, and the reward is read from the
agent's own messages: what survived in its context, not what it wrote to disk.

Paper: [Context Language Models](https://arxiv.org/abs/2609.37725) ([paper page](https://huggingface.co/papers/2609.37725))

## Families

| config | task | reward |
|---|---|---|
| `kv_store` | batches of `SET key = value`, then `GET key` queries | fraction of GETs answered with the right value |
| `log_triage` | batches of service log lines, then count and lookup questions | fraction of questions answered correctly |
| `needle_retention` | chunks with a few needle lines inside a large filler block | fraction of needle lines still present verbatim |
| `sudoku_sketchpad` | one fully specified move per turn on a 16x16 board | fraction of gold board versions the agent displayed |

The `all` config holds every instance. This release has 256 instances:
64 `kv_store`, 56 `log_triage`, 80 `needle_retention`, 56 `sudoku_sketchpad` (32 levels, seeds 42-49), with a context budget of 32768 tokens
and a reserve of 2048.

## Columns

| column | type | meaning |
|---|---|---|
| `task_id` | string | `<family>-<level>-seed<seed>`, also the Harbor task directory name |
| `family` | string | task family |
| `level` | string | difficulty level |
| `seed` | int | generator seed |
| `budget` | int | context budget in tokens |
| `reserve` | int | tokens reserved for the reply; the agent may use `budget - reserve` |
| `n_ops` | int | number of streamed operations |
| `streamed_tokens` | int | tokens streamed over the episode (`o200k_base`) |
| `pressure` | float | `streamed_tokens / budget` |
| `chunks` | list of `{index, header, body}` | the operations, one user turn each |
| `gold` | string (JSON) | the answers the graders score against |
| `meta` | string (JSON) | generator settings and instance statistics |

The budget is counted in `o200k_base` tokens for every agent. An agent may enforce a
stricter budget of its own; that is part of the agent, not of the benchmark.

Each operation is shown to the agent as
`=== {header} ({remaining} op(s) remaining after this) ===` followed by its body.

## Usage

### With `datasets`

```python
import json
from datasets import load_dataset

ds = load_dataset("context-language-model/ContextBench", "kv_store", split="test")   # or "all"
row = ds[0]
ops = row["chunks"]            # list of {"index", "header", "body"}
gold = json.loads(row["gold"])
```

To evaluate an agent from Python, install the `contextbench` package, write an
instance to disk, and pass your agent to `contextbench.run`:

```python
from pathlib import Path
from contextbench import run

inst = Path("instances") / row["task_id"]
inst.mkdir(parents=True, exist_ok=True)
(inst / "chunks.jsonl").write_text(
    "".join(json.dumps(c) + "\n" for c in row["chunks"]))
(inst / "gold.json").write_text(row["gold"])
(inst / "meta.json").write_text(row["meta"])

result = run(my_agent, inst, budget=row["budget"], reserve=row["reserve"],
             out_dir=Path("runs") / row["task_id"])
```

### With Harbor

The `harbor/` directory holds one Harbor task per instance, and `registry.json`
lists the datasets `contextbench` (every task) and `contextbench-<family>`
(for example `contextbench-kv-store`). The same tasks are on GitHub, so Harbor runs
them in one line:

```bash
harbor jobs start --repo RulinShao/ContextBench -d contextbench \
    -a contextbench.harbor.agents:Terminus2Stream -m <model>
```

Or download this repository and run Harbor from inside it:

```bash
hf download context-language-model/ContextBench --repo-type dataset --local-dir contextbench-hf
cd contextbench-hf
harbor jobs start --registry-path registry.json -d contextbench \
    -a contextbench.harbor.agents:Terminus2Stream -m <model>
```

Use `-d contextbench-sudoku-sketchpad` for one family, `-i <task_id>` for one task,
`-p harbor/` to run the downloaded directory without the registry, or `-a oracle` to
check a task with its reference solution. Agents that deliver operations into a running
conversation ship with the `contextbench` package (`contextbench.harbor.agents`).

## Citation

ContextBench was introduced in the Context Language Models paper. If you use it, please cite:

```bibtex
@article{shao2026context,
  title   = {Context Language Models},
  author  = {Shao, Rulin and Shen, Shannon Zejiang and Yin, Junjie Oscar and Li, Yuetai and
             Wang, Minheng and Ivison, Hamish and Poovendran, Radha and Lambert, Nathan and
             Xiao, Teng and Lewis, Mike and Yih, Wen-tau and Zettlemoyer, Luke and Koh, Pang Wei},
  journal = {arXiv preprint arXiv:2609.37725},
  year    = {2026}
}
```

## License

Apache-2.0.