Client-side Frugal-AI layer: context apoptosis that auditably cuts LLM inference cost per deployment.
Project description
B.I.O.M.A.
🌐 English · Português
A local, provider-agnostic efficiency & security micro-kernel for LLM applications.
📖 Full technical guide (architecture, enterprise deployment, tuning): TECHNICAL_GUIDE.pt-BR.md
B.I.O.M.A. is a drop-in artifact — a lock-free Rust kernel (bioma_micro) plus a
thin Python layer — that you embed in any project or architecture that talks to an
LLM. It does not try to make the model "smarter". It makes the processing cheaper,
faster and safer, in-process, before your prompt ever leaves the machine:
- Context apoptosis — dehydrates wasted/stale context (−80% input tokens; up to −97% on long sessions).
- Cognitive firewall — secret redaction, cognitive-DDoS/flood detection, and a dispatch timeout guard.
- Hormonal bus — lock-free μs signalling substrate (~2M signals/s).
100% local. Provider-agnostic: harden the payload here, then send it to Anthropic, Google, OpenAI — or anything — with your SDK.
New here?
OVERVIEW.mdexplains what B.I.O.M.A. is, the pain it attacks, and the real benchmarks as proof. Step-by-step deployment (local & online providers) is inIMPLEMENTATION.md. Every claim is measured and audited inFINDINGS.md, including what we tested and refuted (multi-LLM "mitosis" does not improve quality — it is not part of the product).
Use it as a library (any provider)
from bioma.firewall_client import CognitiveFirewall
fw = CognitiveFirewall(vault={"db_password": DB_PW}) # secrets to protect
# (a) PURE artifact — harden, then call YOUR provider with YOUR SDK:
h = fw.shield(history, "refactor this function")
# h.prompt / h.system → clean, dehydrated, secret-free payload
# h.telemetry → saturation, red_alert, apoptosis_reduction, kernel_latency_us
import anthropic # or google.genai, or openai
msg = anthropic.Anthropic().messages.create(
model="claude-sonnet-5", max_tokens=1024,
system=h.system or "", messages=[{"role": "user", "content": h.prompt}])
# (b) Bring your own async dispatcher (Anthropic/Google/OpenAI), keep the guards:
shield = await fw.harden(history, "refactor", dispatch_fn=my_async_provider_call)
# → timeout guard + response-side secret redaction applied automatically
The Rust kernel is usable directly too:
import bioma_micro as k
k.dehydrate([("system rules", k.SYSTEM), ("verbose log " * 200, k.TOOL)]) # → -80% tokens
k.saturation_scan(payload) # cognitive-DDoS score 0..1 (flood ≈ 1.0)
Proven results (ground truth)
| Capability | Result | Source |
|---|---|---|
| Context apoptosis | −80% input tokens (up to −97% long sessions) | tests/test_enxuto_efficiency.py |
| Answer-quality preservation | 10/10 parity, 100% correct answers at −97% tokens (5 online models, objective probes) | tests/test_quality_preservation.py · reports/BIOMA_QUALITY_PRESERVATION.md |
| Measured energy per dispatch | 2,714.7 J → 69.5 J (−97.4%), quality parity (local Llama 3.2 1B, battery fuel gauge, idle subtracted) | tests/test_energy_local.py · reports/BIOMA_ENERGY_LOCAL.md |
| Vision context apoptosis (agent screenshot loops) | 6/6 parity, 100% correct at −56% real tokens (−77% at 24 steps; dehydrated payload is O(1) in session length) — 3 vision models, probes rendered into the pixels | tests/test_vision_quality_preservation.py · reports/BIOMA_VISION_QUALITY.md |
| Image distillation (keep-latest dedup + OCR + deterministic shape structure) | 100% answers at −74% tokens vs sending every image — stale images become ~25–86-token text blocks; local VLM captions measured and rejected (label confabulation) | tests/test_vision_distill.py · reports/BIOMA_VISION_DISTILL.md |
| Dev-workload cost benchmark (7 agent models, real OpenRouter usage & prices) | −57% to −86% median cost at quality parity — 126 real executions, paired replicas, failures reported first-page (Fable 5×T1 arm-B empty 3/3) | tests/benchmark_dev_openrouter.py · resultados/relatorio.md · resultados/SIMULACAO_MERCADO.md |
| Drop-in gateway (OpenAI and Anthropic surfaces, cache-safe, tool-pair aware) | −78% (OpenAI) / −33% (Anthropic) billed input tokens, answer intact with only base_url changed — proven with both official SDKs on real models; Claude Code speaks the Anthropic surface |
bioma/gateway.py · tests/test_gateway.py · tests/prove_gateway_dropin.py · tests/prove_anthropic_surface.py |
| Apoptosis × prompt caching (real Anthropic cache) | −65% net cost after the cache discount — the durable prefix hits the same cache in both arms; savings come from purging the never-cacheable middle | tests/measure_cache_interaction.py · resultados/MEDICOES_GATEWAY.md |
| Real Claude Code E2E (CLI through the gateway) | solves real bug+feature tasks, pytest green with only ANTHROPIC_BASE_URL changed; apoptosis is a safe no-op here (Claude Code self-manages context — nothing to purge), and the value shows on agents that don't (−84% measured) |
tests/e2e_claude_code.py · resultados/E2E_CLAUDE_CODE.md |
| E2E real tool-calling agent (fixes a real bug to green pytest) | −84% accumulated input tokens at task parity on a long-running agent (−0% on a 3-turn task — apoptosis is a correct no-op with no dead weight) | tests/e2e_agent_gateway.py · resultados/MEDICOES_GATEWAY.md |
| Hormonal bus | ~2M signals/s @ ~5μs, bounded under 10× load | archived bench (research repo) |
| Cognitive-DDoS mitigation | 15k-token flood → dehydrated pre-dispatch | tests/test_sovereign_defense.py |
| Secret redaction | vault values never reach the model | reports/BIOMA_IMMUNITY_VERDICT.md |
| Pixel secret redaction (closes our own declared gap) | a real vision model transcribes an AWS/OpenAI key from the original screenshot but only ████ from the redacted one — OCR + region masking, client-side |
tests/test_vision_secret_redaction.py · reports/BIOMA_PIXEL_SECRETS.md |
Install
pip install bioma-suite # EVERYTHING in one command (then: bioma-doctor)
pip install bioma-framework # core: the Rust micro-kernel + Python API
pip install "bioma-framework[gateway]" # + the drop-in OpenAI/Anthropic gateway
pip install "bioma-framework[all]" # + client, anthropic, vision and monitor tiers
# kernel only (no Python layer): pip install bioma-micro
bioma-suite is the one-shot meta-package: a single install pulls the kernel,
the framework with every tier, and the LangChain integration — and ships
bioma-doctor, a stdlib-only checkup that verifies each component imports and
runs a real kernel smoke test (exit 0 = core healthy).
The core install ships the compiled Rust kernel (bioma_micro) as a binary
wheel — no Rust toolchain required. Extras (gateway, client, anthropic,
vision) are opt-in so the base stays light. Publishing is one tag away for
maintainers (git tag v1.0.0 && git push --tags → the Release workflow builds
multi-platform wheels and publishes to PyPI). Local dev from source is in
Quickstart.
Drop-in gateway — apoptosis with zero code changes
Point any OpenAI-compatible or Anthropic-compatible client's base_url at
the gateway and every request gets context apoptosis transparently — no SDK
swap, no prompt rewrite:
pip install fastapi "uvicorn[standard]" httpx
uvicorn bioma.gateway:app --port 8790
# OpenAI clients:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8790/v1", api_key="...") # only change
# Anthropic clients (incl. Claude Code — set ANTHROPIC_BASE_URL):
from anthropic import Anthropic
client = Anthropic(base_url="http://localhost:8790", api_key="...") # only change
Both surfaces proven with the official SDKs on real models:
- OpenAI (
tests/prove_gateway_dropin.py): billed input −78% on Sonnet 5 / GLM-5.2 / Gemini 3.5 Flash, answer intact, streaming works. - Anthropic
/v1/messages(tests/prove_anthropic_surface.py): billed input −33% on Sonnet 5 / Opus 4.8, answer intact, streaming works — the protocol Claude Code speaks, soANTHROPIC_BASE_URL→ the gateway just works.
Design guarantees (each unit-tested in tests/test_gateway.py, 14 tests): the
current query is never filtered; the surviving system+FACT prefix stays
byte-identical across calls (prompt-cache-safe); tool-call/tool-result pairs
survive or purge as a unit (never orphaned) — on both the OpenAI tool role and
the Anthropic tool_use/tool_result block structure. Anthropic system is a
top-level field, forwarded untouched (never purged).
Frugal AI — the official KPI: energy per token
B.I.O.M.A. is a client-side Frugal AI layer that auditably reduces the energy
cost of LLM inference per deployment. The kernel's per-dispatch audit
(tokens before/after) is the KPI: the reduction percentage is exact and
coefficient-independent. A reproducible benchmark (tests/test_esg_benchmark.py
→ reports/BIOMA_ESG_BENCHMARK.md) converts the measured token savings into
bounded Wh/gCO2e estimates using declared literature coefficients
(0.5–1.3 kWh/M tokens; grid presets; caching-adjusted counterfactual), with the
conversion helpers shipped in bioma/esg.py. This is a per-deployment claim —
not a global one; it scales with adoption and with your grid.
Turn your own real traffic into a case report: run your workload through the
gateway, then python -m bioma.esg_report bioma_gateway_audit.jsonl --grid eu --price-in <your $/M> prints tokens / Wh / gCO2e / $ avoided from the measured
audit log — the design-partner instrument (bioma/esg_report.py). A ready-to-run
NVIDIA-GPU energy harness (tests/measure_energy_gpu.py) awaits datacenter
hardware; it fabricates no numbers without a GPU.
Live monitor — the terminal cockpit
Watch everything the deployment measures, in real time, from the terminal:
pip install "bioma-framework[monitor]"
bioma-monitor # follows bioma_gateway_audit.jsonl live
bioma-monitor --grid br --price-in 2.0 # + bounded ESG / $ estimates
bioma-monitor tails the same per-request audit JSONL the gateway writes
(BIOMA_AUDIT_LOG) — session totals, a reduction sparkline, kernel μs p50/max,
a per-model table, a request feed, and the gateway's /health status. Every
number on screen is a number in the log; the energy/cost panel reuses the
declared-coefficient estimator from bioma.esg and is always labeled an
estimate. --tail starts at the end of the log (live traffic only); --once
renders a single frame (CI/screenshot-friendly).
Auditable carbon ledger — a signed, verifiable savings report
A carbon or cost number is only credible if a third party can verify it. The carbon ledger turns the gateway's measured audit log into a signed, tamper-evident report — the instrument a CFO, a CSRD assessor or an external auditor can check without trusting you:
pip install "bioma-framework[ledger]"
bioma-carbon-ledger keygen --out issuer # Ed25519 keypair
bioma-carbon-ledger build bioma_gateway_audit.jsonl \
--grid br --price-in 2.0 --key issuer.key --out ledger.json
bioma-carbon-ledger verify ledger.json --pub issuer.pub --audit bioma_gateway_audit.jsonl
Four properties make it auditable: tokens are measured ground truth; the
audit rows are hash-chained (altering or dropping any row breaks the chain);
the finished ledger is Ed25519-signed (verified with the public key alone);
and energy uses the declared, versioned coefficient bounds from bioma.esg
(low/mid/high — the reduction % is exact, only the absolute Wh/CO2e inherit the
coefficient's uncertainty). verify catches both attacks: forging a signed
number → signature INVALID; tampering the audit → recompute MISMATCH.
Emissions are reported as an avoided-emissions counterfactual, separately —
never netted against Scope 1/2/3 and never called an offset (GHG Protocol).
Quickstart (local)
# Build & install the Rust micro-kernel (PyO3 extension)
python -m pip install maturin
cd bioma_micro && maturin build --release && \
pip install --force-reinstall target/wheels/bioma_micro-*.whl && cd ..
# Run the test suite (offline, deterministic)
pip install pytest fastapi "openai>=1"
python -m pytest tests/test_kernel.py tests/test_firewall.py tests/test_server.py -q
Optional: a local FastAPI runner (bioma.server, GET /health + POST /v1/dispatch)
and a local container image (deploy/Dockerfile.lean) are included — no hosted
service required.
Layout
bioma_micro/ Rust/PyO3 micro-kernel — hormonal bus + apoptosis + saturation_scan
bioma/ Python: CognitiveFirewall, LeanOpenRouterClient, local server, monitor
bioma_suite/ one-shot meta-package (`pip install bioma-suite`) + bioma-doctor
tests/ unit suite (kernel, firewall, server) + real end-to-end validations
FINDINGS.md ground-truth evaluation (proven / refuted), reproducible
reports/ immunity verdict (APT war-game)
License
Fair-source under the Functional Source License (FSL-1.1-MIT) (LICENSE):
read it, run it, and build on it for any non-competing purpose. The only limit is repackaging
it as a competing product, and each release automatically becomes MIT two years after its date.
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 bioma_framework-1.2.0.tar.gz.
File metadata
- Download URL: bioma_framework-1.2.0.tar.gz
- Upload date:
- Size: 48.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14489383000193ef10a06eabd22e381b1b2119f17f8943aa1ca274501a2667ff
|
|
| MD5 |
43478ceb7317668fd5d66419651fe3c5
|
|
| BLAKE2b-256 |
66e7aa19b9f63cab62e6478bdeaafed25acdbff719e0f4b0a539a1edaed0b084
|
Provenance
The following attestation bundles were made for bioma_framework-1.2.0.tar.gz:
Publisher:
release.yml on jonathascordeiro20/bioma-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bioma_framework-1.2.0.tar.gz -
Subject digest:
14489383000193ef10a06eabd22e381b1b2119f17f8943aa1ca274501a2667ff - Sigstore transparency entry: 2200731407
- Sigstore integration time:
-
Permalink:
jonathascordeiro20/bioma-framework@7ece5553c8f0ece717b16f36db51e9dda064e608 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/jonathascordeiro20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ece5553c8f0ece717b16f36db51e9dda064e608 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bioma_framework-1.2.0-py3-none-any.whl.
File metadata
- Download URL: bioma_framework-1.2.0-py3-none-any.whl
- Upload date:
- Size: 46.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ec660569f0d0d5ca9ec703e23ad7afb53f4ea97cd0f6e266dea46dc3cac1489
|
|
| MD5 |
e36e6e28499fcc1817d40df0b2981d9a
|
|
| BLAKE2b-256 |
0dbd4d7c832763b1999aff962dd24c60a70b4a317fb336bf1f4e0551dcd4050d
|
Provenance
The following attestation bundles were made for bioma_framework-1.2.0-py3-none-any.whl:
Publisher:
release.yml on jonathascordeiro20/bioma-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bioma_framework-1.2.0-py3-none-any.whl -
Subject digest:
7ec660569f0d0d5ca9ec703e23ad7afb53f4ea97cd0f6e266dea46dc3cac1489 - Sigstore transparency entry: 2200731531
- Sigstore integration time:
-
Permalink:
jonathascordeiro20/bioma-framework@7ece5553c8f0ece717b16f36db51e9dda064e608 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/jonathascordeiro20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ece5553c8f0ece717b16f36db51e9dda064e608 -
Trigger Event:
push
-
Statement type: