Skip to main content

B.I.O.M.A. Micro-Kernel — lock-free hormonal bus + autonomous context apoptosis.

Project description

bioma-micro

B.I.O.M.A. Micro-Kernel — a lean efficiency & resilience core for LLM infrastructure, written in Rust, exposed to Python via PyO3.

Exactly two proven primitives, nothing else:

  • Context apoptosis — autonomous history dehydration. Long agent sessions accumulate low-value ballast (verbose tool logs, stale turns). The kernel assigns each message a metabolic weight by class, applies half-life decay, and purges dead weight before the payload hits the API. Microsecond-scale, GIL-released, allocation-light.
  • Hormonal bus — lock-free in-memory signal injection (~2M signals/s, ~5 µs).

Plus saturation_scan(), an O(n) repetition detector for cognitive-DDoS / flood inputs.

Install

pip install bioma-micro

Prebuilt wheel for Windows (Python ≥ 3.8, abi3). Other platforms build from the sdist (requires a Rust toolchain: pip will invoke maturin automatically).

Quick start

import bioma_micro as bm

messages = [
    ("You are a precise operations copilot.", bm.SYSTEM),   # never purged
    ("FACT: the deploy freeze ends on 2026-07-18.", bm.FACT),  # never purged
    ("[tool log] 40 KB of verbose audit output ...", bm.TOOL),  # prime target
    ("Round 1: any anomaly?", bm.USER),
    ("Nothing above baseline.", bm.ASSISTANT),
    # ... hundreds of turns later ...
    ("What is the freeze end date?", bm.USER),
]

result = bm.dehydrate(messages, half_life=6.0, safe_threshold=0.35)
print(result["reduction"])          # fraction of input tokens purged (0..1)
print(result["kernel_latency_us"])  # pure-Rust decision pass, microseconds
prompt = "\n".join(result["kept"])  # dispatch this instead of the full history

Flood detection:

bm.saturation_scan(suspicious_text)  # ~1.0 = repetitive flood, ~0.0 = natural text

The honest contract

Measured, auditable behavior (full methodology and raw data in the framework repo):

Client behavior Measured effect
Naive tool-calling agent (resends growing history) −84% input tokens
Generic long session (16 rounds, resends everything) −95.8% input tokens
Claude Code (already self-manages context) ~0% — safe no-op
  • Values tagged FACT and recent turns survive; answer quality stays at parity with the full-context baseline (verified with objective probes against real online models).
  • Durable info buried in old untagged turns is purged by design — tag it FACT.
  • Against an already-lean agent the kernel is a no-op: it never helps, never hurts.

This is a safety net for agents that do not manage their own context — not a universal "−X%" claim.

API surface

Symbol Kind Purpose
dehydrate(messages, half_life=6.0, safe_threshold=0.35, stable_prefix=0) function one-shot history dehydration; stable_prefix = cache-aware zone kept verbatim; returns kept blocks + audit dict
saturation_scan(text, window=8) function duplicate-shingle flood score (0..1)
consolidation_gain(prefix_tokens, purgeable_tokens, calls_ahead=8, ...) function cache economics: is rewriting a cached prefix worth it? net gain + break-even calls
effort_gauge(text) function O(n) task-complexity score → recommended thinking budget (tier, budget_tokens, raw signals)
ContextApoptosis(half_life, safe_threshold, capacity, state_capacity=64) class stateful engine (insert / dehydrate(absorb=) / render) + purpose contract (set_purpose) + STATE ledger (note_state, state_entries)
HormonalBus, HormonalSignal class lock-free signal bus
SYSTEM, USER, ASSISTANT, FACT, TOOL, THINKING flags metabolic signal classes

Cache-aware dehydration & thinking budgets (1.1.0)

Two cost phases, two levers:

  • Input (prefill): apoptosis is deletion-only and order-preserving, so a durable prefix stays byte-identical. With provider prompt caching, pass stable_prefix to guarantee it, and ask consolidation_gain() when purging cached ballast actually pays off (cache reads at 0.1× make stale prefixes cheap — break-even is often 15+ calls away; the kernel does this arithmetic for you).
  • Reasoning (decode): thinking tokens are output-priced (~5×) and sequential. effort_gauge() scores each request with cheap lexical signals and returns the budget to forward as budget_tokens (Anthropic) / reasoning_effort (OpenAI) — trivial turns ("yes", "continue") stop paying for a full thinking budget.

License

FSL-1.1-MIT — Functional Source License 1.1 with MIT future license. Free for internal use, non-commercial use, and professional services; converts to MIT two years after each release.

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

bioma_micro-1.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bioma_micro-1.1.0-cp38-abi3-win_amd64.whl (201.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

bioma_micro-1.1.0-cp38-abi3-manylinux_2_34_x86_64.whl (282.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

bioma_micro-1.1.0-cp38-abi3-macosx_11_0_arm64.whl (259.4 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file bioma_micro-1.1.0.tar.gz.

File metadata

  • Download URL: bioma_micro-1.1.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for bioma_micro-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5b542b14a421b93522acb79922cc77136403eb7930e034ddc3fe97b813ffa87a
MD5 40327c20a5f859d8478014fcf05b8072
BLAKE2b-256 714ae3aaa0c6c641fa3d1b9d5e61bc8ded7490c845ff2655c44d2675eb9198cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bioma_micro-1.1.0.tar.gz:

Publisher: release.yml on jonathascordeiro20/bioma-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bioma_micro-1.1.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: bioma_micro-1.1.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 201.8 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for bioma_micro-1.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6a0d9ddab3854580a5bb10a2260769aaab7df438accbdfcc34b6fa4d58814541
MD5 1941c6cf03a701d775cec7babbd8268d
BLAKE2b-256 f068435b8bd093df9108c4e1649f24e1bb76d93ea7188ff0452a111bcf8f7134

See more details on using hashes here.

Provenance

The following attestation bundles were made for bioma_micro-1.1.0-cp38-abi3-win_amd64.whl:

Publisher: release.yml on jonathascordeiro20/bioma-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bioma_micro-1.1.0-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for bioma_micro-1.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fa670e037a36f2afdd25f5d539632041518e1944830f50b9d83e2a23b95f7fe5
MD5 ed3b6809f21d0130aa9ffc4a2576d000
BLAKE2b-256 a9d7b4ab754159c0ec95993b465c02bc001111c024186200ad0c4e4fe34a7ab9

See more details on using hashes here.

Provenance

The following attestation bundles were made for bioma_micro-1.1.0-cp38-abi3-manylinux_2_34_x86_64.whl:

Publisher: release.yml on jonathascordeiro20/bioma-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bioma_micro-1.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bioma_micro-1.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9d9ba5e43f2ef462f99b38886bdbd717102f074216d7fc7d374744c8f3e4a45
MD5 01a44ca8a36caf00985c9ec033194384
BLAKE2b-256 48caa670f614764cc9586b36301111965261a8f330b997611f4bd465c353b4a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bioma_micro-1.1.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on jonathascordeiro20/bioma-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page