chap-analytics 0.1.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.1.0/CHANGELOG.md +32 -0
- chap_analytics-0.1.0/LICENSE +201 -0
- chap_analytics-0.1.0/MANIFEST.in +2 -0
- chap_analytics-0.1.0/PKG-INFO +307 -0
- chap_analytics-0.1.0/README.md +267 -0
- chap_analytics-0.1.0/chap_analytics/__init__.py +45 -0
- chap_analytics-0.1.0/chap_analytics/_patch.py +211 -0
- chap_analytics-0.1.0/chap_analytics/frames.py +1704 -0
- chap_analytics-0.1.0/chap_analytics/load.py +308 -0
- chap_analytics-0.1.0/chap_analytics/py.typed +0 -0
- chap_analytics-0.1.0/chap_analytics/sample.py +281 -0
- chap_analytics-0.1.0/chap_analytics/schema.py +368 -0
- chap_analytics-0.1.0/chap_analytics.egg-info/PKG-INFO +307 -0
- chap_analytics-0.1.0/chap_analytics.egg-info/SOURCES.txt +27 -0
- chap_analytics-0.1.0/chap_analytics.egg-info/dependency_links.txt +1 -0
- chap_analytics-0.1.0/chap_analytics.egg-info/requires.txt +14 -0
- chap_analytics-0.1.0/chap_analytics.egg-info/top_level.txt +1 -0
- chap_analytics-0.1.0/pyproject.toml +58 -0
- chap_analytics-0.1.0/setup.cfg +4 -0
- chap_analytics-0.1.0/tests/conftest.py +192 -0
- chap_analytics-0.1.0/tests/test_differential.py +387 -0
- chap_analytics-0.1.0/tests/test_example.py +68 -0
- chap_analytics-0.1.0/tests/test_handoff_and_routing.py +309 -0
- chap_analytics-0.1.0/tests/test_identity.py +290 -0
- chap_analytics-0.1.0/tests/test_notebook.py +63 -0
- chap_analytics-0.1.0/tests/test_projection.py +351 -0
- chap_analytics-0.1.0/tests/test_redaction_and_malformed.py +279 -0
- chap_analytics-0.1.0/tests/test_review_passes.py +331 -0
- chap_analytics-0.1.0/tests/test_sample_and_export.py +66 -0
|
@@ -0,0 +1,32 @@
|
|
|
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 change.
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
First release: stage one of the analytics roadmap.
|
|
10
|
+
|
|
11
|
+
- Eleven documented tables, projected from a CHAP audit chain by replaying
|
|
12
|
+
the envelope stream: `events`, `tasks`, `decisions`, `overrides`,
|
|
13
|
+
`patch_ops`, `participants`, `deliberations`, `votes`, `whispers`,
|
|
14
|
+
`handoffs`, `routing`. Every column declared with its dtype and provenance.
|
|
15
|
+
- Four loaders: a SQLite store, a JSON export, an `audit.read` endpoint, and
|
|
16
|
+
a `Coordinator` in the same process.
|
|
17
|
+
- Review passes kept apart, so a task sent back for revision is measured from
|
|
18
|
+
each pass's own opening and `outcome` reads from the decision that settled
|
|
19
|
+
the last one.
|
|
20
|
+
- The corrected artefact reconstructed from the patch with the coordinator's
|
|
21
|
+
own RFC 6902 semantics, and checked against what the coordinator stored by
|
|
22
|
+
the differential suite.
|
|
23
|
+
- Successors minted by escalation and supersession counted as tasks, with
|
|
24
|
+
what they inherit from the original.
|
|
25
|
+
- `id_certain` and `assignee_certain`, so a row says which of its values are
|
|
26
|
+
inferred.
|
|
27
|
+
- A redactor hook that covers every artefact-bearing field, in both the
|
|
28
|
+
envelope stream and the snapshot.
|
|
29
|
+
- `chap_analytics.sample.support_desk()`, a generated week of review work; a
|
|
30
|
+
walkthrough notebook and a printed report over it.
|
|
31
|
+
- A differential suite: random workspaces against a live coordinator, read
|
|
32
|
+
both ways and checked against what the coordinator holds.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The CHAP Authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chap-analytics
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A CHAP audit chain as documented pandas tables: every task, decision, override, whisper, handoff and vote, ready to analyse
|
|
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: Specification, https://github.com/BrightbeamAI/chap/blob/main/SPECIFICATION.md
|
|
13
|
+
Project-URL: Roadmap, https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md
|
|
14
|
+
Keywords: chap,audit,analytics,pandas,human-in-the-loop,agent
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pandas>=2.0
|
|
29
|
+
Provides-Extra: coordinator
|
|
30
|
+
Requires-Dist: chap-coordinator>=0.2.13; extra == "coordinator"
|
|
31
|
+
Provides-Extra: notebook
|
|
32
|
+
Requires-Dist: nbformat>=5; extra == "notebook"
|
|
33
|
+
Requires-Dist: nbclient>=0.9; extra == "notebook"
|
|
34
|
+
Requires-Dist: ipykernel>=6; extra == "notebook"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
37
|
+
Requires-Dist: chap-coordinator>=0.2.13; extra == "dev"
|
|
38
|
+
Requires-Dist: nbformat>=5; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# chap-analytics
|
|
42
|
+
|
|
43
|
+
[](https://pypi.org/project/chap-analytics/)
|
|
44
|
+
[](https://pypi.org/project/chap-analytics/)
|
|
45
|
+
[](https://github.com/BrightbeamAI/chap/blob/main/LICENSE)
|
|
46
|
+
|
|
47
|
+
A CHAP audit chain, as pandas tables.
|
|
48
|
+
|
|
49
|
+
A CHAP chain records what people decided about agent work: what an agent
|
|
50
|
+
produced, what a person changed, why, under which rule, and when. That is a
|
|
51
|
+
human-labelled evaluation set with provenance, generated as a side effect of
|
|
52
|
+
ordinary review. This package projects the chain into eleven documented tables
|
|
53
|
+
so it can be analysed as one.
|
|
54
|
+
|
|
55
|
+
It is stage one of the
|
|
56
|
+
[analytics roadmap](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md)
|
|
57
|
+
and it stops at the tables. Statistics belong in a layer above, where their
|
|
58
|
+
assumptions can be stated.
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install chap-analytics
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Python 3.10 or later. `pandas` is the only dependency. Reading a chain from a
|
|
67
|
+
live `Coordinator` in the same process, or generating the sample week, needs
|
|
68
|
+
`chap-coordinator` as well:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install 'chap-analytics[coordinator]'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Reading a SQLite file, a JSON export or an HTTP endpoint needs the base
|
|
75
|
+
install alone.
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from chap_analytics import from_sqlite, frames
|
|
81
|
+
|
|
82
|
+
chain = from_sqlite("./chap.db", workspace="wsp_support")
|
|
83
|
+
f = frames(chain)
|
|
84
|
+
|
|
85
|
+
print(f.summary())
|
|
86
|
+
|
|
87
|
+
# Which part of the output do reviewers keep correcting?
|
|
88
|
+
f.patch_ops.groupby("top_path").size().sort_values(ascending=False)
|
|
89
|
+
|
|
90
|
+
# Does the agent's confidence track its outcomes?
|
|
91
|
+
f.tasks.groupby("outcome")["confidence"].describe()
|
|
92
|
+
|
|
93
|
+
# Are reviewers refining the agent's decision or reversing it?
|
|
94
|
+
f.overrides.intent_preserved.value_counts(dropna=False)
|
|
95
|
+
|
|
96
|
+
# Everything, as files.
|
|
97
|
+
f.to_csv("./week")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## A worked week
|
|
101
|
+
|
|
102
|
+
`chap_analytics.sample.support_desk()` generates a week at a support desk
|
|
103
|
+
against a real coordinator. An agent drafts replies to customer tickets and
|
|
104
|
+
three people review them. They approve most, correct some and send a few back.
|
|
105
|
+
One declares a conflict of interest, work changes hands at a shift change, the
|
|
106
|
+
agent asks two questions and gets one answer, a policy exception goes to a
|
|
107
|
+
vote, and one ticket is escalated to legal. Every action is a CHAP envelope,
|
|
108
|
+
and the chain comes back ready to project.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from chap_analytics import frames
|
|
112
|
+
from chap_analytics.sample import support_desk
|
|
113
|
+
|
|
114
|
+
f = frames(support_desk())
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Two guided versions of the same week ship with the repository:
|
|
118
|
+
|
|
119
|
+
- [`examples/chap_analytics_walkthrough.ipynb`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
|
|
120
|
+
follows the envelopes from `audit.read` to the tables, with each table's
|
|
121
|
+
grain, columns, dtypes and provenance explained beside the frames.
|
|
122
|
+
- [`examples/support_desk.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/support_desk.py)
|
|
123
|
+
prints ten short analyses of the week, each a count or a median with a line
|
|
124
|
+
on what it is for.
|
|
125
|
+
|
|
126
|
+
The week is generated on each run, so it reflects the coordinator that is
|
|
127
|
+
installed. The test suite runs both.
|
|
128
|
+
|
|
129
|
+
## The tables
|
|
130
|
+
|
|
131
|
+
| Table | Grain |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `events` | one row per audit log entry |
|
|
134
|
+
| `tasks` | one row per task |
|
|
135
|
+
| `decisions` | one row per approve, reject, override or abstain |
|
|
136
|
+
| `overrides` | one row per correction, with its diff summarised |
|
|
137
|
+
| `patch_ops` | one row per RFC 6902 operation within an override |
|
|
138
|
+
| `participants` | one row per participant per workspace |
|
|
139
|
+
| `deliberations` | one row per group decision |
|
|
140
|
+
| `votes` | one row per vote |
|
|
141
|
+
| `whispers` | one row per deadline-bound question |
|
|
142
|
+
| `handoffs` | one row per proposed handoff |
|
|
143
|
+
| `routing` | one row per routing decision |
|
|
144
|
+
|
|
145
|
+
Every column is declared in
|
|
146
|
+
[`schema.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/chap_analytics/schema.py)
|
|
147
|
+
with its dtype and its provenance. `describe()` prints the whole contract:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from chap_analytics import describe
|
|
151
|
+
print(describe())
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
A column the source lacked a value for is present and null. Code downstream
|
|
155
|
+
can reference any column and see missingness rather than a `KeyError`.
|
|
156
|
+
|
|
157
|
+
## Four sources
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from chap_analytics import from_sqlite, from_url, from_json, from_coordinator
|
|
161
|
+
|
|
162
|
+
from_sqlite("./chap.db", workspace="wsp_support") # the full snapshot
|
|
163
|
+
from_url("http://localhost:8080/chap", "wsp_support") # envelopes, via audit.read
|
|
164
|
+
from_json("export.json") # an audit.read result, a bare entry list, or a snapshot
|
|
165
|
+
from_coordinator(coord, workspace="wsp_support") # a live coordinator, in-process
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
A SQLite file or a live coordinator carries the workspace snapshot: every
|
|
169
|
+
task, override, deliberation and handoff as the coordinator holds it, and the
|
|
170
|
+
audit log beside them. `audit.read`, which is what an MCP client can obtain,
|
|
171
|
+
returns the audit log alone: every request parameter, in order, and
|
|
172
|
+
hash-linked where the coordinator chains its log.
|
|
173
|
+
|
|
174
|
+
The tables are **replayed** from the envelope stream, so most of what is worth
|
|
175
|
+
analysing is available from either source. The artefact under review arrives
|
|
176
|
+
on `review.request` and the patch on `decide.override`, so the before and the
|
|
177
|
+
after of every correction come from the envelopes themselves. Three things
|
|
178
|
+
come from the snapshot alone: deliberation and routing outcomes, which the
|
|
179
|
+
server computes; the assignee a `task.route` chose, which `assignee_certain`
|
|
180
|
+
flags; and the certainty of which server-minted id belongs to which creation,
|
|
181
|
+
which the section on identity below explains.
|
|
182
|
+
|
|
183
|
+
How far the two reads agree is measured. Random workspaces are driven against
|
|
184
|
+
a real coordinator and read both ways. For every task, decision, override,
|
|
185
|
+
whisper, deliberation and handoff, the row either matches what the coordinator
|
|
186
|
+
holds or is marked `id_certain` false.
|
|
187
|
+
|
|
188
|
+
## What the projection handles for you
|
|
189
|
+
|
|
190
|
+
**Parses `confidence`.** Fractional values travel the CHAP wire as decimal
|
|
191
|
+
strings, because canonicalisation admits integers alone
|
|
192
|
+
([SPECIFICATION §7](https://github.com/BrightbeamAI/chap/blob/main/SPECIFICATION.md)).
|
|
193
|
+
The tables carry a float.
|
|
194
|
+
|
|
195
|
+
**Censors open work.** `lifetime_s` is null while a task is unsettled, and
|
|
196
|
+
`settled` says which rows are censored. A mean over the finished work alone
|
|
197
|
+
flatters every latency figure; the flag lets you say so.
|
|
198
|
+
|
|
199
|
+
**Knows when a decision settled a review.** Under `all_approve` or `quorum:N`
|
|
200
|
+
an approval may leave the review open. `is_final` is computed with the rule the
|
|
201
|
+
coordinator applies. Under `all_approve` the coordinator waits on the reviewers
|
|
202
|
+
it can name, and a review addressed to a group alone has none to wait on, so
|
|
203
|
+
it treats that review as first-approve.
|
|
204
|
+
|
|
205
|
+
**Separates the review passes.** A task sent back for revision is reviewed
|
|
206
|
+
again, and the coordinator starts that review afresh. `review_index` says which
|
|
207
|
+
pass a decision belongs to, `n_reviews` counts the passes, `latency_s` is
|
|
208
|
+
measured from each pass's own opening, and `outcome` is read from the decision
|
|
209
|
+
that settled the last pass.
|
|
210
|
+
|
|
211
|
+
**Reconstructs the correction.** `based_on` is the artefact the reviewer saw
|
|
212
|
+
and `result` is the patch applied to it, using the coordinator's own RFC 6902
|
|
213
|
+
semantics. Both are available from `audit.read` alone. Where the snapshot
|
|
214
|
+
carries the artefact the coordinator stored, that one is used, and the
|
|
215
|
+
differential suite requires the replayed one to equal it.
|
|
216
|
+
|
|
217
|
+
**Counts the tasks the server minted.** `escalate.raise` and
|
|
218
|
+
`control.supersede` create a successor without a `task.create` envelope, and
|
|
219
|
+
give it what the original had. An escalation successor takes the original's
|
|
220
|
+
mode, and its kind where the spec omits one. A supersession successor takes
|
|
221
|
+
the original's assignee and mode where the spec omits them, and gets the same
|
|
222
|
+
`review_required` default a `task.create` would. The successor is a row like
|
|
223
|
+
any other, with `supersedes` linking it back.
|
|
224
|
+
|
|
225
|
+
**Keeps the orphans.** A task created and left alone still gets a row.
|
|
226
|
+
|
|
227
|
+
**Says how sure it is.** `id_certain` and `assignee_certain` mark the rows where
|
|
228
|
+
the chain admits more than one reading, so the population to draw conclusions
|
|
229
|
+
from is a filter away.
|
|
230
|
+
|
|
231
|
+
## Redaction
|
|
232
|
+
|
|
233
|
+
Artefacts hold whatever the agent was working on: customer messages,
|
|
234
|
+
contracts, source code. A redactor sees every one of them before anything
|
|
235
|
+
reaches a table.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from chap_analytics import from_sqlite, redact_artefacts, frames
|
|
239
|
+
|
|
240
|
+
f = frames(from_sqlite("./chap.db", redact=redact_artefacts))
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
What goes: task inputs and outputs, the artefact under review and the
|
|
244
|
+
corrected one, the values a patch writes, free-text whisper answers under
|
|
245
|
+
either of their two names, lapse defaults, the inputs of a successor an
|
|
246
|
+
escalation or supersession mints, and the copies a snapshot holds. All of it
|
|
247
|
+
goes in both the envelope stream and the workspace snapshot that also contains
|
|
248
|
+
it. A test plants a marker in each of those places and searches every cell of
|
|
249
|
+
every table for all of them.
|
|
250
|
+
|
|
251
|
+
What stays, because it is the analysis: counts, rates, latencies, tags, policy
|
|
252
|
+
references, patch paths and operations, which option a whisper answer chose,
|
|
253
|
+
and the words participants wrote about the work. A reviewer's rationale,
|
|
254
|
+
comment and decline reason, a handoff summary and a deliberation question are
|
|
255
|
+
the people's account of what they did, and the point of the chain. A whisper
|
|
256
|
+
question is the agent's own words to a person, and it stays too; an agent that
|
|
257
|
+
quotes customer content into a question puts that content in the log, and a
|
|
258
|
+
deployment that needs it removed strips the `question` field before loading.
|
|
259
|
+
|
|
260
|
+
## Identity
|
|
261
|
+
|
|
262
|
+
Server-minted identifiers are returned in the *result* of a call, and the
|
|
263
|
+
audit log records the envelopes. A task id therefore becomes visible when a
|
|
264
|
+
later envelope acts on it, and which creation produced which id is worked out
|
|
265
|
+
afterwards.
|
|
266
|
+
|
|
267
|
+
With the snapshot, the pairing is settled by what the creation envelope and
|
|
268
|
+
the stored task agree they are, with the order of appearance breaking ties.
|
|
269
|
+
From envelopes alone, the order of appearance is the evidence: it settles the
|
|
270
|
+
pairing when work proceeds one task at a time, and leaves it open when two
|
|
271
|
+
tasks are created before either is touched. The row says which case it is in.
|
|
272
|
+
`id_certain` is true where the evidence leaves one reading, so
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
f.tasks[f.tasks.id_certain]
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
is the population to draw conclusions about individual tasks from. Counts hold
|
|
279
|
+
either way: a creation that matches no observed id is given one marked
|
|
280
|
+
`unidentified`, and the total stays right.
|
|
281
|
+
|
|
282
|
+
The protocol settles more than the ordering can. A lapse notice concerns a
|
|
283
|
+
whisper whose deadline had passed. An answer comes from someone the whisper was
|
|
284
|
+
addressed to. A vote comes from someone the deliberation invited. An acceptance
|
|
285
|
+
comes from the named recipient. An id the caller supplied is in the opening
|
|
286
|
+
envelope itself. Each of those is used before the ordering is consulted, and
|
|
287
|
+
`frames.summary()` reports how many rows remain inferred.
|
|
288
|
+
|
|
289
|
+
## Tests
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
pip install -e ".[dev]"
|
|
293
|
+
pytest
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The fixtures drive a real coordinator. A generated fixture captures what the
|
|
297
|
+
coordinator does, and fails when the protocol moves.
|
|
298
|
+
|
|
299
|
+
Alongside the written cases there is a differential suite: random sequences
|
|
300
|
+
of accepted calls against a real coordinator, read both ways. The
|
|
301
|
+
tasks, decisions, overrides, whispers, deliberations and handoffs are checked
|
|
302
|
+
against what that coordinator holds, the corrected artefacts against the ones
|
|
303
|
+
it stored, and a floor is asserted on how many envelope-only rows are certain.
|
|
304
|
+
|
|
305
|
+
## Licence
|
|
306
|
+
|
|
307
|
+
Apache 2.0.
|