ask-or-act 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. ask_or_act-1.0.0/LICENSE +21 -0
  2. ask_or_act-1.0.0/PKG-INFO +249 -0
  3. ask_or_act-1.0.0/README.md +215 -0
  4. ask_or_act-1.0.0/pyproject.toml +119 -0
  5. ask_or_act-1.0.0/pyproject.toml.orig +109 -0
  6. ask_or_act-1.0.0/src/ask_or_act/__init__.py +42 -0
  7. ask_or_act-1.0.0/src/ask_or_act/__main__.py +5 -0
  8. ask_or_act-1.0.0/src/ask_or_act/api.py +743 -0
  9. ask_or_act-1.0.0/src/ask_or_act/audit.py +282 -0
  10. ask_or_act-1.0.0/src/ask_or_act/changelog.py +367 -0
  11. ask_or_act-1.0.0/src/ask_or_act/cli.py +1576 -0
  12. ask_or_act-1.0.0/src/ask_or_act/core/__init__.py +1 -0
  13. ask_or_act-1.0.0/src/ask_or_act/core/budget.py +42 -0
  14. ask_or_act-1.0.0/src/ask_or_act/core/cache.py +103 -0
  15. ask_or_act-1.0.0/src/ask_or_act/core/config.py +231 -0
  16. ask_or_act-1.0.0/src/ask_or_act/core/decider.py +119 -0
  17. ask_or_act-1.0.0/src/ask_or_act/core/limits.py +134 -0
  18. ask_or_act-1.0.0/src/ask_or_act/core/runner.py +302 -0
  19. ask_or_act-1.0.0/src/ask_or_act/core/runs.py +181 -0
  20. ask_or_act-1.0.0/src/ask_or_act/core/types.py +160 -0
  21. ask_or_act-1.0.0/src/ask_or_act/data/__init__.py +1 -0
  22. ask_or_act-1.0.0/src/ask_or_act/data/examples.py +144 -0
  23. ask_or_act-1.0.0/src/ask_or_act/data/hub.py +101 -0
  24. ask_or_act-1.0.0/src/ask_or_act/data/manifest.py +135 -0
  25. ask_or_act-1.0.0/src/ask_or_act/data/sampling.py +216 -0
  26. ask_or_act-1.0.0/src/ask_or_act/data/sources.py +179 -0
  27. ask_or_act-1.0.0/src/ask_or_act/data/training.py +106 -0
  28. ask_or_act-1.0.0/src/ask_or_act/deciders/__init__.py +105 -0
  29. ask_or_act-1.0.0/src/ask_or_act/deciders/baselines.py +105 -0
  30. ask_or_act-1.0.0/src/ask_or_act/deciders/classic.py +247 -0
  31. ask_or_act-1.0.0/src/ask_or_act/deciders/fake.py +169 -0
  32. ask_or_act-1.0.0/src/ask_or_act/deciders/gemini_decisions.py +158 -0
  33. ask_or_act-1.0.0/src/ask_or_act/deciders/http.py +189 -0
  34. ask_or_act-1.0.0/src/ask_or_act/deciders/llm.py +1000 -0
  35. ask_or_act-1.0.0/src/ask_or_act/deciders/pricing.py +186 -0
  36. ask_or_act-1.0.0/src/ask_or_act/deciders/prompts.py +224 -0
  37. ask_or_act-1.0.0/src/ask_or_act/deciders/signals.py +141 -0
  38. ask_or_act-1.0.0/src/ask_or_act/demo.py +102 -0
  39. ask_or_act-1.0.0/src/ask_or_act/exit_codes.py +11 -0
  40. ask_or_act-1.0.0/src/ask_or_act/gate.py +724 -0
  41. ask_or_act-1.0.0/src/ask_or_act/gate_markdown.py +122 -0
  42. ask_or_act-1.0.0/src/ask_or_act/guarantees/__init__.py +1 -0
  43. ask_or_act-1.0.0/src/ask_or_act/guarantees/binomial.py +75 -0
  44. ask_or_act-1.0.0/src/ask_or_act/guarantees/cascade.py +134 -0
  45. ask_or_act-1.0.0/src/ask_or_act/guarantees/fixed_sequence.py +304 -0
  46. ask_or_act-1.0.0/src/ask_or_act/guarantees/mt_bench.py +147 -0
  47. ask_or_act-1.0.0/src/ask_or_act/guarantees/recommend.py +320 -0
  48. ask_or_act-1.0.0/src/ask_or_act/guarantees/sample_size.py +89 -0
  49. ask_or_act-1.0.0/src/ask_or_act/judge.py +407 -0
  50. ask_or_act-1.0.0/src/ask_or_act/metrics/__init__.py +1 -0
  51. ask_or_act-1.0.0/src/ask_or_act/metrics/ace.py +233 -0
  52. ask_or_act-1.0.0/src/ask_or_act/metrics/calibration.py +211 -0
  53. ask_or_act-1.0.0/src/ask_or_act/metrics/classification.py +101 -0
  54. ask_or_act-1.0.0/src/ask_or_act/metrics/command.py +57 -0
  55. ask_or_act-1.0.0/src/ask_or_act/metrics/data.py +136 -0
  56. ask_or_act-1.0.0/src/ask_or_act/metrics/excess.py +126 -0
  57. ask_or_act-1.0.0/src/ask_or_act/metrics/feasibility.py +68 -0
  58. ask_or_act-1.0.0/src/ask_or_act/metrics/mt_bench.py +118 -0
  59. ask_or_act-1.0.0/src/ask_or_act/metrics/report.py +489 -0
  60. ask_or_act-1.0.0/src/ask_or_act/metrics/selective.py +137 -0
  61. ask_or_act-1.0.0/src/ask_or_act/metrics/stats.py +231 -0
  62. ask_or_act-1.0.0/src/ask_or_act/metrics/tango.py +148 -0
  63. ask_or_act-1.0.0/src/ask_or_act/predictions.py +1149 -0
  64. ask_or_act-1.0.0/src/ask_or_act/project_config.py +102 -0
  65. ask_or_act-1.0.0/src/ask_or_act/py.typed +0 -0
  66. ask_or_act-1.0.0/src/ask_or_act/report/__init__.py +1 -0
  67. ask_or_act-1.0.0/src/ask_or_act/report/build.py +773 -0
  68. ask_or_act-1.0.0/src/ask_or_act/report/files.py +548 -0
  69. ask_or_act-1.0.0/src/ask_or_act/report/svg.py +346 -0
  70. ask_or_act-1.0.0/src/ask_or_act/report/table.py +270 -0
  71. ask_or_act-1.0.0/src/ask_or_act/report/template.html +112 -0
  72. ask_or_act-1.0.0/src/ask_or_act/run.py +293 -0
  73. ask_or_act-1.0.0/src/ask_or_act/study.py +381 -0
  74. ask_or_act-1.0.0/src/ask_or_act/study_analysis.py +1811 -0
  75. ask_or_act-1.0.0/src/ask_or_act/study_fakes.py +230 -0
  76. ask_or_act-1.0.0/src/ask_or_act/summaries.py +158 -0
  77. ask_or_act-1.0.0/src/ask_or_act/term.py +62 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 samadarsh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,249 @@
1
+ Metadata-Version: 2.4
2
+ Name: ask-or-act
3
+ Version: 1.0.0
4
+ Summary: Tells you when an AI's decisions can be trusted and when to escalate to a human.
5
+ Keywords: calibration,selective-prediction,llm-evaluation,llm-as-a-judge,conformal,human-in-the-loop,escalation,reliability
6
+ Author: Sam Adarsh
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: numpy>=2.0
21
+ Requires-Dist: scikit-learn>=1.9 ; extra == 'classic'
22
+ Requires-Dist: huggingface-hub>=2.4.0 ; extra == 'data'
23
+ Requires-Dist: pyarrow>=26.0.1 ; extra == 'data'
24
+ Requires-Dist: httpx>=0.28 ; extra == 'providers'
25
+ Requires-Python: >=3.12
26
+ Project-URL: Homepage, https://github.com/samadarsh/ask-or-act
27
+ Project-URL: Documentation, https://github.com/samadarsh/ask-or-act/tree/main/docs
28
+ Project-URL: Issues, https://github.com/samadarsh/ask-or-act/issues
29
+ Project-URL: Changelog, https://github.com/samadarsh/ask-or-act/blob/main/CHANGELOG.md
30
+ Provides-Extra: classic
31
+ Provides-Extra: data
32
+ Provides-Extra: providers
33
+ Description-Content-Type: text/markdown
34
+
35
+ # ask-or-act
36
+
37
+ [![CI](https://github.com/samadarsh/ask-or-act/actions/workflows/ci.yml/badge.svg)](https://github.com/samadarsh/ask-or-act/actions/workflows/ci.yml)
38
+
39
+ **Tells you when an AI's decisions can be trusted, and when to escalate to a human.**
40
+
41
+ AI systems make many small, consequential decisions: which team a ticket goes to,
42
+ whether a message is safe, which of two answers is better, whether an agent should
43
+ *act*, *ask* a clarifying question, or *escalate*. `ask-or-act` takes a file of those
44
+ decisions with the model's confidence and a human label, and tells you:
45
+
46
+ - **how good the decisions are:** accuracy, calibration (ECE, Brier, reliability
47
+ diagrams), selective prediction (risk–coverage) and agreement with humans (Cohen's κ),
48
+ each with a bootstrap confidence interval;
49
+ - **when to act without a human:** a confidence threshold that comes with a
50
+ finite-sample guarantee on the error rate, or a plain statement that your target
51
+ can't be met;
52
+ - **whether a change made things worse:** paired tests of two models on the same ids,
53
+ and a CI gate that fails only when the difference is beyond noise.
54
+
55
+ **[Try it in your browser](https://samadarsh.github.io/ask-or-act/)**: the real package
56
+ runs in the page with Pyodide, on example data or your own file. Nothing is uploaded.
57
+
58
+ > **Status:** 1.0.0 is published to PyPI once the benchmark study's results are in.
59
+ > Release candidates are on [TestPyPI](https://test.pypi.org/project/ask-or-act/).
60
+
61
+ ## Install
62
+
63
+ ```sh
64
+ pip install ask-or-act # or: uv tool install ask-or-act
65
+ ask-or-act demo
66
+ ```
67
+
68
+ Python 3.12 or newer. The only required dependency is numpy.
69
+
70
+ ## Bring your own predictions
71
+
72
+ Give it a CSV, TSV or JSONL file with one row per decision: `id`, `prediction`,
73
+ `confidence` (the model's probability that its answer is right) and `human_label`.
74
+ Optionally add `options`, `split` and `group`.
75
+
76
+ New here? `ask-or-act demo` writes a synthetic example file (an overconfident
77
+ support-ticket router; no text, no download) and its HTML report into a new folder in
78
+ about a second, and prints what the other commands say about it.
79
+ `--overconfidence -1…3` changes how miscalibrated the simulated model is.
80
+
81
+ ```sh
82
+ ask-or-act demo # example data + report in ./ask-or-act-demo/
83
+ ask-or-act check preds.csv # is the file usable, and what does it support?
84
+ ask-or-act thresholds preds.csv # act above what confidence? (with a guarantee)
85
+ ask-or-act metrics preds.csv # accuracy, calibration, ranking, with 95% CIs
86
+ ask-or-act compare a.csv b.csv # is B better than A? paired tests, same ids
87
+ ask-or-act report preds.csv -o r.html # one HTML page: summary, charts, thresholds
88
+ ```
89
+
90
+ - **`check`** reports every problem at once, with line numbers and the flag that fixes
91
+ it. For example, it suggests `--confidence-scale percent` for 0–100 scores, and
92
+ `--confidence-of positive` for P(positive class).
93
+ - **`thresholds`** uses fixed-sequence testing from Trust or Escalate
94
+ ([arXiv 2407.18370](https://arxiv.org/abs/2407.18370)) on a calibration half and
95
+ reports the result on a held-out test half. It also gives a minimum-abstention floor
96
+ ([arXiv 2606.29054](https://arxiv.org/abs/2606.29054)): when the target risk can't be
97
+ reached without abstaining at least some fraction of the time, it says so up front.
98
+ - **`compare`** uses exact McNemar for accuracy and a centered paired bootstrap for
99
+ the rest, Holm-corrected. Calibration is compared by **excess ECE**: each model's ECE
100
+ minus its noise floor, the ECE a perfectly calibrated model with the same confidences
101
+ would score at that n. Raw ECE is biased upward on finite samples, by different
102
+ amounts for different models, so it isn't tested. The ACE views
103
+ ([arXiv 2606.30814](https://arxiv.org/abs/2606.30814)) are shown as diagnostics only:
104
+ when accuracies differ they move with the accuracy gap, even for two perfectly
105
+ calibrated models.
106
+
107
+ Every command prints a short summary, or one JSON document with `--json`. The same
108
+ functions are a Python API:
109
+
110
+ ```python
111
+ import ask_or_act as aoa
112
+
113
+ th = aoa.find_thresholds("preds.csv", alpha=0.10, delta=0.10)
114
+ print(th.summary()) # "Act when confidence ≥ 0.87; ask a human below. ..."
115
+ ```
116
+
117
+ [docs/cli-design.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/cli-design.md)
118
+ has the full design, and
119
+ [docs/guarantees.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/guarantees.md)
120
+ states exactly what the guarantee promises and assumes.
121
+
122
+ **Runs locally.** The analysis commands (`check`, `thresholds`, `metrics`, `compare`,
123
+ `report`, `demo`, `gate`, `changelog`) make no network connections and send no
124
+ telemetry, and the report page loads nothing from elsewhere. A test enforces this.
125
+ Only `run` calls model APIs, and only after you approve the cost.
126
+
127
+ ## Gate CI on your AI's decisions
128
+
129
+ `ask-or-act gate` compares a new predictions file with a baseline on the same ids. It
130
+ exits 1 only when the new file is **worse by more than a tolerance, beyond noise**:
131
+
132
+ - accuracy (Tango's score test);
133
+ - calibration (the excess-ECE gap, so a more accurate model isn't penalised);
134
+ - coverage at your target risk;
135
+ - whether the guarantee still holds.
136
+
137
+ ```sh
138
+ ask-or-act gate new.csv --baseline eval/baseline.csv --expect "accuracy +0 to +2 points"
139
+ ask-or-act changelog --last 5 # what changed, what you expected, what happened
140
+ ```
141
+
142
+ - **Tolerances** default to 1 point of accuracy, 0.02 of calibration and 5 points of
143
+ coverage. The policy lives in `ask-or-act.toml`, next to your code.
144
+ - **The false-FAIL rate is measured.** When nothing changed it is at most 5%, and 1.0%
145
+ in a simulation with the defaults
146
+ ([docs/gate-simulation.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/gate-simulation.md)).
147
+ - **The decision changelog** records the expected effect *before* the run and checks it
148
+ against what happened. Reruns don't get a second guess.
149
+ - **On GitHub,** a composite Action comments the result on the pull request:
150
+
151
+ ```yaml
152
+ # pinned to the 1.0.0 release; always a full commit SHA, never a branch or tag
153
+ - uses: samadarsh/ask-or-act@453b52f073e66f6a1cb57560f4f229441ee7ee79
154
+ with:
155
+ new: predictions.csv
156
+ ```
157
+
158
+ [docs/gate.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/gate.md) covers
159
+ what the gate promises and how to set up CI. A full workflow to copy is in
160
+ [examples/github/gate.yml](https://github.com/samadarsh/ask-or-act/blob/main/examples/github/gate.yml).
161
+
162
+ ## Benchmark study
163
+
164
+ The repository also runs and evaluates models itself (`ask-or-act run`, `study`,
165
+ `judge`). The 1.0 study used four open-weight LLMs on Groq's free tier (gpt-oss-120b,
166
+ gpt-oss-20b, gpt-oss-safeguard-20b and qwen3.8-27b), a classic ML baseline (TF-IDF +
167
+ logistic regression; answer lengths on MT-Bench) and a majority baseline, on three
168
+ tasks:
169
+
170
+ - **Banking77:** routing a banking query to one of 77 intents;
171
+ - **Aegis 2.0:** safe / unsafe content classification, human-labelled rows only (the
172
+ repository never shows its text, only ids);
173
+ - **MT-Bench human judgments:** LLM-as-a-judge, against expert votes.
174
+
175
+ Confidence comes from verbalized scores and from self-consistency over 3 samples. The
176
+ questions, tests, multiple-comparison corrections and targets were pre-registered
177
+ before the main analysis; the few exceptions are disclosed in
178
+ [docs/analysis-plan.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/analysis-plan.md).
179
+ How the study ran is in
180
+ [docs/study.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/study.md).
181
+
182
+ ### Results
183
+
184
+ The unedited analysis output is
185
+ [docs/results.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/results.md).
186
+ What it means, with every figure linked to its line, is in
187
+ [docs/results-interpretation.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/results-interpretation.md).
188
+
189
+ - **Calibration (Q1):** every LLM's verbalized confidence is poorly calibrated on all
190
+ three tasks, with excess ECE 0.08–0.25. On average it is overconfident by 0.10–0.27
191
+ (exploratory). The classic in-domain baseline's excess ECE is consistent with
192
+ calibrated on all three; on MT-Bench its confidence is below its accuracy on average
193
+ (−0.086, exploratory). 9 of 19 pairs are separated.
194
+ - **Self-consistency, k = 3 (Q1b):** 1 of 9 pairs is separated against verbalized
195
+ confidence, and it doesn't survive S1 (pilot-seen examples removed).
196
+ - **Guarantees (Q2):** at α = 0.10, 1 of 14 LLM configurations on Banking77 and Aegis
197
+ certifies a threshold (gpt-oss-120b on Banking77, 44.8% coverage). Classic certifies
198
+ 94.4% on Banking77 and 40.0% on Aegis. For all 7 configurations that certify, there is
199
+ no evidence of a violation on the test halves.
200
+ - **Automation (Q3):** the cascade classic → gpt-oss-120b acts on 90.9% of Banking77 at
201
+ risk 0.079, for about 6% of the LLM cascade's cost per decision.
202
+ - **Transfer (Q4):** thresholds don't transfer. gpt-oss-120b's threshold applied to
203
+ qwen3.8-27b gave risk 0.201 against α 0.10: evidence of a violation.
204
+
205
+ Caveats: classic is trained in-domain and the LLMs are zero-shot; samples are small;
206
+ four free-tier models, three tasks.
207
+
208
+ ## Development
209
+
210
+ Requires [uv](https://docs.astral.sh/uv/). Python 3.12+ is fetched automatically.
211
+
212
+ ```sh
213
+ uv sync --all-extras # create .venv with every optional extra
214
+ uv run pytest # tests (no network)
215
+ uv run ruff check # lint
216
+ uv run ruff format # format
217
+ uv run mypy # type check (strict)
218
+
219
+ # A free fake decider over the Banking77 sample, then its metrics:
220
+ uv run ask-or-act run configs/fake-banking77.toml --dry-run # plan + cost estimate only
221
+ uv run ask-or-act run configs/fake-banking77.toml # saved under runs/
222
+ uv run ask-or-act metrics runs/<run-id> # metrics with 95% CIs
223
+ uv run ask-or-act metrics runs/<run-a> runs/<run-b> # paired comparison
224
+
225
+ # Free baselines, then a real provider (keys in .env, never committed):
226
+ uv run ask-or-act run configs/baselines/classic-banking77.toml
227
+ uv run --env-file .env ask-or-act run configs/smoke/groq-gpt-oss-120b-banking77.toml --dry-run
228
+ uv run --env-file .env ask-or-act run configs/smoke/groq-gpt-oss-120b-banking77.toml --yes
229
+ ```
230
+
231
+ Optional extras: `providers` (HTTP for the model adapters), `classic` (scikit-learn,
232
+ for the classic baseline) and `data` (Hugging Face downloads). Deciders, confidence
233
+ signals, prices and free-tier limits are in
234
+ [docs/deciders.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/deciders.md).
235
+ Adapters for Gemini, OpenAI and the Gemini Decisions API exist and are tested on
236
+ recorded responses only; the study didn't use them. On a free tier, a run that hits
237
+ the daily limit stops cleanly, and re-running it later resumes from the cache.
238
+
239
+ CI runs lint, format, type checks and tests on Python 3.12, 3.13 and 3.14. The papers
240
+ this builds on are in
241
+ [docs/research.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/research.md),
242
+ the datasets in
243
+ [docs/datasets.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/datasets.md),
244
+ and the release history in
245
+ [CHANGELOG.md](https://github.com/samadarsh/ask-or-act/blob/main/CHANGELOG.md).
246
+
247
+ ## License
248
+
249
+ MIT. See [LICENSE](https://github.com/samadarsh/ask-or-act/blob/main/LICENSE).
@@ -0,0 +1,215 @@
1
+ # ask-or-act
2
+
3
+ [![CI](https://github.com/samadarsh/ask-or-act/actions/workflows/ci.yml/badge.svg)](https://github.com/samadarsh/ask-or-act/actions/workflows/ci.yml)
4
+
5
+ **Tells you when an AI's decisions can be trusted, and when to escalate to a human.**
6
+
7
+ AI systems make many small, consequential decisions: which team a ticket goes to,
8
+ whether a message is safe, which of two answers is better, whether an agent should
9
+ *act*, *ask* a clarifying question, or *escalate*. `ask-or-act` takes a file of those
10
+ decisions with the model's confidence and a human label, and tells you:
11
+
12
+ - **how good the decisions are:** accuracy, calibration (ECE, Brier, reliability
13
+ diagrams), selective prediction (risk–coverage) and agreement with humans (Cohen's κ),
14
+ each with a bootstrap confidence interval;
15
+ - **when to act without a human:** a confidence threshold that comes with a
16
+ finite-sample guarantee on the error rate, or a plain statement that your target
17
+ can't be met;
18
+ - **whether a change made things worse:** paired tests of two models on the same ids,
19
+ and a CI gate that fails only when the difference is beyond noise.
20
+
21
+ **[Try it in your browser](https://samadarsh.github.io/ask-or-act/)**: the real package
22
+ runs in the page with Pyodide, on example data or your own file. Nothing is uploaded.
23
+
24
+ > **Status:** 1.0.0 is published to PyPI once the benchmark study's results are in.
25
+ > Release candidates are on [TestPyPI](https://test.pypi.org/project/ask-or-act/).
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ pip install ask-or-act # or: uv tool install ask-or-act
31
+ ask-or-act demo
32
+ ```
33
+
34
+ Python 3.12 or newer. The only required dependency is numpy.
35
+
36
+ ## Bring your own predictions
37
+
38
+ Give it a CSV, TSV or JSONL file with one row per decision: `id`, `prediction`,
39
+ `confidence` (the model's probability that its answer is right) and `human_label`.
40
+ Optionally add `options`, `split` and `group`.
41
+
42
+ New here? `ask-or-act demo` writes a synthetic example file (an overconfident
43
+ support-ticket router; no text, no download) and its HTML report into a new folder in
44
+ about a second, and prints what the other commands say about it.
45
+ `--overconfidence -1…3` changes how miscalibrated the simulated model is.
46
+
47
+ ```sh
48
+ ask-or-act demo # example data + report in ./ask-or-act-demo/
49
+ ask-or-act check preds.csv # is the file usable, and what does it support?
50
+ ask-or-act thresholds preds.csv # act above what confidence? (with a guarantee)
51
+ ask-or-act metrics preds.csv # accuracy, calibration, ranking, with 95% CIs
52
+ ask-or-act compare a.csv b.csv # is B better than A? paired tests, same ids
53
+ ask-or-act report preds.csv -o r.html # one HTML page: summary, charts, thresholds
54
+ ```
55
+
56
+ - **`check`** reports every problem at once, with line numbers and the flag that fixes
57
+ it. For example, it suggests `--confidence-scale percent` for 0–100 scores, and
58
+ `--confidence-of positive` for P(positive class).
59
+ - **`thresholds`** uses fixed-sequence testing from Trust or Escalate
60
+ ([arXiv 2407.18370](https://arxiv.org/abs/2407.18370)) on a calibration half and
61
+ reports the result on a held-out test half. It also gives a minimum-abstention floor
62
+ ([arXiv 2606.29054](https://arxiv.org/abs/2606.29054)): when the target risk can't be
63
+ reached without abstaining at least some fraction of the time, it says so up front.
64
+ - **`compare`** uses exact McNemar for accuracy and a centered paired bootstrap for
65
+ the rest, Holm-corrected. Calibration is compared by **excess ECE**: each model's ECE
66
+ minus its noise floor, the ECE a perfectly calibrated model with the same confidences
67
+ would score at that n. Raw ECE is biased upward on finite samples, by different
68
+ amounts for different models, so it isn't tested. The ACE views
69
+ ([arXiv 2606.30814](https://arxiv.org/abs/2606.30814)) are shown as diagnostics only:
70
+ when accuracies differ they move with the accuracy gap, even for two perfectly
71
+ calibrated models.
72
+
73
+ Every command prints a short summary, or one JSON document with `--json`. The same
74
+ functions are a Python API:
75
+
76
+ ```python
77
+ import ask_or_act as aoa
78
+
79
+ th = aoa.find_thresholds("preds.csv", alpha=0.10, delta=0.10)
80
+ print(th.summary()) # "Act when confidence ≥ 0.87; ask a human below. ..."
81
+ ```
82
+
83
+ [docs/cli-design.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/cli-design.md)
84
+ has the full design, and
85
+ [docs/guarantees.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/guarantees.md)
86
+ states exactly what the guarantee promises and assumes.
87
+
88
+ **Runs locally.** The analysis commands (`check`, `thresholds`, `metrics`, `compare`,
89
+ `report`, `demo`, `gate`, `changelog`) make no network connections and send no
90
+ telemetry, and the report page loads nothing from elsewhere. A test enforces this.
91
+ Only `run` calls model APIs, and only after you approve the cost.
92
+
93
+ ## Gate CI on your AI's decisions
94
+
95
+ `ask-or-act gate` compares a new predictions file with a baseline on the same ids. It
96
+ exits 1 only when the new file is **worse by more than a tolerance, beyond noise**:
97
+
98
+ - accuracy (Tango's score test);
99
+ - calibration (the excess-ECE gap, so a more accurate model isn't penalised);
100
+ - coverage at your target risk;
101
+ - whether the guarantee still holds.
102
+
103
+ ```sh
104
+ ask-or-act gate new.csv --baseline eval/baseline.csv --expect "accuracy +0 to +2 points"
105
+ ask-or-act changelog --last 5 # what changed, what you expected, what happened
106
+ ```
107
+
108
+ - **Tolerances** default to 1 point of accuracy, 0.02 of calibration and 5 points of
109
+ coverage. The policy lives in `ask-or-act.toml`, next to your code.
110
+ - **The false-FAIL rate is measured.** When nothing changed it is at most 5%, and 1.0%
111
+ in a simulation with the defaults
112
+ ([docs/gate-simulation.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/gate-simulation.md)).
113
+ - **The decision changelog** records the expected effect *before* the run and checks it
114
+ against what happened. Reruns don't get a second guess.
115
+ - **On GitHub,** a composite Action comments the result on the pull request:
116
+
117
+ ```yaml
118
+ # pinned to the 1.0.0 release; always a full commit SHA, never a branch or tag
119
+ - uses: samadarsh/ask-or-act@453b52f073e66f6a1cb57560f4f229441ee7ee79
120
+ with:
121
+ new: predictions.csv
122
+ ```
123
+
124
+ [docs/gate.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/gate.md) covers
125
+ what the gate promises and how to set up CI. A full workflow to copy is in
126
+ [examples/github/gate.yml](https://github.com/samadarsh/ask-or-act/blob/main/examples/github/gate.yml).
127
+
128
+ ## Benchmark study
129
+
130
+ The repository also runs and evaluates models itself (`ask-or-act run`, `study`,
131
+ `judge`). The 1.0 study used four open-weight LLMs on Groq's free tier (gpt-oss-120b,
132
+ gpt-oss-20b, gpt-oss-safeguard-20b and qwen3.8-27b), a classic ML baseline (TF-IDF +
133
+ logistic regression; answer lengths on MT-Bench) and a majority baseline, on three
134
+ tasks:
135
+
136
+ - **Banking77:** routing a banking query to one of 77 intents;
137
+ - **Aegis 2.0:** safe / unsafe content classification, human-labelled rows only (the
138
+ repository never shows its text, only ids);
139
+ - **MT-Bench human judgments:** LLM-as-a-judge, against expert votes.
140
+
141
+ Confidence comes from verbalized scores and from self-consistency over 3 samples. The
142
+ questions, tests, multiple-comparison corrections and targets were pre-registered
143
+ before the main analysis; the few exceptions are disclosed in
144
+ [docs/analysis-plan.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/analysis-plan.md).
145
+ How the study ran is in
146
+ [docs/study.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/study.md).
147
+
148
+ ### Results
149
+
150
+ The unedited analysis output is
151
+ [docs/results.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/results.md).
152
+ What it means, with every figure linked to its line, is in
153
+ [docs/results-interpretation.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/results-interpretation.md).
154
+
155
+ - **Calibration (Q1):** every LLM's verbalized confidence is poorly calibrated on all
156
+ three tasks, with excess ECE 0.08–0.25. On average it is overconfident by 0.10–0.27
157
+ (exploratory). The classic in-domain baseline's excess ECE is consistent with
158
+ calibrated on all three; on MT-Bench its confidence is below its accuracy on average
159
+ (−0.086, exploratory). 9 of 19 pairs are separated.
160
+ - **Self-consistency, k = 3 (Q1b):** 1 of 9 pairs is separated against verbalized
161
+ confidence, and it doesn't survive S1 (pilot-seen examples removed).
162
+ - **Guarantees (Q2):** at α = 0.10, 1 of 14 LLM configurations on Banking77 and Aegis
163
+ certifies a threshold (gpt-oss-120b on Banking77, 44.8% coverage). Classic certifies
164
+ 94.4% on Banking77 and 40.0% on Aegis. For all 7 configurations that certify, there is
165
+ no evidence of a violation on the test halves.
166
+ - **Automation (Q3):** the cascade classic → gpt-oss-120b acts on 90.9% of Banking77 at
167
+ risk 0.079, for about 6% of the LLM cascade's cost per decision.
168
+ - **Transfer (Q4):** thresholds don't transfer. gpt-oss-120b's threshold applied to
169
+ qwen3.8-27b gave risk 0.201 against α 0.10: evidence of a violation.
170
+
171
+ Caveats: classic is trained in-domain and the LLMs are zero-shot; samples are small;
172
+ four free-tier models, three tasks.
173
+
174
+ ## Development
175
+
176
+ Requires [uv](https://docs.astral.sh/uv/). Python 3.12+ is fetched automatically.
177
+
178
+ ```sh
179
+ uv sync --all-extras # create .venv with every optional extra
180
+ uv run pytest # tests (no network)
181
+ uv run ruff check # lint
182
+ uv run ruff format # format
183
+ uv run mypy # type check (strict)
184
+
185
+ # A free fake decider over the Banking77 sample, then its metrics:
186
+ uv run ask-or-act run configs/fake-banking77.toml --dry-run # plan + cost estimate only
187
+ uv run ask-or-act run configs/fake-banking77.toml # saved under runs/
188
+ uv run ask-or-act metrics runs/<run-id> # metrics with 95% CIs
189
+ uv run ask-or-act metrics runs/<run-a> runs/<run-b> # paired comparison
190
+
191
+ # Free baselines, then a real provider (keys in .env, never committed):
192
+ uv run ask-or-act run configs/baselines/classic-banking77.toml
193
+ uv run --env-file .env ask-or-act run configs/smoke/groq-gpt-oss-120b-banking77.toml --dry-run
194
+ uv run --env-file .env ask-or-act run configs/smoke/groq-gpt-oss-120b-banking77.toml --yes
195
+ ```
196
+
197
+ Optional extras: `providers` (HTTP for the model adapters), `classic` (scikit-learn,
198
+ for the classic baseline) and `data` (Hugging Face downloads). Deciders, confidence
199
+ signals, prices and free-tier limits are in
200
+ [docs/deciders.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/deciders.md).
201
+ Adapters for Gemini, OpenAI and the Gemini Decisions API exist and are tested on
202
+ recorded responses only; the study didn't use them. On a free tier, a run that hits
203
+ the daily limit stops cleanly, and re-running it later resumes from the cache.
204
+
205
+ CI runs lint, format, type checks and tests on Python 3.12, 3.13 and 3.14. The papers
206
+ this builds on are in
207
+ [docs/research.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/research.md),
208
+ the datasets in
209
+ [docs/datasets.md](https://github.com/samadarsh/ask-or-act/blob/main/docs/datasets.md),
210
+ and the release history in
211
+ [CHANGELOG.md](https://github.com/samadarsh/ask-or-act/blob/main/CHANGELOG.md).
212
+
213
+ ## License
214
+
215
+ MIT. See [LICENSE](https://github.com/samadarsh/ask-or-act/blob/main/LICENSE).
@@ -0,0 +1,119 @@
1
+ [project]
2
+ name = "ask-or-act"
3
+ version = "1.0.0"
4
+ description = "Tells you when an AI's decisions can be trusted and when to escalate to a human."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ keywords = [
10
+ "calibration",
11
+ "selective-prediction",
12
+ "llm-evaluation",
13
+ "llm-as-a-judge",
14
+ "conformal",
15
+ "human-in-the-loop",
16
+ "escalation",
17
+ "reliability",
18
+ ]
19
+ dependencies = ["numpy>=2.0"]
20
+ classifiers = [
21
+ "Development Status :: 5 - Production/Stable",
22
+ "Environment :: Console",
23
+ "Intended Audience :: Developers",
24
+ "Intended Audience :: Science/Research",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
31
+ "Typing :: Typed",
32
+ ]
33
+
34
+ [[project.authors]]
35
+ name = "Sam Adarsh"
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/samadarsh/ask-or-act"
39
+ Documentation = "https://github.com/samadarsh/ask-or-act/tree/main/docs"
40
+ Issues = "https://github.com/samadarsh/ask-or-act/issues"
41
+ Changelog = "https://github.com/samadarsh/ask-or-act/blob/main/CHANGELOG.md"
42
+
43
+ [project.scripts]
44
+ ask-or-act = "ask_or_act.cli:main"
45
+
46
+ [project.optional-dependencies]
47
+ providers = ["httpx>=0.28"]
48
+ classic = ["scikit-learn>=1.9"]
49
+ data = [
50
+ "huggingface-hub>=2.4.0",
51
+ "pyarrow>=26.0.1",
52
+ ]
53
+
54
+ [build-system]
55
+ requires = ["uv_build>=0.11,<0.12"]
56
+ build-backend = "uv_build"
57
+
58
+ [tool.uv.build-backend]
59
+ wheel-exclude = [
60
+ "ask_or_act/study_analysis.py",
61
+ "ask_or_act/study_fakes.py",
62
+ ]
63
+
64
+ [tool.ruff]
65
+ line-length = 100
66
+ target-version = "py312"
67
+
68
+ [tool.ruff.lint]
69
+ ignore = [
70
+ "RUF001",
71
+ "RUF002",
72
+ "RUF003",
73
+ ]
74
+ select = [
75
+ "E",
76
+ "W",
77
+ "F",
78
+ "I",
79
+ "B",
80
+ "UP",
81
+ "N",
82
+ "SIM",
83
+ "C4",
84
+ "PT",
85
+ "RUF",
86
+ ]
87
+
88
+ [tool.mypy]
89
+ strict = true
90
+ python_version = "3.12"
91
+ files = [
92
+ "src",
93
+ "tests",
94
+ ]
95
+
96
+ [[tool.mypy.overrides]]
97
+ module = [
98
+ "pyarrow",
99
+ "pyarrow.*",
100
+ "sklearn",
101
+ "sklearn.*",
102
+ "scipy",
103
+ "scipy.*",
104
+ ]
105
+ ignore_missing_imports = true
106
+
107
+ [tool.pytest.ini_options]
108
+ testpaths = ["tests"]
109
+ addopts = "-ra --strict-markers --strict-config"
110
+
111
+ [dependency-groups]
112
+ dev = [
113
+ "mypy>=2.4.1",
114
+ "pytest>=9.2.0",
115
+ "pytest-cov>=7.1.0",
116
+ "ruff>=0.17.5",
117
+ "scikit-learn>=1.9.1",
118
+ "scipy>=1.18.1",
119
+ ]