Lightweight deterministic execution substrate for governed operations.
Project description
KL Kernel Logic
A small deterministic execution model core.
KL Kernel Logic provides three components:
PsiDefinition: operation definition (what)Kernel: atomic execution primitive (how)CAEL: sequential behaviour order (in what order)
It does not handle orchestration, governance, or policy. Those belong to higher layers.
Version 0.4.0
Version 0.4.0 represents a radical simplification of the core. The codebase has been reduced in three stages:
- From approximately 2000 lines of code
- To approximately 700 lines of core code
- To the current 244 LOC minimal core (psi.py, kernel.py, cael.py)
This reduction reflects a move toward an axiomatic, minimal, stable substrate. The core now contains only what is necessary for the deterministic execution model and tracing.
KL Kernel Logic 0.4.0 is a minimal, stable core.
The public API in __init__.py and the behaviour covered by the tests are considered frozen.
Installation
pip install kl-kernel-logic
Core Concepts
PsiDefinition
A minimal logical operation descriptor. The core treats PsiDefinition as opaque. It stores and passes through these values but never interprets them.
PsiDefinition(
psi_type: str,
name: str,
metadata: Mapping[str, Any] | None = None,
)
PsiDefinition metadata is purely descriptive and never enters the Kernel or the ExecutionTrace unless explicitly passed to Kernel.execute().
Kernel
A deterministic execution engine. Deterministic in its execution model, not in the behaviour of user-provided tasks. Given a PsiDefinition and a callable, the Kernel executes the task and returns an ExecutionTrace.
Semantics:
taskis called exactly once with**kwargssuccessisTrueif and only if no exception is raised bytaskoutputcontains the return value on success,Noneon failureruntime_msis measured via a monotonic perf counter, always non-negativerun_idis unique per execution
The Kernel never interprets metadata, never makes policy decisions, and never retries. Kernel implements Δ as atomicity of execution and observation, not as state change. State belongs to user logic.
ExecutionTrace
Immutable record of a single Kernel execution.
Fields:
psi: the PsiDefinition usedrun_id: unique identifier for this executionsuccess:Trueif task completed without exceptionoutput: return value of task (orNoneon failure)error: exception message (orNoneon success)exception_type: exception class name (orNone)exception_repr: repr of exception (orNone)started_at: UTC datetime when execution started (wall clock)finished_at: UTC datetime when execution finished (wall clock)runtime_ms: elapsed time in milliseconds (monotonic perf counter)metadata: the metadata dict passed toKernel.execute(), not from PsiDefinition
Time carries two layers: observational wall-clock time (UTC timestamps) and monotonic duration (runtime_ms). runtime_ms provides a monotonic measure suitable for ordering and duration, independent of wall-clock adjustments.
The core never mutates traces after creation.
CAEL
Sequential Atomic Execution Layer. Runs a sequence of independent (psi, task, kwargs) steps via a single Kernel instance in deterministic order.
Semantics:
- Steps are executed in order
- If a step fails, execution stops immediately
CaelResult.successisTrueif and only if all steps succeededCaelResult.final_outputis the output of the last successful step, orNoneif the first step failsCaelResult.tracesis the ordered list ofExecutionTraceobjects (only executed steps)
CAEL does not pass output from one step to the next. Each step receives its own independent kwargs. It does not include retry logic, routing, or governance. CAEL establishes a total order over execution steps, independent of temporal measurements.
Usage
Basic Kernel Execution
from kl_kernel_logic import PsiDefinition, Kernel
def uppercase(text: str) -> str:
return text.upper()
psi = PsiDefinition(psi_type="text", name="uppercase")
kernel = Kernel()
trace = kernel.execute(psi=psi, task=uppercase, text="hello")
print(trace.success) # True
print(trace.output) # "HELLO"
CAEL with Independent Steps
from kl_kernel_logic import PsiDefinition, Kernel, CAEL
def step_a() -> int:
return 10
def step_b() -> int:
return 20
psi_a = PsiDefinition(psi_type="math", name="first")
psi_b = PsiDefinition(psi_type="math", name="second")
cael = CAEL(kernel=Kernel())
result = cael.run([
(psi_a, step_a, {}),
(psi_b, step_b, {}),
])
print(result.success) # True
print(result.final_output) # 20
print(len(result.traces)) # 2
Scope and Non-Goals
This package does not handle:
- Policy enforcement
- Governance or access control
- Rate limiting or quotas
- Domain-specific logic
- Retry or fallback strategies
KL Kernel Logic is a small deterministic substrate. Higher layers (gateways, governance layers, orchestrators) build on top of it.
KL Execution Theory
KL Kernel Logic implements Δ (atomic transitions) and V (behaviour sequences) in their stateless form, and provides observable projections of t (logical order and duration). State transitions belong to higher layers or to user logic. G (governance) and L (boundaries) live in higher layers such as gateways or governance systems.
License
MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kl_kernel_logic-0.4.0.tar.gz.
File metadata
- Download URL: kl_kernel_logic-0.4.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8caf2e2d78c54816639ba774c14846713c48400db8b2d0df738cf4388c120a08
|
|
| MD5 |
8ae41c6ce35c05b6fb2d2e454cee1327
|
|
| BLAKE2b-256 |
42f4c05d07d32dd342789bc267ae30a84b4693da8a2fa8035d4fdd2c28edfe25
|
File details
Details for the file kl_kernel_logic-0.4.0-py3-none-any.whl.
File metadata
- Download URL: kl_kernel_logic-0.4.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2be6fb15bc6bf7ada9fde175c6068bb562b50901236961084d6a20424bf142f3
|
|
| MD5 |
33abb0f7193db101ce471569988ca6f7
|
|
| BLAKE2b-256 |
a64371e4d04afa2a05588886cd4dec69a28d8364fb5bddacbb3044e51181797b
|