Skip to content

Commit 296303d

Browse files
feat: release Agr decision models
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
0 parents  commit 296303d

24 files changed

Lines changed: 2375 additions & 0 deletions

‎.github/pull_request_template.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Summary
2+
3+
## What changed
4+
5+
## How this was tested
6+
7+
## Risk and rollback

‎.github/workflows/tests.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python: ["3.11", "3.12"]
13+
steps:
14+
- uses: actions/checkout@v7
15+
- uses: astral-sh/setup-uv@v10.2.0
16+
with:
17+
python-version: ${{ matrix.python }}
18+
activate-environment: true
19+
- name: Install, with the CPU build of torch
20+
run: |
21+
uv pip install torch --index-url https://download.pytorch.org/whl/cpu
22+
uv pip install -e ".[test]"
23+
- run: pytest -q

‎.gitignore‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.venv/
2+
__pycache__/
3+
*.pyc
4+
.pytest_cache/
5+
/runs/
6+
/checkpoints/
7+
*.safetensors
8+
.env
9+
.DS_Store
10+
/uv.lock
11+
/dist/

‎DESIGN.md‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# How Agr works
2+
3+
Agr answers typed questions about a state with a probability for every possible answer. It reads the state and all the questions in one forward pass of a pretrained transformer, and it never generates text.
4+
5+
## A request becomes one sequence
6+
7+
The server turns each question into a list of options: `noul` (or `boolean`) becomes no / yes, `choice` becomes one option per name (with its description, if given), and `score` becomes one option per level. The state and the questions are then laid out as one token sequence, in one of two layouts set by the checkpoint's `readout`.
8+
9+
`letters` (Agr) keeps the instruction-tuned backbone's own chat format. The state opens the user turn; each question continues it with its options under single-token codes and ends where the model's reply begins:
10+
11+
```
12+
<user turn> Context: the state ... | Question: q1 Options: (A) option (B) option <end of turn> <model turn> Answer: ( | Question: q2 ...
13+
```
14+
15+
`bilinear` (Agr-flash) wraps the request in five marker tokens:
16+
17+
```
18+
<doc> the state ... <ask> question 1 <choice> option </choice> <choice> option </choice> <answer> <ask> question 2 ... <answer>
19+
```
20+
21+
Two rules keep the questions independent in both layouts:
22+
23+
- Each question's block attends to the state and to itself, never to another question's block.
24+
- Each block's positions start where the state ends, as if it were the only question.
25+
26+
So an answer is the same whichever other questions come with it, and in whatever order. In fp32 this holds to within 0.00001; in bf16 on a GPU, rounding moves answers by up to about 0.02. The state is read once however many questions there are. Gemma's sliding-window layers get the same rule, further limited to keys within the window by position, and SDPA applies the mask.
27+
28+
## Scoring
29+
30+
`letters`: the hidden vector at the end of each question's block goes through the backbone's own output layer (tied to its input embeddings), restricted to that question's option codes, with the backbone's logit soft-cap. The probabilities are the softmax of those logits divided by a temperature that depends on the number of options, `T(n) = max(min, a + b ln n)`, fitted by log loss on our development data and stored in the checkpoint's `config.json` (`temperature_by_options`). A question with more than ten options lists them as `(` code `) text` with the code kept a single token. `order_averaging: true` in the config reads each choice and yes/no question a second time with its options reversed and averages the two; Agr does not set it.
31+
32+
`bilinear`: the hidden vector at each `<answer>` token is projected to a query, and each option's tokens are averaged and projected to a key. The option probabilities are the softmax of their dot products.
33+
34+
Either way, a `noul` answer is the probability of yes, a `choice` answer is the most likely option, and a `score` answer is the expected level. `confidence` uses System One's definitions:
35+
36+
- choice: `(p_max - 1/K) / (1 - 1/K)` for `K` options, 0 for a uniform spread and 1 for certainty
37+
- score: `max(0, 1 - E|level - mode| / D)`, where `D` is the same distance for a uniform spread
38+
39+
Neither is an accuracy rate. The temperature was fitted on our development data, not yours, so check thresholds on your own data before relying on them (`agr eval` below reports calibration error).
40+
41+
Text in a request stays text: control tokens spelled out in it (the chat template's turn markers, or the five bilinear markers) are tokenized as plain text, so a request cannot forge them. With the `letters` readout the server writes a JSON state compactly, with each element's position written into arrays of eight or more, and puts a yes/no question's true/false descriptions into its two options.
42+
43+
## A checkpoint
44+
45+
| File | Holds |
46+
| --- | --- |
47+
| `config.json` | the readout, the token limits, and the temperature (`letters`) or the scorer size (`bilinear`) |
48+
| `backbone/` | the complete transformer in bf16, with its unmodified tokenizer and chat template |
49+
| `head.safetensors` | `bilinear` only: the marker embeddings and the query and key projections |
50+
51+
What was changed from each base model is listed in NOTICE.md.
52+
53+
## Serving
54+
55+
One request is one forward pass. Requests on the same GPU run one at a time, because models that share a device gain nothing from overlapping. A request takes up to 64 questions and 1 MB of body; the body limit is counted as it arrives, so a chunked upload is capped too. Token limits belong to the checkpoint: its `config.json` sets how much of the state and of each question is read (`max_state_tokens`, `max_question_tokens`) and the most tokens one request may hold (`max_request_tokens`, 12,288 when unset). A request over the token limit is refused with a 422; a state or question longer than its budget is cut, and the response says `"truncated": true`.
56+
57+
## Measuring it yourself
58+
59+
`agr eval` scores any System One endpoint (Agr, or anything else that speaks the schema) on a file of labelled requests, and reports accuracy, Brier score, calibration error and latency. `agr compare` pairs two runs question by question, matched on each request's content rather than its line number, and reports each accuracy with a 95% interval and an exact McNemar test of the difference.
60+
61+
```bash
62+
agr eval http://localhost:8000 labelled.jsonl --out agr.jsonl
63+
agr compare agr.jsonl other.jsonl
64+
```
65+
66+
Each line of a labelled file is a request whose questions also carry a `label`:
67+
68+
| Type | Label |
69+
| --- | --- |
70+
| `choice` | one of the option names |
71+
| `noul` | `true` or `false` |
72+
| `score` | `0` for the first level, `1` for the next, and so on |

‎LICENSE.md‎

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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 reasonable and customary use in describing the
141+
origin of the Work and 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+
Copyright 2026 Command Code
179+
180+
Licensed under the Apache License, Version 2.0 (the "License");
181+
you may not use this file except in compliance with the License.
182+
You may obtain a copy of the License at
183+
184+
http://www.apache.org/licenses/LICENSE-2.0
185+
186+
Unless required by applicable law or agreed to in writing, software
187+
distributed under the License is distributed on an "AS IS" BASIS,
188+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189+
See the License for the specific language governing permissions and
190+
limitations under the License.

‎NOTICE.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Notice
2+
3+
Agr<br>
4+
Copyright 2026 Command Code
5+
6+
## Base models
7+
8+
The Agr models are modified versions of these base models, both under the Apache License 2.0:
9+
10+
| Model | Base model |
11+
| --- | --- |
12+
| Agr | google/gemma-4-31B-it |
13+
| Agr-flash | HuggingFaceTB/SmolLM2-360M |
14+
15+
Modifications: fine-tuned weights merged into the base model. Agr keeps the base model's vocabulary, chat template and output layer, and adds a fitted answer temperature to its configuration. Agr-flash adds marker tokens to the vocabulary and a scoring head on top.
16+
17+
## Adapted work
18+
19+
Parts of Agr's letters readout are adapted from Decider (github.com/Mapika/decider), Copyright 2026 Mark Marosi, Apache License 2.0: the answer-slot prompt layout, the single-token option codes, the handling of a thinking block the chat template leaves open, the position indexes written into long JSON arrays, the "no:"/"yes:" option rendering, and the temperature as a function of the number of options. Option-order averaging follows Invergent AI's Surogate.
20+
21+
## Design
22+
23+
Agr's question-branch design follows TypeSafe's Jev, as described in Archer Hume's "Jev's Architecture Unmasked", and Kev. The request and response format follows TypeSafe's System One API, so TypeSafe's SDK works against an Agr server.
24+
25+
Agr is an independent project, not affiliated with or endorsed by TypeSafe, Decider's authors, or the authors of any model it is compared with.

0 commit comments

Comments
 (0)