# Reproduce the Codex VAKRA comparison

This kit accompanies **I cut median API calls in Codex by 62%** by Andrey Chmerev. It contains the runner, scorer, prompts, schema, sampled task IDs, per-run metrics and aggregate results. The CSVs omit raw model responses and VAKRA answer keys. The fetch script retrieves the public benchmark data directly from IBM at the pinned revision. Review the [dataset terms](https://huggingface.co/datasets/ibm-research/VAKRA#license) before reusing the dataset.

## Setup

The December 2, 2026 run used Codex CLI `0.171.0-alpha.13.2`, `gpt-6.2-sol` with `high` reasoning effort, and the standard service tier. You need an authenticated Codex installation with access to that model, Python 3.12, `uv`, and Git. The local API server listens only on `127.0.0.1:18763`. Re-running the model uses your Codex allowance, and results can vary across runs. Keep reference answers out of the model's working directory and prompt.

In the extracted reproduction directory, install the pinned benchmark code and fetch the public data used by the experiment.

```sh
mkdir -p .benchmark/session .benchmark/results
git clone https://github.com/IBM/vakra.git .benchmark/vakra
git -C .benchmark/vakra checkout 0acf38ee3299284cddb1821f3e783d0ddc0d492f
uv venv --python 3.12 .benchmark/venv
uv pip install --python .benchmark/venv/bin/python -r benchmark/requirements.txt
.benchmark/venv/bin/python benchmark/fetch_vakra.py
(cd .benchmark && venv/bin/uvicorn --app-dir ../benchmark vakra_api:app --host 127.0.0.1 --port 18763 --no-access-log)
```

Leave the local API running. In another terminal, generate both samples and their shortlists.

```sh
.benchmark/venv/bin/python benchmark/prepare.py
.benchmark/venv/bin/python benchmark/embed_tools.py
PYTHONPATH=benchmark .benchmark/venv/bin/python - <<'PY'
import json
from prepare import ROOT, prepare_sample
path = ROOT / '.benchmark' / 'sample.json'
previous = json.loads(path.read_text())['tasks']
omit = {task[key] for task in previous for key in ('uuid','query')}
prepare_sample(path.with_name('confirmation-sample.json'), omit=omit, min_tools=129, size=12, seed=12832)
PY
.benchmark/venv/bin/python benchmark/embed_tools.py .benchmark/confirmation-sample.json
```

`task-manifest.json` records the selected question IDs in order. Compare it with the generated samples before running Codex. The BGE shortlist is computed before timing each CLI run. `baseline-prompt.txt` contains the exact source template, with `{domain}` filled by the runner. `sequential-instruction.txt` contains the exact addition for the sequential and combined variants. `benchmark/answer_schema.json` is the tested output schema.

## Run and score

Use this sequence for the primary comparison, the individual changes, and the additional 32-tool test. The scorer exports CSV and JSON files in the reproduction directory. Existing exports with the same names are replaced, so run this in a fresh extracted copy to preserve the published measurements.

```sh
.benchmark/venv/bin/python benchmark/run_codex.py --workers 8
.benchmark/venv/bin/python benchmark/run_codex.py --tag ablation --limit 12 --workers 4 --variants sequential structured
.benchmark/venv/bin/python benchmark/run_codex.py --tag shortlist-sweep --limit 30 --min-tools 129 --workers 4 --variants shortlist tight_shortlist
.benchmark/venv/bin/python benchmark/run_codex.py --tag confirmation --sample .benchmark/confirmation-sample.json --limit 12 --workers 8 --variants baseline tight_shortlist
.benchmark/venv/bin/python benchmark/score.py --export
.benchmark/venv/bin/python benchmark/score.py --sample .benchmark/confirmation-sample.json confirmation --export --output-prefix confirmation-
```

The runner reuses results for existing tags. Use a fresh `.benchmark/results` directory or new tags for another set of live runs. Model events and tool outputs from your run are saved beneath `.benchmark/results/` and are evaluated by the scorer.

## Apply the workflow locally

`local-agents-rule.md` and `local-skill/SKILL.md` are the later, lightweight Codex configuration. Add the rule to your global `~/.codex/AGENTS.md` and place the skill in a discoverable user skills directory as `tool-workflows/SKILL.md`. Use a fresh Codex session to check that it loads. The benchmark variants used `benchmark/run_codex.py` to apply the actual tool cap and JSON schema.
