prismlang 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.
- prismlang-0.1.0/.gitignore +51 -0
- prismlang-0.1.0/LICENSE +94 -0
- prismlang-0.1.0/PKG-INFO +481 -0
- prismlang-0.1.0/README.md +333 -0
- prismlang-0.1.0/prismlang/__init__.py +88 -0
- prismlang-0.1.0/prismlang/checkpointer.py +547 -0
- prismlang-0.1.0/prismlang/config.py +17 -0
- prismlang-0.1.0/prismlang/encoder.py +129 -0
- prismlang-0.1.0/prismlang/envelope.py +18 -0
- prismlang-0.1.0/prismlang/exceptions.py +158 -0
- prismlang-0.1.0/prismlang/middleware.py +102 -0
- prismlang-0.1.0/prismlang/projector.py +136 -0
- prismlang-0.1.0/prismlang/state.py +29 -0
- prismlang-0.1.0/prismlang/taxonomy.py +100 -0
- prismlang-0.1.0/prismlang/translator.py +84 -0
- prismlang-0.1.0/pyproject.toml +100 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
.Python
|
|
7
|
+
*.egg
|
|
8
|
+
*.egg-info/
|
|
9
|
+
dist/
|
|
10
|
+
build/
|
|
11
|
+
.eggs/
|
|
12
|
+
*.whl
|
|
13
|
+
|
|
14
|
+
# Virtual environments
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
env/
|
|
18
|
+
.env
|
|
19
|
+
|
|
20
|
+
# Model cache (large ONNX files โ downloaded on first use)
|
|
21
|
+
.prismlang/
|
|
22
|
+
|
|
23
|
+
# Demo checkpoints (generated at runtime)
|
|
24
|
+
.prismlang_demo/
|
|
25
|
+
.prismlang_checkpoints/
|
|
26
|
+
|
|
27
|
+
# Test / coverage
|
|
28
|
+
.coverage
|
|
29
|
+
.coverage.*
|
|
30
|
+
htmlcov/
|
|
31
|
+
.pytest_cache/
|
|
32
|
+
.mypy_cache/
|
|
33
|
+
.ruff_cache/
|
|
34
|
+
|
|
35
|
+
# MkDocs
|
|
36
|
+
site/
|
|
37
|
+
|
|
38
|
+
# IDE
|
|
39
|
+
.vscode/
|
|
40
|
+
.idea/
|
|
41
|
+
*.swp
|
|
42
|
+
*.swo
|
|
43
|
+
|
|
44
|
+
# OS
|
|
45
|
+
.DS_Store
|
|
46
|
+
Thumbs.db
|
|
47
|
+
|
|
48
|
+
# Secrets โ never commit
|
|
49
|
+
.env
|
|
50
|
+
*.env
|
|
51
|
+
secrets.json
|
prismlang-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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.
|
|
18
|
+
|
|
19
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
20
|
+
exercising permissions granted by this License.
|
|
21
|
+
|
|
22
|
+
"Source" form shall mean the preferred form for making modifications.
|
|
23
|
+
|
|
24
|
+
"Object" form shall mean any form resulting from mechanical
|
|
25
|
+
transformation or translation of a Source form.
|
|
26
|
+
|
|
27
|
+
"Work" shall mean the work of authorship made available under the License.
|
|
28
|
+
|
|
29
|
+
"Derivative Works" shall mean any work that is based on the Work.
|
|
30
|
+
|
|
31
|
+
"Contribution" shall mean any work of authorship submitted to the Licensor.
|
|
32
|
+
|
|
33
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of whom
|
|
34
|
+
a Contribution has been received by the Licensor.
|
|
35
|
+
|
|
36
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
37
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
38
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
39
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
40
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
41
|
+
Work and such Derivative Works in Source or Object form.
|
|
42
|
+
|
|
43
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
44
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
45
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
46
|
+
patent license to make, use, sell, offer for sale, import, and
|
|
47
|
+
otherwise transfer the Work.
|
|
48
|
+
|
|
49
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
50
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
51
|
+
modifications, provided that You meet the following conditions:
|
|
52
|
+
|
|
53
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
54
|
+
a copy of this License; and
|
|
55
|
+
|
|
56
|
+
(b) You must cause any modified files to carry prominent notices
|
|
57
|
+
stating that You changed the files; and
|
|
58
|
+
|
|
59
|
+
(c) You must retain, in the Source form of any Derivative Works,
|
|
60
|
+
all copyright, patent, trademark, and attribution notices; and
|
|
61
|
+
|
|
62
|
+
(d) If the Work includes a "NOTICE" text file, you must include a
|
|
63
|
+
readable copy of the attribution notices contained within.
|
|
64
|
+
|
|
65
|
+
5. Submission of Contributions. Any Contribution intentionally submitted
|
|
66
|
+
for inclusion in the Work shall be under the terms of this License.
|
|
67
|
+
|
|
68
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
69
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
70
|
+
|
|
71
|
+
7. Disclaimer of Warranty. The Work is provided "AS IS", WITHOUT WARRANTIES
|
|
72
|
+
OR CONDITIONS OF ANY KIND, either express or implied.
|
|
73
|
+
|
|
74
|
+
8. Limitation of Liability. In no event shall any Contributor be liable
|
|
75
|
+
for any damages arising from use of the Work.
|
|
76
|
+
|
|
77
|
+
9. Accepting Warranty or Additional Liability. You may offer additional
|
|
78
|
+
warranty or liability obligations consistent with this License.
|
|
79
|
+
|
|
80
|
+
END OF TERMS AND CONDITIONS
|
|
81
|
+
|
|
82
|
+
Copyright 2026 Insight IT Solutions LLC
|
|
83
|
+
|
|
84
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
85
|
+
you may not use this file except in compliance with the License.
|
|
86
|
+
You may obtain a copy of the License at
|
|
87
|
+
|
|
88
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
89
|
+
|
|
90
|
+
Unless required by applicable law or agreed to in writing, software
|
|
91
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
92
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
93
|
+
See the License for the specific language governing permissions and
|
|
94
|
+
limitations under the License.
|
prismlang-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prismlang
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic vector language protocol for multi-agent AI orchestration
|
|
5
|
+
Project-URL: Homepage, https://www.insightits.com/prismlang
|
|
6
|
+
Project-URL: Documentation, https://insightits.github.io/prismlang
|
|
7
|
+
Project-URL: Repository, https://github.com/insightits/prismlang
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/insightits/prismlang/issues
|
|
9
|
+
Project-URL: Paper, https://www.insightits.com/prismlang/paper
|
|
10
|
+
Author-email: Amin Parva <prismrag@insightits.com>
|
|
11
|
+
Maintainer-email: Amin Parva <prismrag@insightits.com>
|
|
12
|
+
License: Apache License
|
|
13
|
+
Version 2.0, January 2004
|
|
14
|
+
http://www.apache.org/licenses/
|
|
15
|
+
|
|
16
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
17
|
+
|
|
18
|
+
1. Definitions.
|
|
19
|
+
|
|
20
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
21
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
22
|
+
|
|
23
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
24
|
+
the copyright owner that is granting the License.
|
|
25
|
+
|
|
26
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
27
|
+
other entities that control, are controlled by, or are under common
|
|
28
|
+
control with that entity.
|
|
29
|
+
|
|
30
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
31
|
+
exercising permissions granted by this License.
|
|
32
|
+
|
|
33
|
+
"Source" form shall mean the preferred form for making modifications.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship made available under the License.
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work that is based on the Work.
|
|
41
|
+
|
|
42
|
+
"Contribution" shall mean any work of authorship submitted to the Licensor.
|
|
43
|
+
|
|
44
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of whom
|
|
45
|
+
a Contribution has been received by the Licensor.
|
|
46
|
+
|
|
47
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
48
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
49
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
50
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
51
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
52
|
+
Work and such Derivative Works in Source or Object form.
|
|
53
|
+
|
|
54
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
patent license to make, use, sell, offer for sale, import, and
|
|
58
|
+
otherwise transfer the Work.
|
|
59
|
+
|
|
60
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
61
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
62
|
+
modifications, provided that You meet the following conditions:
|
|
63
|
+
|
|
64
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
65
|
+
a copy of this License; and
|
|
66
|
+
|
|
67
|
+
(b) You must cause any modified files to carry prominent notices
|
|
68
|
+
stating that You changed the files; and
|
|
69
|
+
|
|
70
|
+
(c) You must retain, in the Source form of any Derivative Works,
|
|
71
|
+
all copyright, patent, trademark, and attribution notices; and
|
|
72
|
+
|
|
73
|
+
(d) If the Work includes a "NOTICE" text file, you must include a
|
|
74
|
+
readable copy of the attribution notices contained within.
|
|
75
|
+
|
|
76
|
+
5. Submission of Contributions. Any Contribution intentionally submitted
|
|
77
|
+
for inclusion in the Work shall be under the terms of this License.
|
|
78
|
+
|
|
79
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
80
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
81
|
+
|
|
82
|
+
7. Disclaimer of Warranty. The Work is provided "AS IS", WITHOUT WARRANTIES
|
|
83
|
+
OR CONDITIONS OF ANY KIND, either express or implied.
|
|
84
|
+
|
|
85
|
+
8. Limitation of Liability. In no event shall any Contributor be liable
|
|
86
|
+
for any damages arising from use of the Work.
|
|
87
|
+
|
|
88
|
+
9. Accepting Warranty or Additional Liability. You may offer additional
|
|
89
|
+
warranty or liability obligations consistent with this License.
|
|
90
|
+
|
|
91
|
+
END OF TERMS AND CONDITIONS
|
|
92
|
+
|
|
93
|
+
Copyright 2026 Insight IT Solutions LLC
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
96
|
+
you may not use this file except in compliance with the License.
|
|
97
|
+
You may obtain a copy of the License at
|
|
98
|
+
|
|
99
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
100
|
+
|
|
101
|
+
Unless required by applicable law or agreed to in writing, software
|
|
102
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
103
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
104
|
+
See the License for the specific language governing permissions and
|
|
105
|
+
limitations under the License.
|
|
106
|
+
License-File: LICENSE
|
|
107
|
+
Keywords: ai,deterministic,langgraph,llm,multi-agent,onnx,protocol,state-compression,tenant-isolation,vector
|
|
108
|
+
Classifier: Development Status :: 3 - Alpha
|
|
109
|
+
Classifier: Intended Audience :: Developers
|
|
110
|
+
Classifier: Intended Audience :: Science/Research
|
|
111
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
112
|
+
Classifier: Programming Language :: Python :: 3
|
|
113
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
114
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
115
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
116
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
117
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
118
|
+
Requires-Python: >=3.10
|
|
119
|
+
Requires-Dist: huggingface-hub>=0.20.0
|
|
120
|
+
Requires-Dist: langgraph>=0.2.0
|
|
121
|
+
Requires-Dist: numpy>=1.26.0
|
|
122
|
+
Requires-Dist: onnxruntime>=1.17.0
|
|
123
|
+
Requires-Dist: tokenizers>=0.15.0
|
|
124
|
+
Requires-Dist: typing-extensions>=4.9.0
|
|
125
|
+
Provides-Extra: async-files
|
|
126
|
+
Requires-Dist: aiofiles>=23.0.0; extra == 'async-files'
|
|
127
|
+
Provides-Extra: async-postgres
|
|
128
|
+
Requires-Dist: asyncpg>=0.29.0; extra == 'async-postgres'
|
|
129
|
+
Provides-Extra: dev
|
|
130
|
+
Requires-Dist: aiofiles>=23.0.0; extra == 'dev'
|
|
131
|
+
Requires-Dist: asyncpg>=0.29.0; extra == 'dev'
|
|
132
|
+
Requires-Dist: mkdocs-material>=9.0.0; extra == 'dev'
|
|
133
|
+
Requires-Dist: mkdocs>=1.5.0; extra == 'dev'
|
|
134
|
+
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'dev'
|
|
135
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
|
136
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == 'dev'
|
|
137
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
138
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
139
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
140
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
141
|
+
Provides-Extra: docs
|
|
142
|
+
Requires-Dist: mkdocs-material>=9.0.0; extra == 'docs'
|
|
143
|
+
Requires-Dist: mkdocs>=1.5.0; extra == 'docs'
|
|
144
|
+
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'docs'
|
|
145
|
+
Provides-Extra: postgres
|
|
146
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == 'postgres'
|
|
147
|
+
Description-Content-Type: text/markdown
|
|
148
|
+
|
|
149
|
+
<div align="center">
|
|
150
|
+
|
|
151
|
+
<img src="https://img.shields.io/badge/PrismLang-v0.1.0-6366f1?style=for-the-badge&labelColor=0f0f23" alt="PrismLang"/>
|
|
152
|
+
|
|
153
|
+
# PrismLang
|
|
154
|
+
|
|
155
|
+
### Deterministic Vector Language Protocol for LangGraph Multi-Agent AI
|
|
156
|
+
|
|
157
|
+
*Stop paying the token tax on every agent hop. Start routing with math.*
|
|
158
|
+
|
|
159
|
+
[](https://pypi.org/project/prismlang/)
|
|
160
|
+
[](https://python.org)
|
|
161
|
+
[](LICENSE)
|
|
162
|
+
[](https://github.com/langchain-ai/langgraph)
|
|
163
|
+
[](tests/)
|
|
164
|
+
[](docs/SECURITY.md)
|
|
165
|
+
|
|
166
|
+
<br/>
|
|
167
|
+
|
|
168
|
+
**[๐ Docs](https://www.insightits.com/prismlang)** ยท **[๐ Quickstart](#quick-start)** ยท **[๐ Benchmarks](#benchmark-results)** ยท **[๐ข Insight IT Solutions](https://www.insightits.com)**
|
|
169
|
+
|
|
170
|
+
<br/>
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
pip install prismlang
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## The Problem
|
|
181
|
+
|
|
182
|
+
Every node in a LangGraph multi-agent pipeline reads **the entire message history** as prompt tokens. By turn 3 of a standard graph, every agent is paying for every prior agent's output โ every single call.
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Turn 1 โ 800 B 1 agent reading history
|
|
186
|
+
Turn 2 โ 1,600 B 2 agents reading history
|
|
187
|
+
Turn 3 โ 2,400 B 3 agents reading history โ you're paying 3ร for the same data
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
On top of that:
|
|
191
|
+
- **No audit trail** โ you can't trace why an agent classified something the way it did
|
|
192
|
+
- **No tenant isolation** โ in multi-tenant SaaS, one misconfigured agent can bleed context across org boundaries
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## The Solution
|
|
197
|
+
|
|
198
|
+
PrismLang replaces growing text payloads with **64-number deterministic vectors** โ one per agent turn. A single decorator on your existing nodes. No agent refactoring. No LLM retraining.
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
[Your Agent] โ "Credit risk elevated in EM bonds." (text, 400+ tokens)
|
|
202
|
+
โ @prism_node
|
|
203
|
+
โ PrismEnvelope { vector[64], slug="risk", rule_chain } (~414 bytes)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The math guarantees that **the same input always produces the same vector**, that **different tenants produce incompatible vectors**, and that **every routing decision is traceable back to a taxonomy rule**.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## How It Works
|
|
211
|
+
|
|
212
|
+
PrismLang applies two equations on every agent output:
|
|
213
|
+
|
|
214
|
+
**Step 1 โ Spherical Blend** *(pulls the embedding toward its category direction)*
|
|
215
|
+
```
|
|
216
|
+
v' = normalize( (1 โ ฮฑ) ยท v + ฮฑ ยท โvโ ยท eแตข )
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Step 2 โ JL Reduction** *(compresses to k=64 dims, isolated per tenant)*
|
|
220
|
+
```
|
|
221
|
+
p = normalize( P ยท v' )
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Where `P` is a `(64 ร 384)` Gaussian matrix seeded from `SHA-256(tenant_id)`. A vector stolen from Tenant A is **geometrically meaningless** to any model operating under Tenant B's projection.
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
228
|
+
โ Your LangGraph Graph โ
|
|
229
|
+
โ โ
|
|
230
|
+
[researcher] โโโ [summarizer] โโโ [reviewer] โโโ [translator] โ
|
|
231
|
+
โ โ โ โ โ
|
|
232
|
+
@prism_node @prism_node @prism_node (boundary) โ
|
|
233
|
+
โ โ โ โ โ
|
|
234
|
+
PrismEnvelope PrismEnvelope PrismEnvelope Human text โ
|
|
235
|
+
{64-d vector} {64-d vector} {64-d vector} โ
|
|
236
|
+
{rule_chain} {rule_chain} {rule_chain} โ
|
|
237
|
+
โ โ
|
|
238
|
+
โ prism_sequence โโโโโโโโโ append-only โ
|
|
239
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Quick Start
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from prismlang import (
|
|
248
|
+
Category, TaxonomyConfig, PrismProjector,
|
|
249
|
+
PrismState, prism_node, BoundaryTranslator,
|
|
250
|
+
JsonFileCheckpointer,
|
|
251
|
+
)
|
|
252
|
+
from langgraph.graph import StateGraph, END
|
|
253
|
+
|
|
254
|
+
# 1. Define your domain taxonomy
|
|
255
|
+
taxonomy = TaxonomyConfig(categories=[
|
|
256
|
+
Category("risk", "Market Risk", ["risk", "exposure", "volatility"]),
|
|
257
|
+
Category("market", "Market Data", ["price", "equity", "bond"]),
|
|
258
|
+
Category("compliance", "Compliance", ["regulation", "audit", "kyc"]),
|
|
259
|
+
])
|
|
260
|
+
|
|
261
|
+
# 2. One projector per tenant โ cryptographically isolated
|
|
262
|
+
projector = PrismProjector(taxonomy, tenant_id="acme-finance-prod", k=64)
|
|
263
|
+
|
|
264
|
+
# 3. Decorate your existing nodes โ zero changes to agent logic
|
|
265
|
+
@prism_node(agent_id="analyst", projector=projector)
|
|
266
|
+
def analyst(state: PrismState) -> dict:
|
|
267
|
+
return {"raw_output": "Credit risk exposure elevated in EM bonds."}
|
|
268
|
+
|
|
269
|
+
@prism_node(agent_id="reviewer", projector=projector)
|
|
270
|
+
def reviewer(state: PrismState) -> dict:
|
|
271
|
+
prev = state["prism_sequence"][-1]["category_slug"]
|
|
272
|
+
return {"raw_output": f"Reviewing {prev} findings for compliance sign-off."}
|
|
273
|
+
|
|
274
|
+
# 4. Build and run โ exactly like any LangGraph graph
|
|
275
|
+
translator = BoundaryTranslator()
|
|
276
|
+
graph = StateGraph(PrismState)
|
|
277
|
+
graph.add_node("analyst", analyst)
|
|
278
|
+
graph.add_node("reviewer", reviewer)
|
|
279
|
+
graph.add_node("translator", translator.as_langgraph_node())
|
|
280
|
+
graph.set_entry_point("analyst")
|
|
281
|
+
graph.add_edge("analyst", "reviewer")
|
|
282
|
+
graph.add_edge("reviewer", "translator")
|
|
283
|
+
graph.add_edge("translator", END)
|
|
284
|
+
|
|
285
|
+
app = graph.compile(checkpointer=JsonFileCheckpointer())
|
|
286
|
+
result = app.invoke({
|
|
287
|
+
"prism_sequence": [], "raw_output": "", "tenant_id": "acme-finance-prod"
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
# Inspect the audit envelope
|
|
291
|
+
envelope = result["prism_sequence"][0]
|
|
292
|
+
print(envelope["category_slug"]) # "risk"
|
|
293
|
+
print(len(envelope["vector"])) # 64
|
|
294
|
+
print(envelope["rule_chain"])
|
|
295
|
+
# ['text -> encoder(all-MiniLM-L6-v2, d=384)',
|
|
296
|
+
# "category_inference -> slug='risk'",
|
|
297
|
+
# 'spherical_blend(alpha=0.300) -> v_prime',
|
|
298
|
+
# "JL_reduction(seed=sha256('acme-finance-prod'), k=64) -> p"]
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Benchmark Results
|
|
304
|
+
|
|
305
|
+
> Measured against standard LangGraph text-state across three enterprise domains.
|
|
306
|
+
> Full methodology in [`docs/BENCHMARK.md`](docs/BENCHMARK.md). Results stored in PostgreSQL.
|
|
307
|
+
|
|
308
|
+
<table>
|
|
309
|
+
<tr>
|
|
310
|
+
<th>Domain</th>
|
|
311
|
+
<th>Metric</th>
|
|
312
|
+
<th>Standard LangGraph</th>
|
|
313
|
+
<th>PrismLang</th>
|
|
314
|
+
<th>Change</th>
|
|
315
|
+
</tr>
|
|
316
|
+
<tr>
|
|
317
|
+
<td rowspan="2"><b>๐ฅ Healthcare</b><br/><sub>ICU triage pipeline</sub></td>
|
|
318
|
+
<td>Prompt tokens (3 turns)</td>
|
|
319
|
+
<td>391</td>
|
|
320
|
+
<td>148</td>
|
|
321
|
+
<td><b>โ62.1%</b></td>
|
|
322
|
+
</tr>
|
|
323
|
+
<tr>
|
|
324
|
+
<td>State size (turn 3)</td>
|
|
325
|
+
<td>1,928 B</td>
|
|
326
|
+
<td>960 B</td>
|
|
327
|
+
<td><b>โ50.2%</b></td>
|
|
328
|
+
</tr>
|
|
329
|
+
<tr>
|
|
330
|
+
<td rowspan="2"><b>๐น Finance</b><br/><sub>Risk / portfolio pipeline</sub></td>
|
|
331
|
+
<td>Prompt tokens (3 turns)</td>
|
|
332
|
+
<td>407</td>
|
|
333
|
+
<td>175</td>
|
|
334
|
+
<td><b>โ57.0%</b></td>
|
|
335
|
+
</tr>
|
|
336
|
+
<tr>
|
|
337
|
+
<td>State size (turn 3)</td>
|
|
338
|
+
<td>1,760 B</td>
|
|
339
|
+
<td>960 B</td>
|
|
340
|
+
<td><b>โ45.5%</b></td>
|
|
341
|
+
</tr>
|
|
342
|
+
<tr>
|
|
343
|
+
<td rowspan="2"><b>๐ Trade Market</b><br/><sub>Signal / execution pipeline</sub></td>
|
|
344
|
+
<td>Prompt tokens (3 turns)</td>
|
|
345
|
+
<td>435</td>
|
|
346
|
+
<td>180</td>
|
|
347
|
+
<td><b>โ58.6%</b></td>
|
|
348
|
+
</tr>
|
|
349
|
+
<tr>
|
|
350
|
+
<td>State size (turn 3)</td>
|
|
351
|
+
<td>1,867 B</td>
|
|
352
|
+
<td>960 B</td>
|
|
353
|
+
<td><b>โ48.6%</b></td>
|
|
354
|
+
</tr>
|
|
355
|
+
</table>
|
|
356
|
+
|
|
357
|
+
> **LLM inference latency: unchanged.** PrismLang reduces state transport, not compute.
|
|
358
|
+
> Encoding overhead per turn: ~31โ35 ms CPU-only (no GPU required).
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## Key Properties
|
|
363
|
+
|
|
364
|
+
| Property | Detail |
|
|
365
|
+
|---|---|
|
|
366
|
+
| **Zero agent refactoring** | Agents return `{"raw_output": "..."}` โ nothing else changes |
|
|
367
|
+
| **Deterministic** | Same text + same tenant = identical vector, always |
|
|
368
|
+
| **Full audit trail** | Every envelope carries a `rule_chain` tracing the full decision path |
|
|
369
|
+
| **Tenant isolation** | `SHA-256(tenant_id)` seeds the JL matrix โ cross-tenant vectors are incompatible |
|
|
370
|
+
| **No GPU** | ONNX Runtime CPU inference โ runs on any standard server |
|
|
371
|
+
| **No external API** | Encoder is fully local โ no network call per token |
|
|
372
|
+
| **Model-agnostic** | Works with GPT-4, Claude, Gemini, Llama, or any LLM |
|
|
373
|
+
| **Async native** | `@async_prism_node` for async LangGraph nodes |
|
|
374
|
+
| **Two checkpointers** | `JsonFileCheckpointer` (zero deps) + `PostgresCheckpointer` |
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## Installation Options
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
# Core (local JSON checkpointing)
|
|
382
|
+
pip install prismlang
|
|
383
|
+
|
|
384
|
+
# PostgreSQL checkpointing
|
|
385
|
+
pip install "prismlang[postgres]"
|
|
386
|
+
|
|
387
|
+
# Async support (asyncpg + aiofiles)
|
|
388
|
+
pip install "prismlang[async-postgres,async-files]"
|
|
389
|
+
|
|
390
|
+
# Full development environment
|
|
391
|
+
pip install "prismlang[dev]"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## Run the Benchmarks
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
git clone https://github.com/insightitsGit/prismlang
|
|
400
|
+
cd prismlang
|
|
401
|
+
pip install -e ".[dev]"
|
|
402
|
+
|
|
403
|
+
# Runs all 3 domain benchmarks and prints comparison table
|
|
404
|
+
python -m benchmarks.run_all
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Requires a running PostgreSQL instance. Set `DATABASE_URL` or use the default:
|
|
408
|
+
`postgresql://insight_admin:...@localhost/prismLangDB`
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## Project Structure
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
prismlang/
|
|
416
|
+
โโโ prismlang/
|
|
417
|
+
โ โโโ encoder.py # ONNX all-MiniLM-L6-v2 โ 384-d unit vector
|
|
418
|
+
โ โโโ taxonomy.py # TaxonomyConfig + Category direction vectors (eแตข)
|
|
419
|
+
โ โโโ projector.py # PrismProjector: spherical blend + JL reduction
|
|
420
|
+
โ โโโ middleware.py # @prism_node + @async_prism_node decorators
|
|
421
|
+
โ โโโ checkpointer.py # JsonFile + Postgres + Async variants
|
|
422
|
+
โ โโโ exceptions.py # Typed exception hierarchy (17 classes)
|
|
423
|
+
โ โโโ envelope.py # PrismEnvelope TypedDict
|
|
424
|
+
โ โโโ state.py # PrismState (LangGraph append-only channel)
|
|
425
|
+
โ โโโ translator.py # BoundaryTranslator (structural reconstruction)
|
|
426
|
+
โโโ benchmarks/
|
|
427
|
+
โ โโโ domains/ # Healthcare ยท Finance ยท Trade Market
|
|
428
|
+
โโโ demo/
|
|
429
|
+
โ โโโ graph.py # Runnable 3-node LangGraph demo
|
|
430
|
+
โโโ tests/ # 34 tests ยท 0 failures
|
|
431
|
+
โโโ docs/
|
|
432
|
+
โโโ ARCHITECTURE.md
|
|
433
|
+
โโโ BENCHMARK.md
|
|
434
|
+
โโโ SECURITY.md
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
## Security
|
|
440
|
+
|
|
441
|
+
PrismLang's tenant isolation is a **geometric property** guaranteed by the Johnson-Lindenstrauss lemma โ not an access-control system. For production deployments, see [`docs/SECURITY.md`](docs/SECURITY.md) which covers:
|
|
442
|
+
|
|
443
|
+
- What the JL matrix does and does not protect
|
|
444
|
+
- Overlay encryption for PII in `raw_output`
|
|
445
|
+
- Dependency security notes (onnxruntime, psycopg2, asyncpg)
|
|
446
|
+
- NumPy PRNG stability across version upgrades
|
|
447
|
+
|
|
448
|
+
To report a vulnerability: **prismrag@insightits.com** โ do not open a public GitHub issue.
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Citation
|
|
453
|
+
|
|
454
|
+
```bibtex
|
|
455
|
+
@techreport{parva2026prismlang,
|
|
456
|
+
title = {PrismLang: A Deterministic Vector Language Protocol
|
|
457
|
+
for Auditable Multi-Agent AI Orchestration},
|
|
458
|
+
author = {Parva, Amin},
|
|
459
|
+
year = {2026},
|
|
460
|
+
institution = {Insight IT Solutions LLC},
|
|
461
|
+
url = {https://www.insightits.com/prismlang}
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## License
|
|
468
|
+
|
|
469
|
+
[Apache 2.0](LICENSE) โ free for commercial and personal use.
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
<div align="center">
|
|
474
|
+
|
|
475
|
+
**Built by [Insight IT Solutions LLC](https://www.insightits.com)**
|
|
476
|
+
|
|
477
|
+
*Enterprise AI systems ยท LangGraph architecture ยท Vector search ยท Production deployment*
|
|
478
|
+
|
|
479
|
+
[๐ Website](https://www.insightits.com) ยท [๐ง Contact](mailto:prismrag@insightits.com) ยท [๐ Security](mailto:prismrag@insightits.com)
|
|
480
|
+
|
|
481
|
+
</div>
|