system1 0.1.1__py3-none-any.whl
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.
- system1/__init__.py +382 -0
- system1/cache.py +819 -0
- system1/calibration.py +699 -0
- system1/cli.py +620 -0
- system1/compat/__init__.py +57 -0
- system1/compat/typesafe.py +2823 -0
- system1/compiler.py +1234 -0
- system1/core/__init__.py +86 -0
- system1/core/embeddings.py +564 -0
- system1/core/model.py +868 -0
- system1/core/neural.py +261 -0
- system1/core/schema.py +587 -0
- system1/core/telemetry.py +197 -0
- system1/embeddings.py +16 -0
- system1/engine.py +1365 -0
- system1/grpc_server.py +756 -0
- system1/guard.py +1128 -0
- system1/integrations/__init__.py +58 -0
- system1/integrations/fastapi.py +234 -0
- system1/integrations/langchain.py +573 -0
- system1/integrations/mcp.py +750 -0
- system1/integrations/observability.py +247 -0
- system1/integrations/otel.py +117 -0
- system1/ledger.py +636 -0
- system1/model.py +23 -0
- system1/neural.py +17 -0
- system1/proto/__init__.py +15 -0
- system1/proto/reflex.proto +171 -0
- system1/proto/reflex_pb2.py +90 -0
- system1/proto/reflex_pb2_grpc.py +239 -0
- system1/receipt.py +1029 -0
- system1/schema.py +22 -0
- system1/telemetry.py +5 -0
- system1-0.1.1.dist-info/METADATA +546 -0
- system1-0.1.1.dist-info/RECORD +39 -0
- system1-0.1.1.dist-info/WHEEL +5 -0
- system1-0.1.1.dist-info/entry_points.txt +2 -0
- system1-0.1.1.dist-info/licenses/LICENSE +176 -0
- system1-0.1.1.dist-info/top_level.txt +1 -0
system1/__init__.py
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"""System 1: Machine-Native Decision Runtime (Reflex).
|
|
2
|
+
|
|
3
|
+
High-performance, non-autoregressive decision engine implementing Daniel Kahneman's System 1
|
|
4
|
+
fast cognitive layer, designed to pair with deliberate System 2 governors (Astra, Fable, Gemini, or Grok).
|
|
5
|
+
Symmetrically available as both `import system1` and `import reflex`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from typing import Any, Mapping, Optional, Sequence, Type, Union
|
|
12
|
+
|
|
13
|
+
# Core mathematical kernel and schema primitives (Zero crypto, Zero SQLite, pure NumPy)
|
|
14
|
+
from system1.core import (
|
|
15
|
+
BooleanField,
|
|
16
|
+
ChoiceField,
|
|
17
|
+
DecisionField,
|
|
18
|
+
DecisionFieldHead,
|
|
19
|
+
DecisionSchema,
|
|
20
|
+
FieldDefinition,
|
|
21
|
+
DeterministicSemanticProjector,
|
|
22
|
+
HybridProjector,
|
|
23
|
+
HybridSemanticProjector,
|
|
24
|
+
LocalNeuralProjector,
|
|
25
|
+
ModelInferenceResult,
|
|
26
|
+
MultiChoiceField,
|
|
27
|
+
RawFieldEvaluation,
|
|
28
|
+
ScoreField,
|
|
29
|
+
SubwordSemanticEmbeddings,
|
|
30
|
+
SystemOneModel,
|
|
31
|
+
SchemaMeta,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Calibration & Conformal Prediction primitives (pure NumPy, zero crypto, zero SQLite)
|
|
35
|
+
from system1.calibration import (
|
|
36
|
+
BrierDecomposition,
|
|
37
|
+
CalibrationMetrics,
|
|
38
|
+
ConformalPredictionSet,
|
|
39
|
+
ConformalPredictor,
|
|
40
|
+
DecisionCalibrator,
|
|
41
|
+
RegressionConformalInterval,
|
|
42
|
+
RegressionConformalPredictor,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Eager lightweight submodules
|
|
46
|
+
from system1 import (
|
|
47
|
+
calibration,
|
|
48
|
+
core,
|
|
49
|
+
embeddings,
|
|
50
|
+
model,
|
|
51
|
+
neural,
|
|
52
|
+
schema,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
__version__ = "0.1.1"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def decide(
|
|
59
|
+
prompt: str,
|
|
60
|
+
schema: Union[DecisionSchema, Type[DecisionSchema]],
|
|
61
|
+
*,
|
|
62
|
+
telemetry: Optional[Any] = None,
|
|
63
|
+
alpha: float = 0.05,
|
|
64
|
+
record_receipt: bool = True,
|
|
65
|
+
dimension: int = 384,
|
|
66
|
+
backend: str = "auto",
|
|
67
|
+
projector: Optional[Any] = None,
|
|
68
|
+
margin_threshold: Optional[float] = None,
|
|
69
|
+
) -> Any:
|
|
70
|
+
"""One-liner functional API for evaluating a System 1 decision against a typed schema.
|
|
71
|
+
|
|
72
|
+
Example:
|
|
73
|
+
import system1
|
|
74
|
+
|
|
75
|
+
class RoutingSchema(system1.DecisionSchema):
|
|
76
|
+
route = system1.ChoiceField(options=["sales", "support", "billing"])
|
|
77
|
+
is_escalation = system1.BooleanField()
|
|
78
|
+
|
|
79
|
+
result = system1.decide("Customer invoice payment dispute", schema=RoutingSchema)
|
|
80
|
+
print(result.route)
|
|
81
|
+
print(result.confidences["route"])
|
|
82
|
+
print(result.conformal_sets["route"])
|
|
83
|
+
"""
|
|
84
|
+
if not isinstance(prompt, str):
|
|
85
|
+
raise TypeError(f"Prompt must be a string, got {type(prompt).__name__}")
|
|
86
|
+
from system1.engine import ReflexEngine
|
|
87
|
+
engine_instance = ReflexEngine(
|
|
88
|
+
schema,
|
|
89
|
+
dimension=dimension,
|
|
90
|
+
backend=backend,
|
|
91
|
+
projector=projector,
|
|
92
|
+
margin_threshold=margin_threshold,
|
|
93
|
+
)
|
|
94
|
+
return engine_instance.decide(
|
|
95
|
+
prompt,
|
|
96
|
+
telemetry=telemetry,
|
|
97
|
+
alpha=alpha,
|
|
98
|
+
record_receipt=record_receipt,
|
|
99
|
+
margin_threshold=margin_threshold,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
evaluate = decide
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
_SUBMODULE_NAMES = {
|
|
107
|
+
"cache",
|
|
108
|
+
"calibration",
|
|
109
|
+
"cli",
|
|
110
|
+
"compat",
|
|
111
|
+
"compiler",
|
|
112
|
+
"core",
|
|
113
|
+
"embeddings",
|
|
114
|
+
"engine",
|
|
115
|
+
"grpc_server",
|
|
116
|
+
"guard",
|
|
117
|
+
"integrations",
|
|
118
|
+
"ledger",
|
|
119
|
+
"model",
|
|
120
|
+
"neural",
|
|
121
|
+
"proto",
|
|
122
|
+
"receipt",
|
|
123
|
+
"schema",
|
|
124
|
+
"telemetry",
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
# Lazy-loaded governance modules and symbols (cryptography, SQLite, reference monitor, compat)
|
|
128
|
+
_MODULE_MAP = {
|
|
129
|
+
# 18 submodules
|
|
130
|
+
"cache": "system1.cache",
|
|
131
|
+
"calibration": "system1.calibration",
|
|
132
|
+
"cli": "system1.cli",
|
|
133
|
+
"compat": "system1.compat",
|
|
134
|
+
"compiler": "system1.compiler",
|
|
135
|
+
"core": "system1.core",
|
|
136
|
+
"embeddings": "system1.embeddings",
|
|
137
|
+
"engine": "system1.engine",
|
|
138
|
+
"grpc_server": "system1.grpc_server",
|
|
139
|
+
"guard": "system1.guard",
|
|
140
|
+
"integrations": "system1.integrations",
|
|
141
|
+
"ledger": "system1.ledger",
|
|
142
|
+
"model": "system1.model",
|
|
143
|
+
"neural": "system1.neural",
|
|
144
|
+
"proto": "system1.proto",
|
|
145
|
+
"receipt": "system1.receipt",
|
|
146
|
+
"schema": "system1.schema",
|
|
147
|
+
"telemetry": "system1.telemetry",
|
|
148
|
+
# cache (Lever 1)
|
|
149
|
+
"SemanticReflexCache": "system1.cache",
|
|
150
|
+
"CacheEntry": "system1.cache",
|
|
151
|
+
# telemetry (Lever 4)
|
|
152
|
+
"TelemetryProjector": "system1.telemetry",
|
|
153
|
+
# engine
|
|
154
|
+
"ReflexEngine": "system1.engine",
|
|
155
|
+
"SystemOneEngine": "system1.engine",
|
|
156
|
+
"System1Engine": "system1.engine",
|
|
157
|
+
"DecisionResult": "system1.engine",
|
|
158
|
+
"BenchmarkReport": "system1.engine",
|
|
159
|
+
# receipt
|
|
160
|
+
"DecisionWitnessReceipt": "system1.receipt",
|
|
161
|
+
"create_decision_receipt": "system1.receipt",
|
|
162
|
+
"verify_decision_witness_receipt": "system1.receipt",
|
|
163
|
+
"compute_receipt_digest": "system1.receipt",
|
|
164
|
+
"RunWitnessEnvelope": "system1.receipt",
|
|
165
|
+
"create_run_witness_envelope": "system1.receipt",
|
|
166
|
+
"sign_run_witness_envelope": "system1.receipt",
|
|
167
|
+
"verify_run_witness_envelope": "system1.receipt",
|
|
168
|
+
"canonical_json": "system1.receipt",
|
|
169
|
+
"canonical_bytes": "system1.receipt",
|
|
170
|
+
"fingerprint": "system1.receipt",
|
|
171
|
+
"public_key_bytes": "system1.receipt",
|
|
172
|
+
"public_key_fingerprint": "system1.receipt",
|
|
173
|
+
"load_private_key": "system1.receipt",
|
|
174
|
+
"load_public_key": "system1.receipt",
|
|
175
|
+
"save_keypair": "system1.receipt",
|
|
176
|
+
"save_private_key": "system1.receipt",
|
|
177
|
+
"save_public_key": "system1.receipt",
|
|
178
|
+
"sign_payload": "system1.receipt",
|
|
179
|
+
"verify_payload": "system1.receipt",
|
|
180
|
+
"DECISION_WITNESS_PROFILE": "system1.receipt",
|
|
181
|
+
# ledger
|
|
182
|
+
"ActionLedger": "system1.ledger",
|
|
183
|
+
"LedgerError": "system1.ledger",
|
|
184
|
+
"LedgerWriteError": "system1.ledger",
|
|
185
|
+
"IntegrityError": "system1.ledger",
|
|
186
|
+
# guard
|
|
187
|
+
"ReflexGuard": "system1.guard",
|
|
188
|
+
"ReflexGuardHook": "system1.guard",
|
|
189
|
+
"SystemOneGuard": "system1.guard",
|
|
190
|
+
"SystemOneGuardHook": "system1.guard",
|
|
191
|
+
"PolicyRule": "system1.guard",
|
|
192
|
+
"PolicyEngine": "system1.guard",
|
|
193
|
+
"DeterministicPolicyEngine": "system1.guard",
|
|
194
|
+
"DefaultGuardDecisionSchema": "system1.guard",
|
|
195
|
+
"GuardInterceptionResult": "system1.guard",
|
|
196
|
+
"ActionProposal": "system1.guard",
|
|
197
|
+
"PolicyDecision": "system1.guard",
|
|
198
|
+
"EvidenceRef": "system1.guard",
|
|
199
|
+
"DecisionOutcome": "system1.guard",
|
|
200
|
+
"RiskLevel": "system1.guard",
|
|
201
|
+
"ActionState": "system1.guard",
|
|
202
|
+
"ResultStatus": "system1.guard",
|
|
203
|
+
# compat
|
|
204
|
+
"TypeSafeClient": "system1.compat.typesafe",
|
|
205
|
+
"Client": "system1.compat.typesafe",
|
|
206
|
+
"AsyncTypeSafeClient": "system1.compat.typesafe",
|
|
207
|
+
"AsyncClient": "system1.compat.typesafe",
|
|
208
|
+
"Choice": "system1.compat.typesafe",
|
|
209
|
+
"MultiChoice": "system1.compat.typesafe",
|
|
210
|
+
"Noul": "system1.compat.typesafe",
|
|
211
|
+
"Score": "system1.compat.typesafe",
|
|
212
|
+
"TypeSafeResponse": "system1.compat.typesafe",
|
|
213
|
+
"SystemOneResponse": "system1.compat.typesafe",
|
|
214
|
+
"ChoiceAnswer": "system1.compat.typesafe",
|
|
215
|
+
"NoulAnswer": "system1.compat.typesafe",
|
|
216
|
+
"ScoreAnswer": "system1.compat.typesafe",
|
|
217
|
+
"MultiChoiceAnswer": "system1.compat.typesafe",
|
|
218
|
+
"Usage": "system1.compat.typesafe",
|
|
219
|
+
"system_one": "system1.compat.typesafe",
|
|
220
|
+
"systemone": "system1.compat.typesafe",
|
|
221
|
+
"batch_system_one": "system1.compat.typesafe",
|
|
222
|
+
"batch_systemone": "system1.compat.typesafe",
|
|
223
|
+
"patch_typesafe": "system1.compat.typesafe",
|
|
224
|
+
"DotDict": "system1.compat.typesafe",
|
|
225
|
+
"ZeroEgressViolationError": "system1.compat.typesafe",
|
|
226
|
+
# compiler
|
|
227
|
+
"ReflexCompiler": "system1.compiler",
|
|
228
|
+
"CompiledSystemOneModel": "system1.compiler",
|
|
229
|
+
# integrations
|
|
230
|
+
"ReflexMCPProxy": "system1.integrations",
|
|
231
|
+
"ReflexMCPBlockedError": "system1.integrations",
|
|
232
|
+
"wrap_mcp_tool": "system1.integrations",
|
|
233
|
+
"ReflexGatewayMiddleware": "system1.integrations",
|
|
234
|
+
"add_reflex_gateway": "system1.integrations",
|
|
235
|
+
"ReflexGuardCallbackHandler": "system1.integrations",
|
|
236
|
+
"ReflexToolInterceptor": "system1.integrations",
|
|
237
|
+
"ReflexGuardBlockedException": "system1.integrations",
|
|
238
|
+
"wrap_langchain_tool": "system1.integrations",
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def __getattr__(name: str) -> Any:
|
|
243
|
+
mod_name = _MODULE_MAP.get(name)
|
|
244
|
+
if mod_name is not None:
|
|
245
|
+
import importlib
|
|
246
|
+
mod = importlib.import_module(mod_name)
|
|
247
|
+
if name in _SUBMODULE_NAMES:
|
|
248
|
+
val = mod
|
|
249
|
+
else:
|
|
250
|
+
val = getattr(mod, name)
|
|
251
|
+
globals()[name] = val
|
|
252
|
+
return val
|
|
253
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def __dir__() -> list[str]:
|
|
257
|
+
return sorted(set(globals().keys()) | set(__all__) | set(_MODULE_MAP.keys()) | _SUBMODULE_NAMES)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
__all__ = [
|
|
261
|
+
# Version
|
|
262
|
+
"__version__",
|
|
263
|
+
# Engine & Core Results
|
|
264
|
+
"ReflexEngine",
|
|
265
|
+
"SystemOneEngine",
|
|
266
|
+
"System1Engine",
|
|
267
|
+
"DecisionResult",
|
|
268
|
+
"BenchmarkReport",
|
|
269
|
+
"decide",
|
|
270
|
+
# Schemas & Fields
|
|
271
|
+
"DecisionSchema",
|
|
272
|
+
"DecisionField",
|
|
273
|
+
"FieldDefinition",
|
|
274
|
+
"ChoiceField",
|
|
275
|
+
"BooleanField",
|
|
276
|
+
"MultiChoiceField",
|
|
277
|
+
"ScoreField",
|
|
278
|
+
"SchemaMeta",
|
|
279
|
+
# Calibration & Conformal Prediction
|
|
280
|
+
"DecisionCalibrator",
|
|
281
|
+
"CalibrationMetrics",
|
|
282
|
+
"BrierDecomposition",
|
|
283
|
+
"ConformalPredictor",
|
|
284
|
+
"ConformalPredictionSet",
|
|
285
|
+
"RegressionConformalPredictor",
|
|
286
|
+
"RegressionConformalInterval",
|
|
287
|
+
# Proof-Carrying Evidence Receipts & Crypto
|
|
288
|
+
"DecisionWitnessReceipt",
|
|
289
|
+
"create_decision_receipt",
|
|
290
|
+
"verify_decision_witness_receipt",
|
|
291
|
+
"compute_receipt_digest",
|
|
292
|
+
"RunWitnessEnvelope",
|
|
293
|
+
"create_run_witness_envelope",
|
|
294
|
+
"sign_run_witness_envelope",
|
|
295
|
+
"verify_run_witness_envelope",
|
|
296
|
+
"canonical_json",
|
|
297
|
+
"canonical_bytes",
|
|
298
|
+
"fingerprint",
|
|
299
|
+
"public_key_bytes",
|
|
300
|
+
"public_key_fingerprint",
|
|
301
|
+
"load_private_key",
|
|
302
|
+
"load_public_key",
|
|
303
|
+
"save_keypair",
|
|
304
|
+
"save_private_key",
|
|
305
|
+
"save_public_key",
|
|
306
|
+
"sign_payload",
|
|
307
|
+
"verify_payload",
|
|
308
|
+
"DECISION_WITNESS_PROFILE",
|
|
309
|
+
# Action Ledger
|
|
310
|
+
"ActionLedger",
|
|
311
|
+
"LedgerError",
|
|
312
|
+
"LedgerWriteError",
|
|
313
|
+
"IntegrityError",
|
|
314
|
+
# Reference Monitor & Guard
|
|
315
|
+
"ReflexGuard",
|
|
316
|
+
"ReflexGuardHook",
|
|
317
|
+
"SystemOneGuard",
|
|
318
|
+
"SystemOneGuardHook",
|
|
319
|
+
"PolicyRule",
|
|
320
|
+
"PolicyEngine",
|
|
321
|
+
"DeterministicPolicyEngine",
|
|
322
|
+
"DefaultGuardDecisionSchema",
|
|
323
|
+
"GuardInterceptionResult",
|
|
324
|
+
"ActionProposal",
|
|
325
|
+
"PolicyDecision",
|
|
326
|
+
"EvidenceRef",
|
|
327
|
+
"DecisionOutcome",
|
|
328
|
+
"RiskLevel",
|
|
329
|
+
"ActionState",
|
|
330
|
+
"ResultStatus",
|
|
331
|
+
# Model & Neural Projection
|
|
332
|
+
"SystemOneModel",
|
|
333
|
+
"DecisionFieldHead",
|
|
334
|
+
"DeterministicSemanticProjector",
|
|
335
|
+
"LocalNeuralProjector",
|
|
336
|
+
"HybridProjector",
|
|
337
|
+
"HybridSemanticProjector",
|
|
338
|
+
"SubwordSemanticEmbeddings",
|
|
339
|
+
"ModelInferenceResult",
|
|
340
|
+
"RawFieldEvaluation",
|
|
341
|
+
# TypeSafe Compatibility
|
|
342
|
+
"TypeSafeClient",
|
|
343
|
+
"Client",
|
|
344
|
+
"AsyncTypeSafeClient",
|
|
345
|
+
"AsyncClient",
|
|
346
|
+
"Choice",
|
|
347
|
+
"MultiChoice",
|
|
348
|
+
"Noul",
|
|
349
|
+
"Score",
|
|
350
|
+
"TypeSafeResponse",
|
|
351
|
+
"SystemOneResponse",
|
|
352
|
+
"ChoiceAnswer",
|
|
353
|
+
"NoulAnswer",
|
|
354
|
+
"ScoreAnswer",
|
|
355
|
+
"MultiChoiceAnswer",
|
|
356
|
+
"Usage",
|
|
357
|
+
"system_one",
|
|
358
|
+
"systemone",
|
|
359
|
+
"batch_system_one",
|
|
360
|
+
"batch_systemone",
|
|
361
|
+
"patch_typesafe",
|
|
362
|
+
"DotDict",
|
|
363
|
+
"ZeroEgressViolationError",
|
|
364
|
+
# Compiler
|
|
365
|
+
"ReflexCompiler",
|
|
366
|
+
"CompiledSystemOneModel",
|
|
367
|
+
# 4 Levers (Cache, Telemetry, Online Update, Margin Gating)
|
|
368
|
+
"SemanticReflexCache",
|
|
369
|
+
"CacheEntry",
|
|
370
|
+
"TelemetryProjector",
|
|
371
|
+
"evaluate",
|
|
372
|
+
# Framework Integrations (MCP, FastAPI, LangChain)
|
|
373
|
+
"ReflexMCPProxy",
|
|
374
|
+
"ReflexMCPBlockedError",
|
|
375
|
+
"wrap_mcp_tool",
|
|
376
|
+
"ReflexGatewayMiddleware",
|
|
377
|
+
"add_reflex_gateway",
|
|
378
|
+
"ReflexGuardCallbackHandler",
|
|
379
|
+
"ReflexToolInterceptor",
|
|
380
|
+
"ReflexGuardBlockedException",
|
|
381
|
+
"wrap_langchain_tool",
|
|
382
|
+
]
|