chap-analytics 0.1.0__tar.gz → 0.2.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.
- chap_analytics-0.2.0/CHANGELOG.md +103 -0
- chap_analytics-0.2.0/MANIFEST.in +6 -0
- chap_analytics-0.2.0/PKG-INFO +443 -0
- chap_analytics-0.2.0/README.md +394 -0
- chap_analytics-0.2.0/chap_analytics/__init__.py +64 -0
- chap_analytics-0.2.0/chap_analytics/_report/report.css +52 -0
- chap_analytics-0.2.0/chap_analytics/_report/report.html +70 -0
- chap_analytics-0.2.0/chap_analytics/_report/report.js +509 -0
- chap_analytics-0.2.0/chap_analytics/_report/stats.js +577 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/LICENSE.vega +27 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/LICENSE.vega-embed +27 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/LICENSE.vega-lite +27 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/README.md +15 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/render.js +44 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/vega-embed.min.js +7 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/vega-lite.min.js +2 -0
- chap_analytics-0.2.0/chap_analytics/_vendor/vega.min.js +1 -0
- chap_analytics-0.2.0/chap_analytics/briefs.py +457 -0
- chap_analytics-0.2.0/chap_analytics/charts.py +916 -0
- chap_analytics-0.2.0/chap_analytics/export.py +144 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics/frames.py +20 -1
- chap_analytics-0.2.0/chap_analytics/graph.py +1051 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics/load.py +7 -0
- chap_analytics-0.2.0/chap_analytics/models.py +109 -0
- chap_analytics-0.2.0/chap_analytics/report.py +185 -0
- chap_analytics-0.2.0/chap_analytics/sample.py +549 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics/schema.py +2 -0
- chap_analytics-0.2.0/chap_analytics/stats.py +985 -0
- chap_analytics-0.2.0/chap_analytics/watch.py +199 -0
- chap_analytics-0.2.0/chap_analytics.egg-info/PKG-INFO +443 -0
- chap_analytics-0.2.0/chap_analytics.egg-info/SOURCES.txt +57 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics.egg-info/requires.txt +10 -0
- chap_analytics-0.2.0/examples/build_notebook.py +803 -0
- chap_analytics-0.2.0/examples/chap_analytics_walkthrough.ipynb +12374 -0
- chap_analytics-0.2.0/examples/support_desk.py +200 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/pyproject.toml +14 -7
- chap_analytics-0.2.0/tests/js_stats_runner.js +36 -0
- chap_analytics-0.2.0/tests/test_charts_and_briefs.py +138 -0
- chap_analytics-0.2.0/tests/test_from_url_scheme.py +30 -0
- chap_analytics-0.2.0/tests/test_graph.py +195 -0
- chap_analytics-0.2.0/tests/test_report.py +205 -0
- chap_analytics-0.2.0/tests/test_stats.py +294 -0
- chap_analytics-0.2.0/tests/test_watch_export_models.py +132 -0
- chap_analytics-0.1.0/CHANGELOG.md +0 -32
- chap_analytics-0.1.0/MANIFEST.in +0 -2
- chap_analytics-0.1.0/PKG-INFO +0 -307
- chap_analytics-0.1.0/README.md +0 -267
- chap_analytics-0.1.0/chap_analytics/__init__.py +0 -45
- chap_analytics-0.1.0/chap_analytics/sample.py +0 -281
- chap_analytics-0.1.0/chap_analytics.egg-info/PKG-INFO +0 -307
- chap_analytics-0.1.0/chap_analytics.egg-info/SOURCES.txt +0 -27
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/LICENSE +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics/_patch.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics/py.typed +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics.egg-info/dependency_links.txt +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/chap_analytics.egg-info/top_level.txt +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/setup.cfg +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/conftest.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_differential.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_example.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_handoff_and_routing.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_identity.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_notebook.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_projection.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_redaction_and_malformed.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_review_passes.py +0 -0
- {chap_analytics-0.1.0 → chap_analytics-0.2.0}/tests/test_sample_and_export.py +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
`chap-analytics` versions on its own track. It is a reader of the protocol,
|
|
4
|
+
so a protocol release moves the coordinator packages together and leaves this
|
|
5
|
+
one where it is until the tables or the analyses change.
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
|
|
9
|
+
The decision layer: every row of the roadmap's decision table, as a
|
|
10
|
+
statistic with its interval, a chart, and a brief, assembled into a
|
|
11
|
+
self-contained interactive report.
|
|
12
|
+
|
|
13
|
+
- `chap_analytics.stats`: approval, override, rejection and abstention rates
|
|
14
|
+
with Wilson intervals, overall, by group and over time; the refining
|
|
15
|
+
against reversing split; patch-path frequency with the rationales behind
|
|
16
|
+
each cell; the reliability table with expected calibration error and Brier
|
|
17
|
+
score; time to decision as a Kaplan-Meier curve with open reviews
|
|
18
|
+
censored, latency by group and the open queue; promotion readiness as a
|
|
19
|
+
Beta posterior against a threshold and Wald's sequential test; Fleiss'
|
|
20
|
+
kappa on multi-reviewer passes and on deliberation votes, pairwise Cohen's
|
|
21
|
+
kappa and abstentions by category; whisper lapse and handoff acceptance
|
|
22
|
+
rates with response times; chain assurance per period; and a Bernoulli
|
|
23
|
+
CUSUM on the correction rate with its decision interval set by simulation
|
|
24
|
+
for a stated false-alarm rate. Every estimate with a minimum carries a
|
|
25
|
+
`sufficient` flag and the minimum it was judged against.
|
|
26
|
+
- `chap_analytics.graph`: the chain as a typed graph with a fixed ontology
|
|
27
|
+
of nine node types and twenty-five edge types; the lineage of one task as
|
|
28
|
+
a graph and as swimlane rows; the collaboration graph with degree,
|
|
29
|
+
betweenness and per-agent reviewer concentration; oversight coverage of
|
|
30
|
+
shipped outcomes; separation-of-duties findings; a Fruchterman-Reingold
|
|
31
|
+
layout; node-link JSON, GraphML and networkx exports; and the ontology
|
|
32
|
+
drawn as SVG from the declarations.
|
|
33
|
+
- `chap_analytics.charts`: one Vega-Lite specification per chart in the
|
|
34
|
+
decision table, as a plain dictionary that a notebook renders, Altair
|
|
35
|
+
takes, `Chart.save` writes as SVG or PNG, and the report embeds. Charts
|
|
36
|
+
carry the question they answer and the decision they inform.
|
|
37
|
+
- `chap_analytics.briefs`: each decision in a paragraph, with the numbers,
|
|
38
|
+
their intervals, and the decision they support, in words that change with
|
|
39
|
+
the numbers.
|
|
40
|
+
- `chap_analytics.report`: one HTML file with the Vega runtime, the rows
|
|
41
|
+
behind every chart and the page inside it. Headline cards per decision, a
|
|
42
|
+
filter bar for date range, kind, agent, reviewer, mode and tag, brushing
|
|
43
|
+
on the time axis, drill-through from the correction heatmap to the
|
|
44
|
+
rationales, the open queue, and a lineage view for any task. Every
|
|
45
|
+
statistic is recomputed in the browser as the reader filters, by a
|
|
46
|
+
JavaScript mirror of the library that the suite checks against the Python
|
|
47
|
+
functions. Artefact content stays out of the file.
|
|
48
|
+
- `chap_analytics.watch`: a `Watcher` that reads `audit.read` incrementally
|
|
49
|
+
from a sequence cursor over HTTP, an in-process coordinator or any
|
|
50
|
+
callable, re-projects, regenerates the report, and raises each drift alarm
|
|
51
|
+
once with the tasks behind it.
|
|
52
|
+
- `chap_analytics.export`: evaluation cases with the agent's output, the
|
|
53
|
+
corrected output and the rationale, written as JSON lines; prompt-revision
|
|
54
|
+
candidates ranked by frequency and reversing share; and routing
|
|
55
|
+
calibration, the confidence threshold that reaches a target acceptance.
|
|
56
|
+
- `chap_analytics.models`: reviewer severity separated from agent quality
|
|
57
|
+
by a Rasch-style logistic model in numpy, with approximate standard
|
|
58
|
+
errors, which declines to fit below its minimum and says why.
|
|
59
|
+
- `chap_analytics.sample.synthetic`: a workspace generated from stated
|
|
60
|
+
rates (override, rejection, refining share, quorum share and agreement,
|
|
61
|
+
latency, open share, whisper and lapse rates, handoffs, drift, reviewer
|
|
62
|
+
strictness, agent quality, and how confidence relates to outcomes), so
|
|
63
|
+
every statistic is tested against the truth that produced it. The
|
|
64
|
+
coordinator's own clock follows the simulated timeline.
|
|
65
|
+
- `events.signed` and `events.scitt_submitted` columns.
|
|
66
|
+
- A `concerns` edge for the task a deliberation is about; `asked_to` and
|
|
67
|
+
`whispered_to` read from the `to` field of the request envelope; `fulfils`
|
|
68
|
+
read from the `fulfils` field of a `task.complete` envelope where a chain
|
|
69
|
+
carries one.
|
|
70
|
+
- Documentation: the README carries the decision table and the pictures;
|
|
71
|
+
`docs/methods.md`, `docs/graph.md` and `docs/report.md` state each
|
|
72
|
+
method's assumptions and minimums, the ontology, and how the report is
|
|
73
|
+
built. The walkthrough notebook continues from the tables to the decision
|
|
74
|
+
layer, with the charts drawn inline.
|
|
75
|
+
- Extras: `viz` (Altair and vl-convert), `graph` (networkx). numpy is named
|
|
76
|
+
as a dependency alongside pandas.
|
|
77
|
+
|
|
78
|
+
## 0.1.0
|
|
79
|
+
|
|
80
|
+
First release: stage one of the analytics roadmap.
|
|
81
|
+
|
|
82
|
+
- Eleven documented tables, projected from a CHAP audit chain by replaying
|
|
83
|
+
the envelope stream: `events`, `tasks`, `decisions`, `overrides`,
|
|
84
|
+
`patch_ops`, `participants`, `deliberations`, `votes`, `whispers`,
|
|
85
|
+
`handoffs`, `routing`. Every column declared with its dtype and provenance.
|
|
86
|
+
- Four loaders: a SQLite store, a JSON export, an `audit.read` endpoint, and
|
|
87
|
+
a `Coordinator` in the same process.
|
|
88
|
+
- Review passes kept apart, so a task sent back for revision is measured from
|
|
89
|
+
each pass's own opening and `outcome` reads from the decision that settled
|
|
90
|
+
the last one.
|
|
91
|
+
- The corrected artefact reconstructed from the patch with the coordinator's
|
|
92
|
+
own RFC 6902 semantics, and checked against what the coordinator stored by
|
|
93
|
+
the differential suite.
|
|
94
|
+
- Successors minted by escalation and supersession counted as tasks, with
|
|
95
|
+
what they inherit from the original.
|
|
96
|
+
- `id_certain` and `assignee_certain`, so a row says which of its values are
|
|
97
|
+
inferred.
|
|
98
|
+
- A redactor hook that covers every artefact-bearing field, in both the
|
|
99
|
+
envelope stream and the snapshot.
|
|
100
|
+
- `chap_analytics.sample.support_desk()`, a generated week of review work; a
|
|
101
|
+
walkthrough notebook and a printed report over it.
|
|
102
|
+
- A differential suite: random workspaces against a live coordinator, read
|
|
103
|
+
both ways and checked against what the coordinator holds.
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chap-analytics
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
|
|
5
|
+
Author-email: Brightbeam AI <oss@brightbeam.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/BrightbeamAI/chap/tree/main/packages/chap-analytics
|
|
8
|
+
Project-URL: Repository, https://github.com/BrightbeamAI/chap
|
|
9
|
+
Project-URL: Bugs, https://github.com/BrightbeamAI/chap/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md
|
|
11
|
+
Project-URL: Walkthrough, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb
|
|
12
|
+
Project-URL: Report, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md
|
|
13
|
+
Project-URL: Specification, https://github.com/BrightbeamAI/chap/blob/main/SPECIFICATION.md
|
|
14
|
+
Project-URL: Roadmap, https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md
|
|
15
|
+
Keywords: chap,audit,analytics,pandas,human-in-the-loop,agent,vega-lite,review,provenance,multi-agent
|
|
16
|
+
Classifier: Development Status :: 3 - Alpha
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: pandas>=2.0
|
|
30
|
+
Requires-Dist: numpy>=1.23
|
|
31
|
+
Provides-Extra: coordinator
|
|
32
|
+
Requires-Dist: chap-coordinator>=0.2.13; extra == "coordinator"
|
|
33
|
+
Provides-Extra: viz
|
|
34
|
+
Requires-Dist: altair>=5; extra == "viz"
|
|
35
|
+
Requires-Dist: vl-convert-python>=1.0; extra == "viz"
|
|
36
|
+
Provides-Extra: graph
|
|
37
|
+
Requires-Dist: networkx>=3; extra == "graph"
|
|
38
|
+
Provides-Extra: notebook
|
|
39
|
+
Requires-Dist: nbformat>=5; extra == "notebook"
|
|
40
|
+
Requires-Dist: nbclient>=0.9; extra == "notebook"
|
|
41
|
+
Requires-Dist: ipykernel>=6; extra == "notebook"
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
44
|
+
Requires-Dist: chap-coordinator>=0.2.13; extra == "dev"
|
|
45
|
+
Requires-Dist: nbformat>=5; extra == "dev"
|
|
46
|
+
Requires-Dist: altair>=5; extra == "dev"
|
|
47
|
+
Requires-Dist: networkx>=3; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# chap-analytics
|
|
51
|
+
|
|
52
|
+
[](https://pypi.org/project/chap-analytics/)
|
|
53
|
+
[](https://pypi.org/project/chap-analytics/)
|
|
54
|
+
[](https://github.com/BrightbeamAI/chap/blob/main/LICENSE)
|
|
55
|
+
|
|
56
|
+
[CHAP](https://github.com/BrightbeamAI/chap) is a protocol for work that
|
|
57
|
+
people and agents do together under review. A coordinator, the CHAP server,
|
|
58
|
+
keeps an audit log of every request it handled: each entry is a JSON-RPC
|
|
59
|
+
envelope, hash-linked to the one before it where the coordinator chains its
|
|
60
|
+
log. That log records what people decided about agent work: what an agent
|
|
61
|
+
produced, what a person changed, why, under which rule, and when. Every
|
|
62
|
+
override carries the patch and the reviewer's reason. Every decision
|
|
63
|
+
carries who made it and when, against the time the review opened. Every
|
|
64
|
+
question an agent asked, every handoff between people, every vote and every
|
|
65
|
+
escalation is an envelope in the same log.
|
|
66
|
+
|
|
67
|
+
This package reads that log back and answers the questions a team running
|
|
68
|
+
agents under review has to answer: how often the work is changed and whether
|
|
69
|
+
that is falling, which corrections keep recurring, whether the agent's
|
|
70
|
+
reported confidence means anything, how long review takes and where it
|
|
71
|
+
waits, when an agent has earned a lighter mode of oversight (CHAP tasks run
|
|
72
|
+
in shadow, trial or production mode), whether reviewers agree with each
|
|
73
|
+
other, who decides on whose work, and whether every outcome that went out
|
|
74
|
+
had a person on its path.
|
|
75
|
+
|
|
76
|
+
Each answer comes as a table with its interval and sample size, a chart, and
|
|
77
|
+
a paragraph that states the number and the decision it supports. All of it
|
|
78
|
+
assembles into one self-contained HTML report that recomputes as the reader
|
|
79
|
+
filters.
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install chap-analytics
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Python 3.10 or later; pandas and numpy are the dependencies. The extras:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install 'chap-analytics[coordinator]' # read a live coordinator in-process; generate the sample chains
|
|
91
|
+
pip install 'chap-analytics[viz]' # Altair objects; SVG and PNG without Node
|
|
92
|
+
pip install 'chap-analytics[graph]' # hand the graph to networkx
|
|
93
|
+
pip install 'chap-analytics[notebook]' # regenerate the walkthrough notebook with its outputs
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Charts render in Jupyter with the base install. Saving a chart as SVG uses
|
|
97
|
+
`vl-convert` where it is installed and otherwise the Vega runtime the package
|
|
98
|
+
ships, under Node. The report needs nothing beyond the base install.
|
|
99
|
+
|
|
100
|
+
## Quick start
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from chap_analytics import from_sqlite, frames, briefs, charts, report
|
|
104
|
+
|
|
105
|
+
chain = from_sqlite("./chap.db", workspace="wsp_support") # or from_url, from_json, from_coordinator
|
|
106
|
+
f = frames(chain)
|
|
107
|
+
|
|
108
|
+
# Every decision in the table below, answered in a sentence.
|
|
109
|
+
for b in briefs.everything(f):
|
|
110
|
+
print(b.headline)
|
|
111
|
+
print(" ", b.decision)
|
|
112
|
+
|
|
113
|
+
# The same answers as charts. In a notebook, the last line draws it.
|
|
114
|
+
c = charts.everything(f)
|
|
115
|
+
c["rate_over_time"]
|
|
116
|
+
|
|
117
|
+
# One file, opens from disk, filters and recomputes in the browser.
|
|
118
|
+
report.write(f, "support.html")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Without a chain of your own, the package ships two:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from chap_analytics.sample import support_desk, synthetic
|
|
125
|
+
|
|
126
|
+
f = frames(support_desk()) # a week at a support desk, driven against a real coordinator
|
|
127
|
+
f = frames(synthetic(seed=1, tasks=400, # a workspace generated from stated rates, for checking statistics
|
|
128
|
+
override_rate=0.15, quorum_share=0.25, drift=(300, 0.4)))
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Both need `chap-coordinator`, which the `coordinator` extra installs.
|
|
132
|
+
|
|
133
|
+
## What the chain makes decidable
|
|
134
|
+
|
|
135
|
+
The package is organised around the decisions a team makes about its
|
|
136
|
+
agents. Each row is one question, the statistic that answers it, and the
|
|
137
|
+
chart that shows it. `briefs.everything` states every row that has a number
|
|
138
|
+
in words; `charts.everything` draws every row that has a chart; the report
|
|
139
|
+
carries all of them. A "substantive correction" below is an override that
|
|
140
|
+
reversed the agent's decision, or a rejection.
|
|
141
|
+
|
|
142
|
+
| Decision | Question | Statistic | Chart |
|
|
143
|
+
|---|---|---|---|
|
|
144
|
+
| Revise the prompt, or revise the policy | How often do reviewers change the agent's output, and do they refine it or reverse it? | Override, rejection and approval rates with Wilson intervals; refining share from `intent_preserved` | Rate over time with its interval band; refine and reverse split by task kind |
|
|
145
|
+
| Which part of the prompt to fix | Where do the corrections land in the artefact? | Patch path frequency by task kind | Heatmap of `top_path` (the first segment of the corrected path) against kind, with the rationales behind each cell one click away |
|
|
146
|
+
| Retune the routing thresholds | Does the agent's reported confidence track its outcomes? | Reliability curve, expected calibration error, Brier score | Reliability diagram with per-bin counts |
|
|
147
|
+
| Promote an agent from trial to production | Is the substantive correction rate below the bar, given how many tasks have been seen? | Beta posterior probability that the true rate is under the threshold; Wald's sequential test | Posterior density against the threshold; the sequential test between its bounds |
|
|
148
|
+
| Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue | Survival curve; median and 90th percentile per reviewer |
|
|
149
|
+
| Rewrite an ambiguous policy | Do reviewers agree with each other on the same artefact? | Fleiss' kappa across multi-reviewer passes; pairwise Cohen's kappa; abstentions by category | Agreement matrix |
|
|
150
|
+
| Clarify the task inputs | How often do agents have to ask, and does anyone answer in time? | Whispers (an agent's deadline-bound question to a person) per task, the share that lapsed unanswered, response time | Lapse rate by asker |
|
|
151
|
+
| Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
|
|
152
|
+
| Trust the record | Is the chain verifiable end to end? | Hash-linked, signed and transparency-log-submitted fractions | Coverage over time |
|
|
153
|
+
| Notice a change early | Has the correction rate moved since the last prompt or model change? | Bernoulli CUSUM with a stated false-alarm rate | Control chart with the alarms marked |
|
|
154
|
+
| Trace one outcome to its origin | What led to this action, and who was involved at each step? | The lineage of one task: draft, review, decisions, override, supersession, in order | A swimlane, one lane per participant |
|
|
155
|
+
| Find the bottleneck | Who does most of the reviewing, and does one reviewer decide most of one agent's work? | Betweenness on the collaboration graph; each agent's top reviewer share and Herfindahl index | Collaboration graph, edges weighted by work |
|
|
156
|
+
| Confirm there is a person in the loop | Which outcomes that went out had a person on their path? | Share of shipped outcomes with a human decision on the task or a predecessor, or a person doing the work; `coverage(f).attrs["uncovered"]` names the rest | The lineage view for any uncovered outcome |
|
|
157
|
+
| Separate duties | Does the same actor draft and approve, or propose and accept? | Same-actor pairs across roles, one row per finding in `duties(f)` | The collaboration graph, where a self-review shows as a reviewer deciding on their own work |
|
|
158
|
+
|
|
159
|
+
Every rate carries its sample size and its interval, and every estimate
|
|
160
|
+
with a minimum carries a `sufficient` flag that says whether there is
|
|
161
|
+
enough data to read it. A function that lacks the data to answer says so.
|
|
162
|
+
|
|
163
|
+
## The pictures
|
|
164
|
+
|
|
165
|
+
Every chart is a Vega-Lite specification built from a frame: a plain
|
|
166
|
+
dictionary, rendered in a notebook, in the report, or saved as SVG or PNG
|
|
167
|
+
for a paper. The pictures below come from a generated quarter with a story
|
|
168
|
+
in it: a correction rate near 15% for most of the period, quorum reviews on
|
|
169
|
+
a quarter of the tasks, one reviewer stricter than the others, and a drift
|
|
170
|
+
upwards late on. The reliability diagram comes from a second generated
|
|
171
|
+
workspace whose agent reports a confidence that tracks its outcomes.
|
|
172
|
+
[`docs/build_images.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/build_images.py)
|
|
173
|
+
is the script that makes them.
|
|
174
|
+
|
|
175
|
+
| | |
|
|
176
|
+
|---|---|
|
|
177
|
+
|  |  |
|
|
178
|
+
| The rate per week with its 95% interval. The rise in June is visible here; the chart on the right says when it became more than noise. | The CUSUM, tuned to the shift it should catch and the false-alarm rate it should keep, with the alarms marked. |
|
|
179
|
+
|  |  |
|
|
180
|
+
| Reported confidence against the share of work accepted as drafted. An agent whose confidence tracks its outcomes sits on the diagonal, and routing thresholds can be read off the curve. | The posterior for the substantive correction rate against the promotion threshold. The area to the left of the line is the chance the agent is already under it. |
|
|
181
|
+
|  |  |
|
|
182
|
+
| Which part of the artefact reviewers touch, by task kind. In the report, a click on a cell lists the rationales behind it. | Whether corrections kept the agent's decision and improved the wording, or reversed it. The two call for different fixes. |
|
|
183
|
+
|  |  |
|
|
184
|
+
| The share of reviews still waiting after each hour, with open reviews censored rather than dropped. | Wald's sequential probability ratio test on the same rate: it stops at the first crossing and says which way. |
|
|
185
|
+
|
|
186
|
+
## The chain as a graph
|
|
187
|
+
|
|
188
|
+
The same chain is also a graph. The workspace, its participants, tasks,
|
|
189
|
+
review passes, artefacts, decisions, whispers, deliberations and handoffs
|
|
190
|
+
are nodes. Who delegated, who was assigned, who was asked to review, who
|
|
191
|
+
decided, what an override was based on, which task superseded which, who
|
|
192
|
+
handed work to whom, who asked and who answered, who voted: those are the
|
|
193
|
+
edges. Every edge is an envelope or a field on one. The vocabulary is fixed
|
|
194
|
+
in `graph.NODE_TYPES` and `graph.EDGE_TYPES`, the diagram below is drawn
|
|
195
|
+
from those two tables, and the node-link export carries them under
|
|
196
|
+
`ontology`.
|
|
197
|
+
|
|
198
|
+
<p align="center">
|
|
199
|
+
<img src="https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ontology.svg" alt="The ontology of a CHAP workspace: nine node types and the edges between them" width="860">
|
|
200
|
+
</p>
|
|
201
|
+
|
|
202
|
+
Two views come out of the graph. The lineage of one task is everything that
|
|
203
|
+
led to it, in time order, with a lane per participant: the picture to start
|
|
204
|
+
from when someone asks what happened. The collaboration graph is the people
|
|
205
|
+
and agents of a workspace with the work that passed between them, where
|
|
206
|
+
load, concentration and separation of duties can be seen at a glance.
|
|
207
|
+
|
|
208
|
+
| | |
|
|
209
|
+
|---|---|
|
|
210
|
+
|  |  |
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from chap_analytics import graph
|
|
214
|
+
|
|
215
|
+
g = graph.build(f) # the whole chain
|
|
216
|
+
task_id = f.tasks["task_id"].iloc[-1]
|
|
217
|
+
graph.lineage_table(f, task_id) # one task's history, in order
|
|
218
|
+
graph.collaboration(f) # who worked with whom, weighted
|
|
219
|
+
graph.centrality(f) # betweenness per participant
|
|
220
|
+
graph.concentration(f) # each agent's top reviewer and Herfindahl index
|
|
221
|
+
graph.coverage(f) # shipped outcomes with a person on the path
|
|
222
|
+
graph.duties(f) # same-actor pairs that should be separate
|
|
223
|
+
graph.to_node_link(g) # also to_graphml(g) and to_networkx(g)
|
|
224
|
+
graph.ontology_svg() # the diagram above
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## The report
|
|
228
|
+
|
|
229
|
+
`report.write(f, "workspace.html")` produces one HTML file with the Vega
|
|
230
|
+
runtime, the data and the page inside it, so it opens from a file share
|
|
231
|
+
with no network. The front page carries a headline card for every decision
|
|
232
|
+
that has a number: the figure, its interval, the sample size and one line
|
|
233
|
+
on what it means for that workspace. Below it, one section per decision
|
|
234
|
+
with the charts and the brief.
|
|
235
|
+
|
|
236
|
+
The filter bar applies to everything on the page: date range, task kind,
|
|
237
|
+
agent, reviewer, mode and tag. Every chart and every headline recomputes in
|
|
238
|
+
the browser from the embedded rows, using a JavaScript mirror of the
|
|
239
|
+
library's statistics that the test suite checks against the Python numbers.
|
|
240
|
+
Brushing the time axis re-scopes the page. A click on a cell of the
|
|
241
|
+
correction heatmap lists the overrides behind it with their rationales. The
|
|
242
|
+
open queue is a list. A selector opens the lineage of any task.
|
|
243
|
+
|
|
244
|
+
Artefact content stays out of the file. Rationales are included by default
|
|
245
|
+
and can be left out with `rationales=False`.
|
|
246
|
+
|
|
247
|
+
## Watching a live workspace
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from chap_analytics import watch
|
|
251
|
+
|
|
252
|
+
w = watch.Watcher("http://localhost:8080/chap", "wsp_support",
|
|
253
|
+
report_path="support.html",
|
|
254
|
+
on_alarm=lambda a: print(a.headline))
|
|
255
|
+
w.run(interval_s=300)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
On each poll the watcher calls `audit.read`, the protocol method that
|
|
259
|
+
returns the log, from a sequence cursor, then re-projects, runs the drift
|
|
260
|
+
chart and regenerates the report. When the CUSUM crosses its decision
|
|
261
|
+
interval it calls `on_alarm` once with the metric, the task and time it
|
|
262
|
+
moved at, and the changed tasks among the twenty decided before it. The
|
|
263
|
+
source can be an HTTP endpoint, an in-process `Coordinator`, or any callable
|
|
264
|
+
that returns entries from a sequence number.
|
|
265
|
+
|
|
266
|
+
## Exports
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
from chap_analytics import export
|
|
270
|
+
|
|
271
|
+
cases = export.evaluation_cases(f) # one row per corrected task
|
|
272
|
+
export.to_jsonl(cases, "cases.jsonl") # input, agent output, corrected output, rationale, tags
|
|
273
|
+
export.prompt_revision_candidates(f, top=10) # the correction clusters most worth addressing, with examples
|
|
274
|
+
export.routing_calibration(f, target_acceptance=0.9) # the confidence threshold that reaches the target, if any
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
The task input is available where the chain was read with state (a SQLite
|
|
278
|
+
file or an in-process coordinator); from `audit.read` alone it is null. The
|
|
279
|
+
agent's output and the corrected output come from the envelopes themselves.
|
|
280
|
+
|
|
281
|
+
## Models
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
from chap_analytics import models
|
|
285
|
+
|
|
286
|
+
m = models.reviewer_severity(f)
|
|
287
|
+
m.attrs["fitted"], m.attrs.get("reason")
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
A reviewer who changes half of what they see may be strict, or may be seeing
|
|
291
|
+
weak work. With several reviewers deciding on several agents the two can be
|
|
292
|
+
separated: one number per agent for quality and one per reviewer for
|
|
293
|
+
severity, fitted as a Rasch-style logistic model in numpy, each with an
|
|
294
|
+
approximate standard error and the count it rests on. Below its minimum the
|
|
295
|
+
function declines to fit and says which minimum it fell short of.
|
|
296
|
+
|
|
297
|
+
## What each statistic needs
|
|
298
|
+
|
|
299
|
+
A new adopter has a dozen decisions in month one, and kappa, drift
|
|
300
|
+
detection and calibration curves need far more. So every estimate carries
|
|
301
|
+
its uncertainty: rates carry Wilson intervals, the promotion question is
|
|
302
|
+
answered with a posterior rather than a point, the survival curve carries
|
|
303
|
+
Greenwood bands, and each estimate with a minimum carries a `sufficient`
|
|
304
|
+
flag with the minimum it was judged against. The briefs read that flag and
|
|
305
|
+
say so where it is false.
|
|
306
|
+
[`docs/methods.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/methods.md)
|
|
307
|
+
states each method, what it assumes, and the minimum it asks for.
|
|
308
|
+
|
|
309
|
+
## The tables
|
|
310
|
+
|
|
311
|
+
Underneath the statistics are eleven documented tables, projected from the
|
|
312
|
+
chain by replaying the envelope stream.
|
|
313
|
+
|
|
314
|
+
| Table | Grain |
|
|
315
|
+
|---|---|
|
|
316
|
+
| `events` | one row per audit log entry |
|
|
317
|
+
| `tasks` | one row per task |
|
|
318
|
+
| `decisions` | one row per approve, reject, override or abstain |
|
|
319
|
+
| `overrides` | one row per correction, with its diff summarised |
|
|
320
|
+
| `patch_ops` | one row per RFC 6902 (JSON Patch) operation within an override |
|
|
321
|
+
| `participants` | one row per participant per workspace |
|
|
322
|
+
| `deliberations` | one row per group decision |
|
|
323
|
+
| `votes` | one row per vote |
|
|
324
|
+
| `whispers` | one row per deadline-bound question |
|
|
325
|
+
| `handoffs` | one row per proposed handoff |
|
|
326
|
+
| `routing` | one row per routing decision |
|
|
327
|
+
|
|
328
|
+
Every column is declared in
|
|
329
|
+
[`schema.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/chap_analytics/schema.py)
|
|
330
|
+
with its dtype and its provenance, and `describe()` returns the whole
|
|
331
|
+
contract as text. A column the source lacked a value for is present and
|
|
332
|
+
null, so code downstream sees missingness rather than a `KeyError`.
|
|
333
|
+
`f.to_csv(directory)` writes them all.
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from chap_analytics import from_sqlite, from_url, from_json, from_coordinator
|
|
337
|
+
|
|
338
|
+
from_sqlite("./chap.db", workspace="wsp_support") # the full snapshot
|
|
339
|
+
from_url("http://localhost:8080/chap", "wsp_support") # envelopes, via audit.read
|
|
340
|
+
from_json("export.json") # an audit.read result, a bare entry list, or a snapshot
|
|
341
|
+
from_coordinator(coord, workspace="wsp_support") # a live coordinator, in-process
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
A SQLite file or a live coordinator carries the workspace snapshot and the
|
|
345
|
+
audit log beside it. `audit.read`, which is what an MCP client can call,
|
|
346
|
+
returns the audit log alone. The tables are replayed from the envelope
|
|
347
|
+
stream, so most of what is worth analysing is available from either source:
|
|
348
|
+
the artefact under review arrives on `review.request` and the patch on
|
|
349
|
+
`decide.override`, so the before and the after of every correction come
|
|
350
|
+
from the envelopes themselves. Three things come from the snapshot alone:
|
|
351
|
+
deliberation and routing outcomes, which the server computes; the assignee
|
|
352
|
+
a `task.route` chose, which `assignee_certain` flags; and the certainty of
|
|
353
|
+
which server-minted id belongs to which creation, which `id_certain` flags.
|
|
354
|
+
|
|
355
|
+
The projection does the work that otherwise gets done in every notebook. It
|
|
356
|
+
parses `confidence` from its decimal-string wire form. It censors open
|
|
357
|
+
work, so `lifetime_s` is null while a task is unsettled and `settled` says
|
|
358
|
+
which rows are censored. It knows when a decision settled a review under
|
|
359
|
+
each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
|
|
360
|
+
review passes apart, so a task sent back for revision is measured from each
|
|
361
|
+
pass's own opening and `outcome` reads from the decision that settled the
|
|
362
|
+
last pass. It reconstructs the corrected artefact from the patch with the
|
|
363
|
+
coordinator's own RFC 6902 semantics. It counts the tasks the server mints
|
|
364
|
+
on escalation and supersession, with what they inherit from the original.
|
|
365
|
+
And it says how sure it is: `id_certain` and `assignee_certain` mark the
|
|
366
|
+
rows where the chain admits more than one reading, so the population to
|
|
367
|
+
draw conclusions from is a filter away.
|
|
368
|
+
|
|
369
|
+
## Redaction
|
|
370
|
+
|
|
371
|
+
Artefacts hold whatever the agent was working on: customer messages,
|
|
372
|
+
contracts, source code. A redactor sees every one of them before anything
|
|
373
|
+
reaches a table, and what the tables lack the charts, briefs, report and
|
|
374
|
+
exports lack too.
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
from chap_analytics import from_sqlite, redact_artefacts, frames
|
|
378
|
+
|
|
379
|
+
f = frames(from_sqlite("./chap.db", redact=redact_artefacts))
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
What goes: task inputs and outputs, the artefact under review and the
|
|
383
|
+
corrected one, the values a patch writes, free-text whisper answers, lapse
|
|
384
|
+
defaults, the inputs of a successor an escalation or supersession mints,
|
|
385
|
+
and the copies a snapshot holds. What stays, because it is the analysis:
|
|
386
|
+
counts, rates, latencies, tags, policy references, patch paths and
|
|
387
|
+
operations, which option a whisper answer chose, and the words participants
|
|
388
|
+
wrote about the work. A reviewer's rationale, a decline reason, a handoff
|
|
389
|
+
summary and a deliberation question are the people's account of what they
|
|
390
|
+
did. A whisper question is the agent's own words to a person; a deployment
|
|
391
|
+
that needs it removed strips the `question` field before loading.
|
|
392
|
+
|
|
393
|
+
## Sample data
|
|
394
|
+
|
|
395
|
+
`sample.support_desk()` generates a week at a support desk against a real
|
|
396
|
+
coordinator: an agent drafts replies to tickets and three people review
|
|
397
|
+
them, approving most, correcting some and sending a few back. One declares
|
|
398
|
+
a conflict of interest, work changes hands at a shift change, the agent
|
|
399
|
+
asks two questions and gets one answer, a policy exception goes to a vote,
|
|
400
|
+
and one ticket is escalated to legal.
|
|
401
|
+
|
|
402
|
+
`sample.synthetic()` generates a workspace from stated rates: the override
|
|
403
|
+
and rejection rates, the refining share, how many tasks go to two reviewers
|
|
404
|
+
and how often the second agrees, the latency range, how many are left open,
|
|
405
|
+
whisper and lapse rates, handoffs, a drift point, reviewer strictness and
|
|
406
|
+
agent quality, and how the agent's confidence relates to its outcomes. The
|
|
407
|
+
test suite checks every statistic against the truth that generated it.
|
|
408
|
+
|
|
409
|
+
The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
|
|
410
|
+
follows the sample week from the envelopes to the tables and on to every
|
|
411
|
+
decision in the table, with the charts drawn inline, and
|
|
412
|
+
[`examples/support_desk.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/support_desk.py)
|
|
413
|
+
prints the same analyses from the command line.
|
|
414
|
+
|
|
415
|
+
## Tests
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
pip install -e ".[dev]"
|
|
419
|
+
pytest
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
The fixtures drive a real coordinator, so the suite fails when the protocol
|
|
423
|
+
moves. Statistics are checked against generated chains whose truth is
|
|
424
|
+
known. Every chart is compiled and rendered by the Vega-Lite runtime the
|
|
425
|
+
package ships. The report is checked to be self-contained, and its
|
|
426
|
+
JavaScript is run under Node on the embedded tables and compared with the
|
|
427
|
+
Python numbers. The notebook is executed. A differential suite reads random
|
|
428
|
+
workspaces both ways and checks the tables against what the coordinator
|
|
429
|
+
holds. The chart and report checks need `node` on the path and are skipped
|
|
430
|
+
without it.
|
|
431
|
+
|
|
432
|
+
## Documentation
|
|
433
|
+
|
|
434
|
+
- [`docs/methods.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/methods.md): every statistic, what it assumes, what it needs, how to read it.
|
|
435
|
+
- [`docs/graph.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/graph.md): the ontology, the two views, the graph statistics and the exports.
|
|
436
|
+
- [`docs/report.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md): what is in the report and how it is built.
|
|
437
|
+
- [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
|
|
438
|
+
- [`CHANGELOG.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md).
|
|
439
|
+
|
|
440
|
+
## Licence
|
|
441
|
+
|
|
442
|
+
Apache 2.0. The report embeds Vega, Vega-Lite and vega-embed, which are
|
|
443
|
+
BSD-3-Clause; their licences ship in `chap_analytics/_vendor`.
|