โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโ
โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โโโโ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โโโ
โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ
โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโ โโโ โโโโโโโ
A fully local, production-grade autonomous AI agent. Runs 9B-class GGUF models on constrained hardware using adaptive TurboQuant strategies โ all within a strict 3 GB RAM budget, no cloud required.
๐ Quick Start ยท ๐๏ธ Architecture ยท ๐ง TurboQuant ยท ๐ Structure ยท ๐ Security ยท โ Support
Heisenberg is not just another AI wrapper. It is a production-oriented autonomous agent built from the ground up for developers who refuse to compromise on privacy, performance, or control.
| Feature | Detail |
|---|---|
| ๐งฑ Core Language | Rust โ zero-cost abstractions, memory safety, raw speed |
| ๐ค Inference Engine | llama-cpp via FFI/subprocess (GGUF native) |
| ๐พ Memory Model | Adaptive 3 GB hard cap with graceful degradation |
| ๐ Execution Layer | Bash-first, auditable, sandboxed via ulimit |
| ๐งฌ Long-term Memory | PostgreSQL (mike module) |
| ๐ Browser Automation | Sandboxed via the_rv + scripts/drive.sh |
| โ๏ธ Cloud Dependency | Zero โ fully offline, fully private |
| ๐ฆ Model Format | GGUF (drop .gguf in models/ and go) |
flowchart TD
U(["๐ค User Terminal"]) -->|natural language input| H
subgraph HEISENBERG ["๐งช Heisenberg Orchestrator (Rust)"]
H["๐ฏ REPL / Action Loop"]
H -->|structured JSON commands| J["๐ง Jesse\nBash Executor"]
H -->|inference requests| L["โ๏ธ The Lab\nllama-cpp + GGUF Loader"]
H -->|memory ops| M["๐๏ธ Mike\nMemory Manager"]
H -->|schedule tasks| G["โฑ๏ธ Gus\nScheduler"]
H -.->|self-patch| B["๐ต Blue Sky\nSelf-Modification"]
H -.->|screen events| K["๐๏ธ Hank\nScreen Observer"]
H -.->|browser tasks| RV["๐ The RV\nBrowser Sandbox"]
end
J -->|shell result JSON| H
L -->|streamed tokens| H
M <-->|read/write| DB[("๐ PostgreSQL\nLong-term Memory")]
RV -->|page data| H
style HEISENBERG fill:#1a1a2e,stroke:#e94560,color:#fff
style U fill:#16213e,stroke:#0f3460,color:#fff
style DB fill:#0f3460,stroke:#533483,color:#fff
sequenceDiagram
autonumber
participant U as ๐ค User
participant R as ๐ฏ Rust Orchestrator
participant CF as ๐จ CMD_FIFO
participant BW as ๐ง Bash Worker (Jesse)
participant RF as ๐ฉ RESP_FIFO
participant DB as ๐๏ธ PostgreSQL (Mike)
U->>R: "Analyze logs and summarize"
R->>CF: write {cmd: "run", script: "cook.sh", args: [...]}
CF->>BW: Execute script under ulimit sandbox
BW->>BW: Run, collect stdout/stderr
BW->>RF: write {status: "ok", pid: 1234, output: "..."}
RF->>R: Read response
R->>DB: Persist summary to long-term memory
DB-->>R: ACK
R-->>U: Stream result tokens
flowchart LR
A["๐ GGUF Header Scan\n(layers, heads, dim, tokenizer)"]
--> B["๐ KV Cache Estimator\n(context ร layers ร heads ร dtype)"]
--> C["๐ Memory Planner\n(weights + KV + OS overhead)"]
C --> D{"> 3 GB?"}
D -- YES --> E["โก Quantization Selector\nQ8_0 โ Q5_0 โ Q4_0"]
D -- YES --> F["๐ Context Reducer\n2048 โ 1024 โ 512"]
D -- NO --> G["โ
Launch as-is"]
E --> H["๐ cook.sh Launcher\nulimit -v 3072 MB"]
F --> H
G --> H
H --> I["๐ Mike Live Monitor\n(RSS polling)"]
I -->|pressure detected| J["๐ Runtime Mitigation\n(shrink ctx / cancel tasks)"]
J --> I
style D fill:#e94560,stroke:#c23152,color:#fff
style H fill:#0f3460,stroke:#533483,color:#fff
style I fill:#16213e,stroke:#e94560,color:#fff
Each module in src/ has a named role inspired by Breaking Bad โ intentional, consistent, and memorable.
mindmap
root((๐งช Heisenberg))
๐ฏ heisenberg
REPL loop
Action dispatcher
Agent state machine
โ๏ธ the_lab
GGUF loader
llama-cpp FFI
TurboQuant Planner
Token streamer
๐ง jesse
Bash executor
FIFO IPC
ulimit sandbox
Script runner
โฑ๏ธ gus
Task scheduler
Priority queue
Retry logic
๐๏ธ mike
Memory manager
PostgreSQL glue
Context compaction
Pressure monitor
โ๏ธ saul
Config parser
CLI interface
Argument validation
๐๏ธ hank
Screen observer
Event capture
Display hooks
๐ the_rv
Browser sandbox
Automation layer
Allow-list engine
๐ต blue_sky
Self-modification
Patch generator
Safe apply
Heisenberg/
โ
โโโ ๐ฆ src/
โ โโโ heisenberg/ # ๐ฏ Orchestrator โ REPL, action loop, agent state machine
โ โโโ the_lab/ # โ๏ธ Inference engine โ GGUF loader, llama-cpp, TurboQuant
โ โโโ jesse/ # ๐ง Bash executor โ FIFO IPC, sandboxed shell worker
โ โโโ gus/ # โฑ๏ธ Scheduler โ task queue, priority, retries
โ โโโ mike/ # ๐๏ธ Memory manager โ PostgreSQL glue, context compaction
โ โโโ saul/ # โ๏ธ Config & CLI โ argument parsing, env vars
โ โโโ hank/ # ๐๏ธ Screen observer โ display hooks, event capture
โ โโโ the_rv/ # ๐ Browser sandbox โ automation, allow-list control
โ โโโ blue_sky/ # ๐ต Self-modification โ patch generator, safe apply
โ
โโโ ๐ ๏ธ scripts/
โ โโโ build.sh # Full build (release mode)
โ โโโ say-my-name.sh # Launch agent with shell UI
โ โโโ cook.sh # Inference wrapper โ ulimit enforcement
โ โโโ drive.sh # Browser automation entry point
โ
โโโ ๐ค models/ # Drop your .gguf files here (do NOT commit large files)
โ โโโ *.gguf
โ
โโโ ๐๏ธ sql/ # PostgreSQL schema โ long-term memory tables
โ
โโโ ๐ Cargo.toml # Rust workspace manifest
| Requirement | Version | Check |
|---|---|---|
| Rust toolchain | 1.70+ | rustc --version |
| Cargo | Latest stable | cargo --version |
| PostgreSQL | 14+ (for Mike memory) | psql --version |
| A GGUF model | 9B-class recommended | โ |
# 1. Clone the repository
git clone https://github.com/at264939-ctrl/Heisenberg.git
cd Heisenberg
# 2. Place your GGUF model
cp /path/to/your/model.gguf models/
# Recommended: Qwen3.5-9B-Uncensored-HauhauCS-Aggressive-Q4_K_M.gguf
# 3. Build (release mode, optimized)
./scripts/build.sh
# 4. Launch the agent
Heisenberg
# โ or โ
./scripts/say-my-name.sh chat
# 5. Check system status
Heisenberg status๐ก Tip: For large models (>2 GB), use Git LFS if you plan to track them in version control.
The secret weapon that makes 9B-class models behave like small models.
TurboQuant is Heisenberg's adaptive runtime strategy layer. It solves a fundamental problem: 9B parameter models have massive KV caches that expand with context length and easily exceed available RAM.
9B model weights (Q4_K_M) โ ~5.5 GB on disk
But RAM usage during inference = weights + KV cache + OS overhead
KV cache alone at context=2048 can push total usage well over 3 GB
Stage 1 โ SCAN Read GGUF header: layers, heads, hidden_dim, tokenizer
Stage 2 โ ESTIMATE Calculate KV cache size for requested context window
Stage 3 โ PLAN Aggregate: KV + mmap'd weights + tokenizer + OS overhead
Stage 4 โ ADAPT If predicted > 3 GB: downgrade KV quant and/or reduce context
Stage 5 โ CONFINE Launch via cook.sh with ulimit -v enforced at OS level
| Step | Action | Value |
|---|---|---|
| Request | User asks for generation | context = 2048 |
| Scan | Read GGUF metadata | layers, heads, hidden_dim extracted |
| Estimate | Compute KV cache | ~X MB for context=2048 |
| Plan | Total predicted usage | Exceeds 3 GB cap |
| Adapt | Select stronger KV quant | Q8_0 โ Q5_0 โ Q4_0 |
| Adapt | Reduce context if needed | 2048 โ 1024 |
| Launch | cook.sh --mem-mb 3072 |
ulimit enforced at OS level โ |
| Monitor | mike polls RSS live |
Mitigation triggered if needed |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SECURITY PRINCIPLES โ
โ โ
โ โ
100% local โ zero external API calls โ
โ โ
Zero telemetry โ no usage data ever leaves โ
โ โ
Bash scripts are auditable first-class citizens โ
โ โ
Browser automation is allow-listed by default โ
โ โ
ulimit enforced at OS level for all subprocesses โ
โ โ
FIFO-based IPC โ no shared memory exploits โ
โ โ
โ โ ๏ธ Review scripts/ before granting execution perms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Heisenberg enforces a 3 GB hard memory cap via sysinfo monitoring. When RAM pressure is detected, the orchestrator responds progressively:
Level 1 โ YELLOW โถ Shrink inference context + reduce KV cache size
Level 2 โ ORANGE โถ Lower concurrency โ single-thread fallback for heavy ops
Level 3 โ RED โถ Persist + compact long-term memory to PostgreSQL
Level 4 โ CRITICALโถ Drop nonessential buffers, disable expensive observers
Design philosophy: Stay responsive under pressure, never crash.
src/the_lab/
โโโ your_adaptor.rs # Implement the InferenceAdaptor trait
โโโ mod.rs # Register your adaptor
Preferred: FFI to llama-cpp. Fallback: isolated subprocess.
src/jesse/
โโโ your_action.rs # Define the action and its JSON schema
โโโ mod.rs # Register via FIFO IPC
ููุทุฉ ุงูููุฉ ุงูุญููููุฉ ูู Heisenberg ูู ูุฏุฑุฉ
TurboQuant Plannerุนูู ุชุดุบูู ู ูุฏูู 9B ู ุญูููุง ุจุฐุงูุฑุฉ 3 ุฌูุฌุงุจุงูุช ููุท.
ููู ูุดุชุบูุ
- ุงูู ุณุญ: ููุฑุฃ header ู ูู ุงูู GGUF ููุณุชุฎุฑุฌ ู ูุงุตูุงุช ุงููู ูุฐุฌ (ุนุฏุฏ ุงูุทุจูุงุชุ ุงูุฃุจุนุงุฏุ ุนุฏุฏ ุงูู heads)
- ุงูุชูุฏูุฑ: ูุญุณุจ ุญุฌู ุงูู KV cache ุงูู ุทููุจ ุจูุงุกู ุนูู ุทูู ุงูุณูุงู ุงูู ุทููุจ
- ุงูุชุฎุทูุท: ูุฌู ุน: KV cache + ุงูุฃูุฒุงู ุงูู ุญู ูุฉ + overhead ุงููุธุงู ูููุงุฑู ุจุงูุณูู
- ุงูุชูููู: ูู ุงูุชููุนุงุช ุชุฌุงูุฒุช 3GBุ ููููู ุฌูุฏุฉ ุงูู KV cache ุชููุงุฆููุง ุฃู ููููุต ูุงูุฐุฉ ุงูุณูุงู
- ุงูุนุฒู: ูุดุบูู ุงูู inference ุฏุงุฎู
cook.shู ุนulimit -vูู ูุน ุฃู ุชุฌุงูุฒ ูู ุงูุฐุงูุฑุฉ
ุงููุชูุฌุฉ: ุชูุฏุฑ ุชุดุบูู Qwen3.5-9B-Q4_K_M.gguf ุนูู ุฌูุงุฒ ุนุงุฏู ุจุฏูู ุณุญุงุจุ ุจุฏูู ุฎุตูุตูุฉ ู
ูุดููุฉุ ูุจุฃุฏุงุก ู
ุชุฏุฑุฌ ุจุฏููุง ู
ู ุงูุงูููุงุฑ.
If Heisenberg helped you cook something great โ consider buying me a coffee.
Building and maintaining a production-grade local AI agent takes serious time and effort. If this project saved you hours of work or sparked something useful in your own projects, your support means the world.
Every contribution โ big or small โ goes directly toward:
- ๐ฅ๏ธ Better hardware for testing on constrained environments
- ๐งช Experimenting with new GGUF models and quantization strategies
- ๐ Documentation, tutorials, and community support
- โก Continued active development of new features
Have questions, ideas, or want to collaborate? Reach out!
| Channel | Info |
|---|---|
| ๐ง Email | ibrahimtarek1245@gmail.com |
| ๐ฑ Phone / WhatsApp | +201030553763 |
| ๐ GitHub | at264939-ctrl/Heisenberg |
Feel free to open an Issue or Discussion directly on GitHub for bugs, feature requests, or general feedback.
MIT License โ Copyright (c) Ibrahim Tarek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...
See the full LICENSE file for details.