Showcase: Deterministic Neuro-Symbolic Kernel & O(1) Token Gatekeeper for google-genai

Hi Gemini API & DevRel Team, While testing the `google-genai` SDK (`gemini-3.8-flash`) on a 75 MB clinical conversation dataset (`opus5-5diseaseconversations.jsonl`), I built an open-source, zero-dependency **Neuro-Symbolic Python Kernel** designed to solve two major bottlenecks in production LLM pipelines: **API token cost/rate-limit spikes** and **multi-hop causal hallucinations** (plus **adversarial prompt injection**). :link: **GitHub Repository (MIT License):** GitHub - sunsteelts-ctrl/abhidhamma-neuro-symbolic-kernel: Deterministic Causal Inference, O(1) Thermodynamic Gatekeeping & Intrinsic AI Alignment wrapper for Google Gemini (google-genai) · GitHub ### How It Works (3-Layer State Machine) Instead of using the LLM as an autonomous executive agent, this architecture demotes Gemini to a **stateless, read-only perception sensor (`Santīraṇa`)** inside a deterministic state-machine modeled on the formal logic of the *Abhidhamma* and *Paṭṭhāna* (24 conditional relations): 1. **$O(1)$ Thermodynamic Gatekeeper (`RupaDualStreamPipeline`):** * Scans incoming text streams locally at **>1,000 records/sec** on a single CPU core before touching the API. * Decouples input into **Channel A (`KineticImpression`)** and **Channel B (`SemanticProposition`)**. * Low-friction/nominal logs are routed to a local fast-path (`SATI_OBSERVATION`), cutting API token usage by **45%–80%**. * High kinetic turbulence ($\ge 0.50$, e.g., adversarial jailbreak attempts) automatically clamps `enforced_temperature = 0.0`. 2. **Subordinate Structured Perception & Counterfactual Firewall:** * Gemini is called *only* at Moment 7 under a strict `RESPONSE_JSON_SCHEMA` to extract canonical `(cause_a → effect_b)` pairs and state vectors. * Built-in Token-Bucket pacing and dynamic `RetryInfo` parsing seamlessly absorb Free-Tier `429 RESOURCE_EXHAUSTED` and `503 UNAVAILABLE` spikes with graceful fallback. * A counterfactual check (`Natthi-paccaya` at Moment 11) expels spurious correlations, while a 52-dimensional constraint matrix (`enforce_sampayoga`) mathematically zeroes out hostile/dogmatic vectors before execution. 3. **Sensor-Off Transitive Root-Cause Analysis (`ManodvaraSynthesizer`):** * After batch ingestion, the kernel detaches from external input and runs a 12-moment synthesis cycle over the persistent JSON Knowledge Graph (`BhavangaMemoryStore`), using **zero additional LLM calls** to discover multi-hop transitive chains ($A \rightarrow B$ in Record X, $B \rightarrow C$ in Record Y $\implies A \implies C$). ### Empirical Results on Clinical Data (with `gemini-3.8-flash`) On a 20-record sample from the clinical archive: * **9/20 records** filtered in $O(1)$ fast-path (~0.5ms/record). * **442 causal edges** mathematically verified in the graph. * **11 multi-hop transitive laws** autonomously deduced across separate records, such as: * `‘22q11.2 microdeletion’ → [‘hypoparathyroidism’] → ‘hypocalcemia’ ==> ‘carpopedal spasm’ & ‘qtc interval prolongation’` * `‘plaque rupture or erosion with superimposed thrombosis’ → [‘acute reduction in coronary blood flow’] ==> ‘cardiac troponin elevation’` ### Run the 1-Second Benchmark (Zero Dependencies) You can test both the **Adversarial Jailbreak Defense** and **Distributed Telemetry RCA** locally in 1 second: ```bash git clone [https://github.com/sunsteelts-ctrl/abhidhamma-neuro-symbolic-kernel.git\](GitHub - sunsteelts-ctrl/abhidhamma-neuro-symbolic-kernel: Deterministic Causal Inference, O(1) Thermodynamic Gatekeeping & Intrinsic AI Alignment wrapper for Google Gemini (google-genai) · GitHub) cd abhidhamma-neuro-symbolic-kernel python3 abhidhamma_engineering_showcase.py