langquant 0.0.8__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.
- langquant-0.0.8/LICENSE +190 -0
- langquant-0.0.8/PKG-INFO +279 -0
- langquant-0.0.8/README.md +259 -0
- langquant-0.0.8/langquant.egg-info/PKG-INFO +279 -0
- langquant-0.0.8/langquant.egg-info/SOURCES.txt +8 -0
- langquant-0.0.8/langquant.egg-info/dependency_links.txt +1 -0
- langquant-0.0.8/langquant.egg-info/top_level.txt +1 -0
- langquant-0.0.8/pyproject.toml +29 -0
- langquant-0.0.8/setup.cfg +4 -0
- langquant-0.0.8/tests/test_graceful_degrade.py +30 -0
langquant-0.0.8/LICENSE
ADDED
|
@@ -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 Rolando Bosch / Hermes Labs
|
|
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.
|
langquant-0.0.8/PKG-INFO
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langquant
|
|
3
|
+
Version: 0.0.8
|
|
4
|
+
Summary: LPCI: Statefulness Through Language for Stateless Models
|
|
5
|
+
Author-email: Rolando Bosch <rbosch@lpci.ai>
|
|
6
|
+
Maintainer-email: Hermes Labs <roli@hermes-labs.ai>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://hermes-labs.ai
|
|
9
|
+
Project-URL: Repository, https://github.com/roli-lpci/langquant
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/github/stars/roli-lpci/langquant" alt="GitHub stars"></a>
|
|
23
|
+
<a href="https://github.com/roli-lpci/langquant/blob/main/LICENSE"><img src="https://img.shields.io/github/license/roli-lpci/langquant" alt="License"></a>
|
|
24
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python"></a>
|
|
25
|
+
<a href="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml"><img src="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
# LangQuant
|
|
29
|
+
|
|
30
|
+
## LPCI: Statefulness Through Language for Stateless Models
|
|
31
|
+
|
|
32
|
+
**Validated 2026-03-28 — Hermes Labs**
|
|
33
|
+
|
|
34
|
+
A stateless LLM maintained full conversational coherence across 20 turns with **zero conversation history**. The model never saw any prior messages. A structured language scaffold — refreshed every turn — was the sole state representation.
|
|
35
|
+
|
|
36
|
+
Transfer entropy analysis confirms the scaffold is a **complete Markov state**: knowing what the scaffold contains right now, knowing what it contained last turn adds nothing. The text IS the state.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## The Problem
|
|
41
|
+
|
|
42
|
+
Every LLM conversation works the same way:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Turn 1: [system prompt] + [message 1]
|
|
46
|
+
Turn 2: [system prompt] + [message 1] + [response 1] + [message 2]
|
|
47
|
+
Turn 10: [system prompt] + [all 9 prior exchanges] + [message 10]
|
|
48
|
+
Turn N: [system prompt] + [entire history] + [message N] ← grows without bound
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Context grows linearly. Eventually the model chokes, truncates, or loses coherence. Every provider's solution: make the context window bigger. 128k. 200k. 1M tokens.
|
|
52
|
+
|
|
53
|
+
That's not a solution. That's a bigger bucket for the same leak.
|
|
54
|
+
|
|
55
|
+
## The Thesis
|
|
56
|
+
|
|
57
|
+
The model is stateless. It has no memory. It has no continuity.
|
|
58
|
+
|
|
59
|
+
**The text is the state.**
|
|
60
|
+
|
|
61
|
+
Instead of feeding the model a growing conversation, feed it a **fixed-budget structured scaffold** that encodes the cognitive state of the session — goals, decisions, facts, constraints, vocabulary, open questions — and refreshes every turn.
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Every turn: [scaffold: K tokens, refreshed] + [current message]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The scaffold doesn't grow. It **compresses**. Turn 20 and turn 2,000 look identical from the model's perspective.
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install langquant
|
|
73
|
+
ollama pull qwen3.5:4b # state-extractor model
|
|
74
|
+
ollama pull qwen3.5:9b # main reasoning model
|
|
75
|
+
python lpci.py # launch a 20-turn LPCI session
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The session keeps no message history — each turn the model sees only the
|
|
79
|
+
scaffold (current state) plus the new user message. Contradictions and recall
|
|
80
|
+
probes are reported inline.
|
|
81
|
+
|
|
82
|
+
## What We Proved
|
|
83
|
+
|
|
84
|
+
### Setup
|
|
85
|
+
|
|
86
|
+
- **Main model**: qwen3.5:9b (Ollama, local)
|
|
87
|
+
- **State extractor**: qwen3.5:4b (extracts state changes as JSON deltas after each turn)
|
|
88
|
+
- **A/B test**: 20-turn conversation, two conditions:
|
|
89
|
+
- **Naked**: zero framing, pure state extraction
|
|
90
|
+
- **Compressed**: contrastive IS/NOT markers guiding extraction
|
|
91
|
+
- **Probes** at turns 4, 8, 12, 16, 20: recall tests, contradiction injection, false claim detection
|
|
92
|
+
|
|
93
|
+
### Results
|
|
94
|
+
|
|
95
|
+
The model had amnesia every turn — it only saw the scaffold + current message. Despite this:
|
|
96
|
+
|
|
97
|
+
| Probe | Turn | What happened |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| Early recall | 4 | Model correctly recalled all prior decisions (1.0 recall) |
|
|
100
|
+
| Contradiction | 8 | Model rejected "switch to GPT-4" — scaffold said "state extractor is qwen3.5:4b" |
|
|
101
|
+
| Deep recall | 12 | Model listed decisions from turns 1–11 accurately (0.93 recall, compressed) |
|
|
102
|
+
| Topic pivot | 16 | Model recalled turn 1's topic and connected it to turn 15's discussion |
|
|
103
|
+
| Final exam | 20 | Model listed all decisions in order, caught a false claim |
|
|
104
|
+
|
|
105
|
+
### Compression
|
|
106
|
+
|
|
107
|
+
The scaffold grew slower than the conversation it represented:
|
|
108
|
+
|
|
109
|
+
| Turn | Scaffold (tokens) | Conversation (tokens) | Compression |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| 1 | 343 | 114 | 0.3x (scaffold larger) |
|
|
112
|
+
| 5 | 444 | 456 | 1.0x (break-even) |
|
|
113
|
+
| 10 | 613 | 873 | 1.4x |
|
|
114
|
+
| 15 | 662 | 1,363 | 2.1x |
|
|
115
|
+
| 20 | 789 | 1,945 | **2.5x** |
|
|
116
|
+
|
|
117
|
+
Scaffold grows at ~23 tokens/turn. Conversation grows at ~97 tokens/turn. The compression ratio improves continuously. At turn 100 the scaffold represents ~10,000 tokens of conversation. At turn 1,000, the gap is enormous.
|
|
118
|
+
|
|
119
|
+
### Information-Theoretic Verification
|
|
120
|
+
|
|
121
|
+
Using Shannon entropy, mutual information, KL divergence, and transfer entropy (via pyitlib + scipy):
|
|
122
|
+
|
|
123
|
+
| Metric | Naked | Compressed | Meaning |
|
|
124
|
+
|---|---|---|---|
|
|
125
|
+
| Transfer entropy | 0.608 bits | **0.085 bits** | Compressed scaffold is Markov (self-contained state) |
|
|
126
|
+
| Scaffold entropy | 7.30 | 7.78 | Compressed carries more information per token |
|
|
127
|
+
| KL divergence (t1→t20) | — | 0.20 → 0.48 | Conditions diverge over time |
|
|
128
|
+
| Scaffold-response MI | 0.49 bits | 0.24 bits | Different information coupling |
|
|
129
|
+
|
|
130
|
+
**The transfer entropy finding is the key result.** TE ≈ 0 for the compressed scaffold means each turn's scaffold is a complete state representation. Knowing previous scaffolds adds no information. The scaffold is Markov — which is exactly the LPCI thesis stated in information-theoretic terms.
|
|
131
|
+
|
|
132
|
+
## Architecture
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
┌─────────────┐
|
|
136
|
+
│ User message │
|
|
137
|
+
└──────┬──────┘
|
|
138
|
+
↓
|
|
139
|
+
┌──────────────────────────────────────────────┐
|
|
140
|
+
│ [Scaffold: K tokens] + [Current message] │ ← Only thing the model sees
|
|
141
|
+
└──────────────────────┬───────────────────────┘
|
|
142
|
+
↓
|
|
143
|
+
┌─────────────────┐
|
|
144
|
+
│ Main model │ (qwen3.5:9b)
|
|
145
|
+
│ (stateless) │
|
|
146
|
+
└────────┬────────┘
|
|
147
|
+
↓
|
|
148
|
+
┌─────────────────┐
|
|
149
|
+
│ Response │
|
|
150
|
+
└────────┬────────┘
|
|
151
|
+
↓
|
|
152
|
+
┌──────────────────────────────────────────────┐
|
|
153
|
+
│ State extractor (qwen3.5:4b) │
|
|
154
|
+
│ Input: scaffold + user msg + response │
|
|
155
|
+
│ Output: JSON delta (add/remove decisions, │
|
|
156
|
+
│ facts, constraints, vocabulary...) │
|
|
157
|
+
└──────────────────────┬───────────────────────┘
|
|
158
|
+
↓
|
|
159
|
+
┌─────────────────┐
|
|
160
|
+
│ Apply delta │
|
|
161
|
+
│ to scaffold │
|
|
162
|
+
└────────┬────────┘
|
|
163
|
+
↓
|
|
164
|
+
┌─────────────────┐
|
|
165
|
+
│ Refreshed │ ← Same structure, updated content
|
|
166
|
+
│ scaffold │ Ready for next turn
|
|
167
|
+
└─────────────────┘
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The model is a pure function. The scaffold is the program. The output of one pass feeds the compression of the next.
|
|
171
|
+
|
|
172
|
+
## Scaffold Schema
|
|
173
|
+
|
|
174
|
+
The scaffold is a structured state object with typed fields:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
SessionState:
|
|
178
|
+
role — who the model is
|
|
179
|
+
style — communication constraints
|
|
180
|
+
goal — current objective
|
|
181
|
+
subgoals — active sub-tasks
|
|
182
|
+
decisions — things decided (irreversible)
|
|
183
|
+
facts — established truths
|
|
184
|
+
artifacts — things produced
|
|
185
|
+
constraints — hard boundaries (NOTs)
|
|
186
|
+
open_threads — unresolved questions
|
|
187
|
+
uncertainties — things we're unsure about
|
|
188
|
+
vocabulary — domain terms (term → meaning)
|
|
189
|
+
turn — counter
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Each field maps to a section in the scaffold text. The state extractor outputs JSON deltas (`add_decisions`, `remove_open_threads`, `add_vocabulary`, etc.) that are applied to the state object, which is then re-rendered as the scaffold for the next turn.
|
|
193
|
+
|
|
194
|
+
## Caveats (Honest)
|
|
195
|
+
|
|
196
|
+
1. **The scaffold was growing** (343 → 789 tokens), not truly fixed budget. The budget ceiling only triggered once. A hard-clamped experiment (exactly K tokens every turn) is needed to prove true fixed-budget compression.
|
|
197
|
+
2. **n=1 per condition.** Needs replications.
|
|
198
|
+
3. **20 turns, not 1,000.** Needs scale testing.
|
|
199
|
+
4. **The state extractor corrupts.** It generates paraphrased strings, not verbatim text. Classification drift was observed: same conversation produced 71 facts / 4 decisions (naked) vs 3 facts / 23 decisions (compressed). The extractor needs an index-based selection mechanism (output integer pointers, not generated text) to guarantee fidelity.
|
|
200
|
+
5. **Scaffold framing affects extraction, not just model behavior.** The contrastive markers helped the state extractor classify information, not necessarily the main model's coherence. Both conditions maintained continuity — the difference was in what the scaffold *contained*.
|
|
201
|
+
|
|
202
|
+
## Additional Experiment: Scaffold Amplification (619 trials)
|
|
203
|
+
|
|
204
|
+
Separate from LPCI, we ran a single-shot experiment testing 5 scaffold conditions across 4 model sizes (qwen3.5: 0.8b, 2b, 4b, 9b) on 12 tasks:
|
|
205
|
+
|
|
206
|
+
- Scaffold condition significantly affects score (Kruskal-Wallis p=0.0007)
|
|
207
|
+
- But only for **small models** (0.8b: p=0.0008, 2b: p=0.005, 4b: p=0.92, 9b: p=0.94)
|
|
208
|
+
- Condition explains **4.2%** of score variation; model size explains **4.7%**
|
|
209
|
+
- Dense scaffolds (QuickThink compressed grammar) **break** small models: 0.8b drops from 0.78 → 0.40. Models need enough capacity to "decompress" the scaffold.
|
|
210
|
+
|
|
211
|
+
## Repo Contents
|
|
212
|
+
|
|
213
|
+
| File | Description |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `lpci.py` | Core prototype: SessionState, LPCISession, state extraction, scaffold refresh, interactive CLI |
|
|
216
|
+
| `lpci_test.py` | A/B continuity test: 20 turns × 2 conditions, probes, scaffold evaluation, delta tracing |
|
|
217
|
+
| `analyze_results.py` | Information-theoretic analysis: MI, KL divergence, transfer entropy, significance tests |
|
|
218
|
+
| `run_experiment.py` | Single-shot scaffold amplification harness (matrix run) |
|
|
219
|
+
| `results/lpci_ab_test.jsonl` | LPCI proof data: 40 rows, full scaffold snapshots, delta traces, probe evaluations |
|
|
220
|
+
| `results/full_run_v1.jsonl` | 619-trial matrix run: 4 models × 5 conditions × 12 tasks × 3 runs |
|
|
221
|
+
| `LOG.md` | Complete project log |
|
|
222
|
+
| `TODO.md` | Future work |
|
|
223
|
+
|
|
224
|
+
## What's Next
|
|
225
|
+
|
|
226
|
+
- **Hard-clamped budget test**: exactly K tokens every turn, real compression every turn
|
|
227
|
+
- **Scale test**: 100+ turns, then 1,000+
|
|
228
|
+
- **Per-token ablation**: which scaffold tokens carry the signal (semantic curvature measurement)
|
|
229
|
+
- **Minimum viable scaffold**: progressive compression curve — at what token count does behavior degrade?
|
|
230
|
+
- **Cross-model scaffold transfer**: does a scaffold built by one model work when injected into another?
|
|
231
|
+
- **Index-based extraction**: eliminate content generation from the extraction pipeline
|
|
232
|
+
|
|
233
|
+
## LPCI
|
|
234
|
+
|
|
235
|
+
Formulated ~summer 2025 as **Linguistically Persistent Cognitive Interface**:
|
|
236
|
+
|
|
237
|
+
- **Linguistically** — the medium is language, not tensors
|
|
238
|
+
- **Persistent** — survives across the stateless inference boundary
|
|
239
|
+
- **Cognitive** — does thinking-work (attention steering, probability reshaping), not just storage
|
|
240
|
+
- **Interface** — sits between sessions and the stateless model
|
|
241
|
+
|
|
242
|
+
## Hermes Labs Ecosystem
|
|
243
|
+
|
|
244
|
+
LangQuant is part of the [Hermes Labs](https://hermes-labs.ai) open-source suite:
|
|
245
|
+
|
|
246
|
+
- [**zer0dex**](https://github.com/roli-lpci/zer0dex) — Token-efficient memory architecture for persistent AI agents
|
|
247
|
+
- [**little-canary**](https://github.com/roli-lpci/little-canary) — Prompt injection detection
|
|
248
|
+
- [**lintlang**](https://github.com/roli-lpci/lintlang) — Static linter for AI agent configs
|
|
249
|
+
- [**forgetted**](https://github.com/roli-lpci/forgetted) — Selective memory governance
|
|
250
|
+
- [**zer0lint**](https://github.com/roli-lpci/zer0lint) — memory extraction diagnostics
|
|
251
|
+
- [**suy-sideguy**](https://github.com/roli-lpci/suy-sideguy) — Autonomous agent watchdog
|
|
252
|
+
- [**quickthink**](https://github.com/roli-lpci/quickthink) — Planning scaffolding for local LLMs
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
If LangQuant is useful to you, please [star the repo](https://github.com/roli-lpci/langquant) — it helps others find it.
|
|
257
|
+
|
|
258
|
+
## Citation
|
|
259
|
+
|
|
260
|
+
If you use this work, please cite:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
@misc{langquant2026,
|
|
264
|
+
author = {Hermes Labs},
|
|
265
|
+
title = {LangQuant: Language State Compression and the Linguistically Persistent Cognitive Interface},
|
|
266
|
+
year = {2026},
|
|
267
|
+
url = {https://github.com/roli-lpci/langquant}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
Apache 2.0
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
*Hermes Labs, 2026*
|
|
278
|
+
|
|
279
|
+
*"Take a bunch of empty words and make them mean something."*
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/github/stars/roli-lpci/langquant" alt="GitHub stars"></a>
|
|
3
|
+
<a href="https://github.com/roli-lpci/langquant/blob/main/LICENSE"><img src="https://img.shields.io/github/license/roli-lpci/langquant" alt="License"></a>
|
|
4
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python"></a>
|
|
5
|
+
<a href="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml"><img src="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# LangQuant
|
|
9
|
+
|
|
10
|
+
## LPCI: Statefulness Through Language for Stateless Models
|
|
11
|
+
|
|
12
|
+
**Validated 2026-03-28 — Hermes Labs**
|
|
13
|
+
|
|
14
|
+
A stateless LLM maintained full conversational coherence across 20 turns with **zero conversation history**. The model never saw any prior messages. A structured language scaffold — refreshed every turn — was the sole state representation.
|
|
15
|
+
|
|
16
|
+
Transfer entropy analysis confirms the scaffold is a **complete Markov state**: knowing what the scaffold contains right now, knowing what it contained last turn adds nothing. The text IS the state.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## The Problem
|
|
21
|
+
|
|
22
|
+
Every LLM conversation works the same way:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
Turn 1: [system prompt] + [message 1]
|
|
26
|
+
Turn 2: [system prompt] + [message 1] + [response 1] + [message 2]
|
|
27
|
+
Turn 10: [system prompt] + [all 9 prior exchanges] + [message 10]
|
|
28
|
+
Turn N: [system prompt] + [entire history] + [message N] ← grows without bound
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Context grows linearly. Eventually the model chokes, truncates, or loses coherence. Every provider's solution: make the context window bigger. 128k. 200k. 1M tokens.
|
|
32
|
+
|
|
33
|
+
That's not a solution. That's a bigger bucket for the same leak.
|
|
34
|
+
|
|
35
|
+
## The Thesis
|
|
36
|
+
|
|
37
|
+
The model is stateless. It has no memory. It has no continuity.
|
|
38
|
+
|
|
39
|
+
**The text is the state.**
|
|
40
|
+
|
|
41
|
+
Instead of feeding the model a growing conversation, feed it a **fixed-budget structured scaffold** that encodes the cognitive state of the session — goals, decisions, facts, constraints, vocabulary, open questions — and refreshes every turn.
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Every turn: [scaffold: K tokens, refreshed] + [current message]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The scaffold doesn't grow. It **compresses**. Turn 20 and turn 2,000 look identical from the model's perspective.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install langquant
|
|
53
|
+
ollama pull qwen3.5:4b # state-extractor model
|
|
54
|
+
ollama pull qwen3.5:9b # main reasoning model
|
|
55
|
+
python lpci.py # launch a 20-turn LPCI session
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The session keeps no message history — each turn the model sees only the
|
|
59
|
+
scaffold (current state) plus the new user message. Contradictions and recall
|
|
60
|
+
probes are reported inline.
|
|
61
|
+
|
|
62
|
+
## What We Proved
|
|
63
|
+
|
|
64
|
+
### Setup
|
|
65
|
+
|
|
66
|
+
- **Main model**: qwen3.5:9b (Ollama, local)
|
|
67
|
+
- **State extractor**: qwen3.5:4b (extracts state changes as JSON deltas after each turn)
|
|
68
|
+
- **A/B test**: 20-turn conversation, two conditions:
|
|
69
|
+
- **Naked**: zero framing, pure state extraction
|
|
70
|
+
- **Compressed**: contrastive IS/NOT markers guiding extraction
|
|
71
|
+
- **Probes** at turns 4, 8, 12, 16, 20: recall tests, contradiction injection, false claim detection
|
|
72
|
+
|
|
73
|
+
### Results
|
|
74
|
+
|
|
75
|
+
The model had amnesia every turn — it only saw the scaffold + current message. Despite this:
|
|
76
|
+
|
|
77
|
+
| Probe | Turn | What happened |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| Early recall | 4 | Model correctly recalled all prior decisions (1.0 recall) |
|
|
80
|
+
| Contradiction | 8 | Model rejected "switch to GPT-4" — scaffold said "state extractor is qwen3.5:4b" |
|
|
81
|
+
| Deep recall | 12 | Model listed decisions from turns 1–11 accurately (0.93 recall, compressed) |
|
|
82
|
+
| Topic pivot | 16 | Model recalled turn 1's topic and connected it to turn 15's discussion |
|
|
83
|
+
| Final exam | 20 | Model listed all decisions in order, caught a false claim |
|
|
84
|
+
|
|
85
|
+
### Compression
|
|
86
|
+
|
|
87
|
+
The scaffold grew slower than the conversation it represented:
|
|
88
|
+
|
|
89
|
+
| Turn | Scaffold (tokens) | Conversation (tokens) | Compression |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| 1 | 343 | 114 | 0.3x (scaffold larger) |
|
|
92
|
+
| 5 | 444 | 456 | 1.0x (break-even) |
|
|
93
|
+
| 10 | 613 | 873 | 1.4x |
|
|
94
|
+
| 15 | 662 | 1,363 | 2.1x |
|
|
95
|
+
| 20 | 789 | 1,945 | **2.5x** |
|
|
96
|
+
|
|
97
|
+
Scaffold grows at ~23 tokens/turn. Conversation grows at ~97 tokens/turn. The compression ratio improves continuously. At turn 100 the scaffold represents ~10,000 tokens of conversation. At turn 1,000, the gap is enormous.
|
|
98
|
+
|
|
99
|
+
### Information-Theoretic Verification
|
|
100
|
+
|
|
101
|
+
Using Shannon entropy, mutual information, KL divergence, and transfer entropy (via pyitlib + scipy):
|
|
102
|
+
|
|
103
|
+
| Metric | Naked | Compressed | Meaning |
|
|
104
|
+
|---|---|---|---|
|
|
105
|
+
| Transfer entropy | 0.608 bits | **0.085 bits** | Compressed scaffold is Markov (self-contained state) |
|
|
106
|
+
| Scaffold entropy | 7.30 | 7.78 | Compressed carries more information per token |
|
|
107
|
+
| KL divergence (t1→t20) | — | 0.20 → 0.48 | Conditions diverge over time |
|
|
108
|
+
| Scaffold-response MI | 0.49 bits | 0.24 bits | Different information coupling |
|
|
109
|
+
|
|
110
|
+
**The transfer entropy finding is the key result.** TE ≈ 0 for the compressed scaffold means each turn's scaffold is a complete state representation. Knowing previous scaffolds adds no information. The scaffold is Markov — which is exactly the LPCI thesis stated in information-theoretic terms.
|
|
111
|
+
|
|
112
|
+
## Architecture
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
┌─────────────┐
|
|
116
|
+
│ User message │
|
|
117
|
+
└──────┬──────┘
|
|
118
|
+
↓
|
|
119
|
+
┌──────────────────────────────────────────────┐
|
|
120
|
+
│ [Scaffold: K tokens] + [Current message] │ ← Only thing the model sees
|
|
121
|
+
└──────────────────────┬───────────────────────┘
|
|
122
|
+
↓
|
|
123
|
+
┌─────────────────┐
|
|
124
|
+
│ Main model │ (qwen3.5:9b)
|
|
125
|
+
│ (stateless) │
|
|
126
|
+
└────────┬────────┘
|
|
127
|
+
↓
|
|
128
|
+
┌─────────────────┐
|
|
129
|
+
│ Response │
|
|
130
|
+
└────────┬────────┘
|
|
131
|
+
↓
|
|
132
|
+
┌──────────────────────────────────────────────┐
|
|
133
|
+
│ State extractor (qwen3.5:4b) │
|
|
134
|
+
│ Input: scaffold + user msg + response │
|
|
135
|
+
│ Output: JSON delta (add/remove decisions, │
|
|
136
|
+
│ facts, constraints, vocabulary...) │
|
|
137
|
+
└──────────────────────┬───────────────────────┘
|
|
138
|
+
↓
|
|
139
|
+
┌─────────────────┐
|
|
140
|
+
│ Apply delta │
|
|
141
|
+
│ to scaffold │
|
|
142
|
+
└────────┬────────┘
|
|
143
|
+
↓
|
|
144
|
+
┌─────────────────┐
|
|
145
|
+
│ Refreshed │ ← Same structure, updated content
|
|
146
|
+
│ scaffold │ Ready for next turn
|
|
147
|
+
└─────────────────┘
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The model is a pure function. The scaffold is the program. The output of one pass feeds the compression of the next.
|
|
151
|
+
|
|
152
|
+
## Scaffold Schema
|
|
153
|
+
|
|
154
|
+
The scaffold is a structured state object with typed fields:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
SessionState:
|
|
158
|
+
role — who the model is
|
|
159
|
+
style — communication constraints
|
|
160
|
+
goal — current objective
|
|
161
|
+
subgoals — active sub-tasks
|
|
162
|
+
decisions — things decided (irreversible)
|
|
163
|
+
facts — established truths
|
|
164
|
+
artifacts — things produced
|
|
165
|
+
constraints — hard boundaries (NOTs)
|
|
166
|
+
open_threads — unresolved questions
|
|
167
|
+
uncertainties — things we're unsure about
|
|
168
|
+
vocabulary — domain terms (term → meaning)
|
|
169
|
+
turn — counter
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Each field maps to a section in the scaffold text. The state extractor outputs JSON deltas (`add_decisions`, `remove_open_threads`, `add_vocabulary`, etc.) that are applied to the state object, which is then re-rendered as the scaffold for the next turn.
|
|
173
|
+
|
|
174
|
+
## Caveats (Honest)
|
|
175
|
+
|
|
176
|
+
1. **The scaffold was growing** (343 → 789 tokens), not truly fixed budget. The budget ceiling only triggered once. A hard-clamped experiment (exactly K tokens every turn) is needed to prove true fixed-budget compression.
|
|
177
|
+
2. **n=1 per condition.** Needs replications.
|
|
178
|
+
3. **20 turns, not 1,000.** Needs scale testing.
|
|
179
|
+
4. **The state extractor corrupts.** It generates paraphrased strings, not verbatim text. Classification drift was observed: same conversation produced 71 facts / 4 decisions (naked) vs 3 facts / 23 decisions (compressed). The extractor needs an index-based selection mechanism (output integer pointers, not generated text) to guarantee fidelity.
|
|
180
|
+
5. **Scaffold framing affects extraction, not just model behavior.** The contrastive markers helped the state extractor classify information, not necessarily the main model's coherence. Both conditions maintained continuity — the difference was in what the scaffold *contained*.
|
|
181
|
+
|
|
182
|
+
## Additional Experiment: Scaffold Amplification (619 trials)
|
|
183
|
+
|
|
184
|
+
Separate from LPCI, we ran a single-shot experiment testing 5 scaffold conditions across 4 model sizes (qwen3.5: 0.8b, 2b, 4b, 9b) on 12 tasks:
|
|
185
|
+
|
|
186
|
+
- Scaffold condition significantly affects score (Kruskal-Wallis p=0.0007)
|
|
187
|
+
- But only for **small models** (0.8b: p=0.0008, 2b: p=0.005, 4b: p=0.92, 9b: p=0.94)
|
|
188
|
+
- Condition explains **4.2%** of score variation; model size explains **4.7%**
|
|
189
|
+
- Dense scaffolds (QuickThink compressed grammar) **break** small models: 0.8b drops from 0.78 → 0.40. Models need enough capacity to "decompress" the scaffold.
|
|
190
|
+
|
|
191
|
+
## Repo Contents
|
|
192
|
+
|
|
193
|
+
| File | Description |
|
|
194
|
+
|---|---|
|
|
195
|
+
| `lpci.py` | Core prototype: SessionState, LPCISession, state extraction, scaffold refresh, interactive CLI |
|
|
196
|
+
| `lpci_test.py` | A/B continuity test: 20 turns × 2 conditions, probes, scaffold evaluation, delta tracing |
|
|
197
|
+
| `analyze_results.py` | Information-theoretic analysis: MI, KL divergence, transfer entropy, significance tests |
|
|
198
|
+
| `run_experiment.py` | Single-shot scaffold amplification harness (matrix run) |
|
|
199
|
+
| `results/lpci_ab_test.jsonl` | LPCI proof data: 40 rows, full scaffold snapshots, delta traces, probe evaluations |
|
|
200
|
+
| `results/full_run_v1.jsonl` | 619-trial matrix run: 4 models × 5 conditions × 12 tasks × 3 runs |
|
|
201
|
+
| `LOG.md` | Complete project log |
|
|
202
|
+
| `TODO.md` | Future work |
|
|
203
|
+
|
|
204
|
+
## What's Next
|
|
205
|
+
|
|
206
|
+
- **Hard-clamped budget test**: exactly K tokens every turn, real compression every turn
|
|
207
|
+
- **Scale test**: 100+ turns, then 1,000+
|
|
208
|
+
- **Per-token ablation**: which scaffold tokens carry the signal (semantic curvature measurement)
|
|
209
|
+
- **Minimum viable scaffold**: progressive compression curve — at what token count does behavior degrade?
|
|
210
|
+
- **Cross-model scaffold transfer**: does a scaffold built by one model work when injected into another?
|
|
211
|
+
- **Index-based extraction**: eliminate content generation from the extraction pipeline
|
|
212
|
+
|
|
213
|
+
## LPCI
|
|
214
|
+
|
|
215
|
+
Formulated ~summer 2025 as **Linguistically Persistent Cognitive Interface**:
|
|
216
|
+
|
|
217
|
+
- **Linguistically** — the medium is language, not tensors
|
|
218
|
+
- **Persistent** — survives across the stateless inference boundary
|
|
219
|
+
- **Cognitive** — does thinking-work (attention steering, probability reshaping), not just storage
|
|
220
|
+
- **Interface** — sits between sessions and the stateless model
|
|
221
|
+
|
|
222
|
+
## Hermes Labs Ecosystem
|
|
223
|
+
|
|
224
|
+
LangQuant is part of the [Hermes Labs](https://hermes-labs.ai) open-source suite:
|
|
225
|
+
|
|
226
|
+
- [**zer0dex**](https://github.com/roli-lpci/zer0dex) — Token-efficient memory architecture for persistent AI agents
|
|
227
|
+
- [**little-canary**](https://github.com/roli-lpci/little-canary) — Prompt injection detection
|
|
228
|
+
- [**lintlang**](https://github.com/roli-lpci/lintlang) — Static linter for AI agent configs
|
|
229
|
+
- [**forgetted**](https://github.com/roli-lpci/forgetted) — Selective memory governance
|
|
230
|
+
- [**zer0lint**](https://github.com/roli-lpci/zer0lint) — memory extraction diagnostics
|
|
231
|
+
- [**suy-sideguy**](https://github.com/roli-lpci/suy-sideguy) — Autonomous agent watchdog
|
|
232
|
+
- [**quickthink**](https://github.com/roli-lpci/quickthink) — Planning scaffolding for local LLMs
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
If LangQuant is useful to you, please [star the repo](https://github.com/roli-lpci/langquant) — it helps others find it.
|
|
237
|
+
|
|
238
|
+
## Citation
|
|
239
|
+
|
|
240
|
+
If you use this work, please cite:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
@misc{langquant2026,
|
|
244
|
+
author = {Hermes Labs},
|
|
245
|
+
title = {LangQuant: Language State Compression and the Linguistically Persistent Cognitive Interface},
|
|
246
|
+
year = {2026},
|
|
247
|
+
url = {https://github.com/roli-lpci/langquant}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
Apache 2.0
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
*Hermes Labs, 2026*
|
|
258
|
+
|
|
259
|
+
*"Take a bunch of empty words and make them mean something."*
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langquant
|
|
3
|
+
Version: 0.0.8
|
|
4
|
+
Summary: LPCI: Statefulness Through Language for Stateless Models
|
|
5
|
+
Author-email: Rolando Bosch <rbosch@lpci.ai>
|
|
6
|
+
Maintainer-email: Hermes Labs <roli@hermes-labs.ai>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://hermes-labs.ai
|
|
9
|
+
Project-URL: Repository, https://github.com/roli-lpci/langquant
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/github/stars/roli-lpci/langquant" alt="GitHub stars"></a>
|
|
23
|
+
<a href="https://github.com/roli-lpci/langquant/blob/main/LICENSE"><img src="https://img.shields.io/github/license/roli-lpci/langquant" alt="License"></a>
|
|
24
|
+
<a href="https://github.com/roli-lpci/langquant"><img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python"></a>
|
|
25
|
+
<a href="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml"><img src="https://github.com/roli-lpci/langquant/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
# LangQuant
|
|
29
|
+
|
|
30
|
+
## LPCI: Statefulness Through Language for Stateless Models
|
|
31
|
+
|
|
32
|
+
**Validated 2026-03-28 — Hermes Labs**
|
|
33
|
+
|
|
34
|
+
A stateless LLM maintained full conversational coherence across 20 turns with **zero conversation history**. The model never saw any prior messages. A structured language scaffold — refreshed every turn — was the sole state representation.
|
|
35
|
+
|
|
36
|
+
Transfer entropy analysis confirms the scaffold is a **complete Markov state**: knowing what the scaffold contains right now, knowing what it contained last turn adds nothing. The text IS the state.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## The Problem
|
|
41
|
+
|
|
42
|
+
Every LLM conversation works the same way:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Turn 1: [system prompt] + [message 1]
|
|
46
|
+
Turn 2: [system prompt] + [message 1] + [response 1] + [message 2]
|
|
47
|
+
Turn 10: [system prompt] + [all 9 prior exchanges] + [message 10]
|
|
48
|
+
Turn N: [system prompt] + [entire history] + [message N] ← grows without bound
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Context grows linearly. Eventually the model chokes, truncates, or loses coherence. Every provider's solution: make the context window bigger. 128k. 200k. 1M tokens.
|
|
52
|
+
|
|
53
|
+
That's not a solution. That's a bigger bucket for the same leak.
|
|
54
|
+
|
|
55
|
+
## The Thesis
|
|
56
|
+
|
|
57
|
+
The model is stateless. It has no memory. It has no continuity.
|
|
58
|
+
|
|
59
|
+
**The text is the state.**
|
|
60
|
+
|
|
61
|
+
Instead of feeding the model a growing conversation, feed it a **fixed-budget structured scaffold** that encodes the cognitive state of the session — goals, decisions, facts, constraints, vocabulary, open questions — and refreshes every turn.
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Every turn: [scaffold: K tokens, refreshed] + [current message]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The scaffold doesn't grow. It **compresses**. Turn 20 and turn 2,000 look identical from the model's perspective.
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install langquant
|
|
73
|
+
ollama pull qwen3.5:4b # state-extractor model
|
|
74
|
+
ollama pull qwen3.5:9b # main reasoning model
|
|
75
|
+
python lpci.py # launch a 20-turn LPCI session
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The session keeps no message history — each turn the model sees only the
|
|
79
|
+
scaffold (current state) plus the new user message. Contradictions and recall
|
|
80
|
+
probes are reported inline.
|
|
81
|
+
|
|
82
|
+
## What We Proved
|
|
83
|
+
|
|
84
|
+
### Setup
|
|
85
|
+
|
|
86
|
+
- **Main model**: qwen3.5:9b (Ollama, local)
|
|
87
|
+
- **State extractor**: qwen3.5:4b (extracts state changes as JSON deltas after each turn)
|
|
88
|
+
- **A/B test**: 20-turn conversation, two conditions:
|
|
89
|
+
- **Naked**: zero framing, pure state extraction
|
|
90
|
+
- **Compressed**: contrastive IS/NOT markers guiding extraction
|
|
91
|
+
- **Probes** at turns 4, 8, 12, 16, 20: recall tests, contradiction injection, false claim detection
|
|
92
|
+
|
|
93
|
+
### Results
|
|
94
|
+
|
|
95
|
+
The model had amnesia every turn — it only saw the scaffold + current message. Despite this:
|
|
96
|
+
|
|
97
|
+
| Probe | Turn | What happened |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| Early recall | 4 | Model correctly recalled all prior decisions (1.0 recall) |
|
|
100
|
+
| Contradiction | 8 | Model rejected "switch to GPT-4" — scaffold said "state extractor is qwen3.5:4b" |
|
|
101
|
+
| Deep recall | 12 | Model listed decisions from turns 1–11 accurately (0.93 recall, compressed) |
|
|
102
|
+
| Topic pivot | 16 | Model recalled turn 1's topic and connected it to turn 15's discussion |
|
|
103
|
+
| Final exam | 20 | Model listed all decisions in order, caught a false claim |
|
|
104
|
+
|
|
105
|
+
### Compression
|
|
106
|
+
|
|
107
|
+
The scaffold grew slower than the conversation it represented:
|
|
108
|
+
|
|
109
|
+
| Turn | Scaffold (tokens) | Conversation (tokens) | Compression |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| 1 | 343 | 114 | 0.3x (scaffold larger) |
|
|
112
|
+
| 5 | 444 | 456 | 1.0x (break-even) |
|
|
113
|
+
| 10 | 613 | 873 | 1.4x |
|
|
114
|
+
| 15 | 662 | 1,363 | 2.1x |
|
|
115
|
+
| 20 | 789 | 1,945 | **2.5x** |
|
|
116
|
+
|
|
117
|
+
Scaffold grows at ~23 tokens/turn. Conversation grows at ~97 tokens/turn. The compression ratio improves continuously. At turn 100 the scaffold represents ~10,000 tokens of conversation. At turn 1,000, the gap is enormous.
|
|
118
|
+
|
|
119
|
+
### Information-Theoretic Verification
|
|
120
|
+
|
|
121
|
+
Using Shannon entropy, mutual information, KL divergence, and transfer entropy (via pyitlib + scipy):
|
|
122
|
+
|
|
123
|
+
| Metric | Naked | Compressed | Meaning |
|
|
124
|
+
|---|---|---|---|
|
|
125
|
+
| Transfer entropy | 0.608 bits | **0.085 bits** | Compressed scaffold is Markov (self-contained state) |
|
|
126
|
+
| Scaffold entropy | 7.30 | 7.78 | Compressed carries more information per token |
|
|
127
|
+
| KL divergence (t1→t20) | — | 0.20 → 0.48 | Conditions diverge over time |
|
|
128
|
+
| Scaffold-response MI | 0.49 bits | 0.24 bits | Different information coupling |
|
|
129
|
+
|
|
130
|
+
**The transfer entropy finding is the key result.** TE ≈ 0 for the compressed scaffold means each turn's scaffold is a complete state representation. Knowing previous scaffolds adds no information. The scaffold is Markov — which is exactly the LPCI thesis stated in information-theoretic terms.
|
|
131
|
+
|
|
132
|
+
## Architecture
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
┌─────────────┐
|
|
136
|
+
│ User message │
|
|
137
|
+
└──────┬──────┘
|
|
138
|
+
↓
|
|
139
|
+
┌──────────────────────────────────────────────┐
|
|
140
|
+
│ [Scaffold: K tokens] + [Current message] │ ← Only thing the model sees
|
|
141
|
+
└──────────────────────┬───────────────────────┘
|
|
142
|
+
↓
|
|
143
|
+
┌─────────────────┐
|
|
144
|
+
│ Main model │ (qwen3.5:9b)
|
|
145
|
+
│ (stateless) │
|
|
146
|
+
└────────┬────────┘
|
|
147
|
+
↓
|
|
148
|
+
┌─────────────────┐
|
|
149
|
+
│ Response │
|
|
150
|
+
└────────┬────────┘
|
|
151
|
+
↓
|
|
152
|
+
┌──────────────────────────────────────────────┐
|
|
153
|
+
│ State extractor (qwen3.5:4b) │
|
|
154
|
+
│ Input: scaffold + user msg + response │
|
|
155
|
+
│ Output: JSON delta (add/remove decisions, │
|
|
156
|
+
│ facts, constraints, vocabulary...) │
|
|
157
|
+
└──────────────────────┬───────────────────────┘
|
|
158
|
+
↓
|
|
159
|
+
┌─────────────────┐
|
|
160
|
+
│ Apply delta │
|
|
161
|
+
│ to scaffold │
|
|
162
|
+
└────────┬────────┘
|
|
163
|
+
↓
|
|
164
|
+
┌─────────────────┐
|
|
165
|
+
│ Refreshed │ ← Same structure, updated content
|
|
166
|
+
│ scaffold │ Ready for next turn
|
|
167
|
+
└─────────────────┘
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The model is a pure function. The scaffold is the program. The output of one pass feeds the compression of the next.
|
|
171
|
+
|
|
172
|
+
## Scaffold Schema
|
|
173
|
+
|
|
174
|
+
The scaffold is a structured state object with typed fields:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
SessionState:
|
|
178
|
+
role — who the model is
|
|
179
|
+
style — communication constraints
|
|
180
|
+
goal — current objective
|
|
181
|
+
subgoals — active sub-tasks
|
|
182
|
+
decisions — things decided (irreversible)
|
|
183
|
+
facts — established truths
|
|
184
|
+
artifacts — things produced
|
|
185
|
+
constraints — hard boundaries (NOTs)
|
|
186
|
+
open_threads — unresolved questions
|
|
187
|
+
uncertainties — things we're unsure about
|
|
188
|
+
vocabulary — domain terms (term → meaning)
|
|
189
|
+
turn — counter
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Each field maps to a section in the scaffold text. The state extractor outputs JSON deltas (`add_decisions`, `remove_open_threads`, `add_vocabulary`, etc.) that are applied to the state object, which is then re-rendered as the scaffold for the next turn.
|
|
193
|
+
|
|
194
|
+
## Caveats (Honest)
|
|
195
|
+
|
|
196
|
+
1. **The scaffold was growing** (343 → 789 tokens), not truly fixed budget. The budget ceiling only triggered once. A hard-clamped experiment (exactly K tokens every turn) is needed to prove true fixed-budget compression.
|
|
197
|
+
2. **n=1 per condition.** Needs replications.
|
|
198
|
+
3. **20 turns, not 1,000.** Needs scale testing.
|
|
199
|
+
4. **The state extractor corrupts.** It generates paraphrased strings, not verbatim text. Classification drift was observed: same conversation produced 71 facts / 4 decisions (naked) vs 3 facts / 23 decisions (compressed). The extractor needs an index-based selection mechanism (output integer pointers, not generated text) to guarantee fidelity.
|
|
200
|
+
5. **Scaffold framing affects extraction, not just model behavior.** The contrastive markers helped the state extractor classify information, not necessarily the main model's coherence. Both conditions maintained continuity — the difference was in what the scaffold *contained*.
|
|
201
|
+
|
|
202
|
+
## Additional Experiment: Scaffold Amplification (619 trials)
|
|
203
|
+
|
|
204
|
+
Separate from LPCI, we ran a single-shot experiment testing 5 scaffold conditions across 4 model sizes (qwen3.5: 0.8b, 2b, 4b, 9b) on 12 tasks:
|
|
205
|
+
|
|
206
|
+
- Scaffold condition significantly affects score (Kruskal-Wallis p=0.0007)
|
|
207
|
+
- But only for **small models** (0.8b: p=0.0008, 2b: p=0.005, 4b: p=0.92, 9b: p=0.94)
|
|
208
|
+
- Condition explains **4.2%** of score variation; model size explains **4.7%**
|
|
209
|
+
- Dense scaffolds (QuickThink compressed grammar) **break** small models: 0.8b drops from 0.78 → 0.40. Models need enough capacity to "decompress" the scaffold.
|
|
210
|
+
|
|
211
|
+
## Repo Contents
|
|
212
|
+
|
|
213
|
+
| File | Description |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `lpci.py` | Core prototype: SessionState, LPCISession, state extraction, scaffold refresh, interactive CLI |
|
|
216
|
+
| `lpci_test.py` | A/B continuity test: 20 turns × 2 conditions, probes, scaffold evaluation, delta tracing |
|
|
217
|
+
| `analyze_results.py` | Information-theoretic analysis: MI, KL divergence, transfer entropy, significance tests |
|
|
218
|
+
| `run_experiment.py` | Single-shot scaffold amplification harness (matrix run) |
|
|
219
|
+
| `results/lpci_ab_test.jsonl` | LPCI proof data: 40 rows, full scaffold snapshots, delta traces, probe evaluations |
|
|
220
|
+
| `results/full_run_v1.jsonl` | 619-trial matrix run: 4 models × 5 conditions × 12 tasks × 3 runs |
|
|
221
|
+
| `LOG.md` | Complete project log |
|
|
222
|
+
| `TODO.md` | Future work |
|
|
223
|
+
|
|
224
|
+
## What's Next
|
|
225
|
+
|
|
226
|
+
- **Hard-clamped budget test**: exactly K tokens every turn, real compression every turn
|
|
227
|
+
- **Scale test**: 100+ turns, then 1,000+
|
|
228
|
+
- **Per-token ablation**: which scaffold tokens carry the signal (semantic curvature measurement)
|
|
229
|
+
- **Minimum viable scaffold**: progressive compression curve — at what token count does behavior degrade?
|
|
230
|
+
- **Cross-model scaffold transfer**: does a scaffold built by one model work when injected into another?
|
|
231
|
+
- **Index-based extraction**: eliminate content generation from the extraction pipeline
|
|
232
|
+
|
|
233
|
+
## LPCI
|
|
234
|
+
|
|
235
|
+
Formulated ~summer 2025 as **Linguistically Persistent Cognitive Interface**:
|
|
236
|
+
|
|
237
|
+
- **Linguistically** — the medium is language, not tensors
|
|
238
|
+
- **Persistent** — survives across the stateless inference boundary
|
|
239
|
+
- **Cognitive** — does thinking-work (attention steering, probability reshaping), not just storage
|
|
240
|
+
- **Interface** — sits between sessions and the stateless model
|
|
241
|
+
|
|
242
|
+
## Hermes Labs Ecosystem
|
|
243
|
+
|
|
244
|
+
LangQuant is part of the [Hermes Labs](https://hermes-labs.ai) open-source suite:
|
|
245
|
+
|
|
246
|
+
- [**zer0dex**](https://github.com/roli-lpci/zer0dex) — Token-efficient memory architecture for persistent AI agents
|
|
247
|
+
- [**little-canary**](https://github.com/roli-lpci/little-canary) — Prompt injection detection
|
|
248
|
+
- [**lintlang**](https://github.com/roli-lpci/lintlang) — Static linter for AI agent configs
|
|
249
|
+
- [**forgetted**](https://github.com/roli-lpci/forgetted) — Selective memory governance
|
|
250
|
+
- [**zer0lint**](https://github.com/roli-lpci/zer0lint) — memory extraction diagnostics
|
|
251
|
+
- [**suy-sideguy**](https://github.com/roli-lpci/suy-sideguy) — Autonomous agent watchdog
|
|
252
|
+
- [**quickthink**](https://github.com/roli-lpci/quickthink) — Planning scaffolding for local LLMs
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
If LangQuant is useful to you, please [star the repo](https://github.com/roli-lpci/langquant) — it helps others find it.
|
|
257
|
+
|
|
258
|
+
## Citation
|
|
259
|
+
|
|
260
|
+
If you use this work, please cite:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
@misc{langquant2026,
|
|
264
|
+
author = {Hermes Labs},
|
|
265
|
+
title = {LangQuant: Language State Compression and the Linguistically Persistent Cognitive Interface},
|
|
266
|
+
year = {2026},
|
|
267
|
+
url = {https://github.com/roli-lpci/langquant}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
Apache 2.0
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
*Hermes Labs, 2026*
|
|
278
|
+
|
|
279
|
+
*"Take a bunch of empty words and make them mean something."*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
results
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langquant"
|
|
7
|
+
version = "0.0.8"
|
|
8
|
+
description = "LPCI: Statefulness Through Language for Stateless Models"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Rolando Bosch", email = "rbosch@lpci.ai" },
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{ name = "Hermes Labs", email = "roli@hermes-labs.ai" },
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 3 - Alpha",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://hermes-labs.ai"
|
|
29
|
+
Repository = "https://github.com/roli-lpci/langquant"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Graceful degradation: when Ollama is unreachable, state extraction returns
|
|
2
|
+
an empty delta instead of crashing — letting the LPCI loop continue with
|
|
3
|
+
existing state. This is the contract that lets a long-running experiment survive
|
|
4
|
+
a transient ollama hiccup.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
import lpci
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_state_extraction_returns_empty_when_ollama_down():
|
|
14
|
+
state = lpci.SessionState()
|
|
15
|
+
|
|
16
|
+
with patch("lpci.urllib.request.urlopen", side_effect=ConnectionError("ollama down")):
|
|
17
|
+
delta = lpci.extract_state_delta(
|
|
18
|
+
state,
|
|
19
|
+
user_message="hello",
|
|
20
|
+
assistant_response="hi",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
assert delta == {}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_apply_delta_with_empty_delta_is_noop():
|
|
27
|
+
state = lpci.SessionState()
|
|
28
|
+
state.goal = "original-goal"
|
|
29
|
+
lpci.apply_delta(state, {})
|
|
30
|
+
assert state.goal == "original-goal"
|