Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

172 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Typing SVG


Bun TypeScript PostgreSQL MCP License


┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                    ┃
┃   PERSISTENT SELF-IMPROVING MEMORY FOR MULTI-AGENT LLM SYSTEMS    ┃
┃                                                                    ┃
┃   3-lobe cognitive architecture  Β·  semantic decay & promotion     ┃
┃   boot injection  Β·  closed learning loop  Β·  fleet signal bus     ┃
┃                                                                    ┃
┃   The reasoning core. Every agent runs on top of this.             ┃
┃                                                                    ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

> WHAT IT DOES

Theorex gives AI agents persistent, self-improving memory that survives across sessions β€” not a chat log, but a live concept graph that decays, promotes, and injects itself into every new session.

WITHOUT  β†’  Each session starts blank. Same mistakes. No growth.
WITH     β†’  Agent boots with its 50 most relevant concepts pre-injected.
             Wins reinforce. Losses write trace_fix concepts.
             3am cron runs evolve-review. Session N+1 is smarter than N.

> ARCHITECTURE

╔══════════════════════════════════════════════════════════════════════╗
β•‘                    CLAUDE CODE SESSION                               β•‘
β•‘                                                                      β•‘
β•‘   [Hook Dispatcher]  ─────────────────────────────────────────►     β•‘
β•‘   PostToolUse Β· Stop          inject at start ◄── [SHARED_CONTEXT]  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
                       β”‚ emitSpan()                    β”‚ boot-inject
                       β–Ό                               β”‚
╔══════════════════════════════════╗                   β”‚
β•‘        FLASH LOBE                β•‘                   β”‚
β•‘  per-session ring buffer         β•‘                   β”‚
β•‘  flush on Stop β†’ Significance    β•‘                   β”‚
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•                   β”‚
                       β”‚ scored concept events         β”‚
                       β–Ό                               β”‚
╔══════════════════════════════════╗                   β”‚
β•‘     SIGNIFICANCE ENGINE          β•‘                   β”‚
β•‘                                  β•‘                   β”‚
β•‘  ConceptExtractor                β•‘                   β”‚
β•‘       β”‚                          β•‘                   β”‚
β•‘  ImportanceGate  (binary)        β•‘                   β”‚
β•‘       β”‚                          β•‘                   β”‚
β•‘  FrequencyAmplifier  (log-norm)  β•‘                   β”‚
β•‘       β”‚                          β•‘                   β”‚
β•‘  CompositeSignal  (0.0 β†’ 1.0)   β•‘                   β”‚
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•                   β”‚
                       β”‚                               β”‚
                       β–Ό                               β”‚
╔══════════════════════════════════════════════════════╧══════════════╗
β•‘                   CONCEPT WEB  (Axon)  Β·  PostgreSQL                β•‘
β•‘                                                                      β•‘
β•‘  CrossPollinator  Β·  activation spreads through edge weights         β•‘
β•‘  DecayRunner      Β·  exponential decay on idle nodes                 β•‘
β•‘  TierClassifier   Β·  ACTIVE (β‰₯0.6)  Β·  MILD (β‰₯0.3)  Β·  LESS        β•‘
β•‘                                                                      β•‘
β•‘   concepts  Β·  agent_spans  Β·  flash_events  Β·  outcomes            β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•€β•β•β•β•β•β•β•β•β•
                       β”‚                  β”‚                  β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
              β”‚ SHORT-TERM    β”‚  β”‚  LONG-TERM    β”‚  β”‚   MCP SERVER  β”‚
              β”‚ BM25 + vector β”‚  β”‚  axon.json    β”‚  β”‚   :18800      β”‚
              β”‚ 14-day window β”‚  β”‚  moment nodes β”‚  β”‚   JSON-RPC2.0 β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

> MEMORY PIPELINE

Claude Code session  (tool call)
  β”‚
  β”‚  SpanStore.emitSpan()  Β·  TokenJuice  (~60–80% compression)
  β–Ό
agent_spans  ──  PostgreSQL  ──  FTS5-indexed  ──  searchable by session
  β”‚
  β”‚  [3am OC cron]  theorex evolve-review --agent all
  β–Ό
concepts  ──  enrich_bodies  ──  scan  ──  promote
  β”‚
  β”‚  theorex boot-inject
  β”‚  Postgres β†’ semantic grouping β†’ palace structure
  β–Ό
~/.openclaw/workspace/theorex/SHARED_CONTEXT.md
  β”‚
  └──►  injected at every new session start

Palace structure at inject time:

Wing Tier Score
🟒 Wins ACTIVE β‰₯ 0.6
πŸ”΄ Losses ACTIVE β‰₯ 0.6
🟑 Identity MILD β‰₯ 0.3

> THREE LOBES

⚑ Flash Lobe β€” per-session ring buffer
Purpose   β†’  presence, not retrieval. "What happened this session?"
Writes    β†’  ~/.theorex/flash/{session-id}.jsonl
Trigger   β†’  PostToolUse + Stop hooks via Claude Code
Flush     β†’  on session Stop β†’ Significance Engine
πŸ” Short-Term Lobe β€” 14-day rolling window
Search    β†’  BM25 + vector hybrid  (RRF fusion)
Window    β†’  14-day rolling JSONL log
Promotion β†’  qualifying concepts graduate β†’ Long-Term Lobe
BM25      β†’  Postgres FTS5 tsvector  (auto-populated generated column)
Vector    β†’  nomic-embed-text-v1.5 via LM Studio
🧬 Long-Term Lobe β€” permanent crystallised knowledge
Storage   β†’  axon.json  (concept graph with edge weights)
Nodes     β†’  Moment nodes β€” permanent episodic anchors
Decay     β†’  exponential, halflife 14 days (configurable)
Promotion β†’  composite score β‰₯ 0.5
Tiers     β†’  ACTIVE β‰₯ 0.6  |  MILD β‰₯ 0.3  |  LESS < 0.3

> LEARNING LOOP

theorex dispatch(task, {outcome_id})
  β”‚
  β”œβ”€β”€  LM_INFERENCE_START  (trace_id = preGeneratedUUID)
  β”‚
  β”œβ”€β”€  qwen-abliterated :8000  β†’  success / failure
  β”‚
  β”œβ”€β”€  LM_INFERENCE_END  β†’  EventBus  β†’  TraceRecord written
  β”‚
  β”œβ”€β”€  patchOutcomeTraceId(outcome_id, trace_id)
  β”‚
  β”‚    [3am OC cron]  theorex evolve-review --agent all
  β”œβ”€β”€  reviewOutcomes()  +  refineFromReport()
  β”œβ”€β”€  reviewAllFailures()  β†’  trace_fix concepts written
  β”‚
  β”‚    [OC cron]  theorex promote  +  boot-inject
  └──  trace_fix in SHARED_CONTEXT.md  Β·  half-life = 7 days

Router priority chain:

1  Role registry      model_preference wins if query type matches
2  EnergyDispatch     pmset battery check  ·  large→medium below 20%
3  ConfidenceMatrix   0.6 Γ— success_rate  +  0.4 Γ— (1 βˆ’ latency)
4  HeuristicRouter    code Β· math Β· retrieval Β· synthesis Β· creative Β· safety Β· general

> FLEET-GE SIGNAL SCANNER

Gene registry + GEP directives
bun run src/ge/signal-scanner.ts --source watchdog
bun run src/ge/signal-scanner.ts --source pm2
bun run src/ge/signal-scanner.ts --source theorex
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Gene                                                β”‚ Priority β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  gene_divergence_win_rate_anomaly                    β”‚  HIGH    β”‚
β”‚  gene_horizon_outcome_tracking                       β”‚  HIGH    β”‚
β”‚  gene_singularity_position_cap                       β”‚ CRITICAL β”‚
β”‚  gene_hades_turboquant_health_monitor                β”‚  MEDIUM  β”‚
β”‚  gene_hades_watchdog_cooldown_race                   β”‚  HIGH βœ“  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Every GEP directive written to evolution_events with full audit trail.


> MCP SERVER

JSON-RPC 2.0 on :18800 β€” full axon read/write/search for any agent or external tool.

theorex mcp-start --port 18800 --agent main
Method Description
status agent name Β· concept count Β· top ACTIVE
search FTS5 + vector hybrid search
write extract concepts + write to axon
search_spans FTS5 span search across sessions
boot-inject regenerate SHARED_CONTEXT.md
retrieve_outcomes read trade outcomes
write_trade_outcome shadow a trade outcome
write_learning write structured lesson
get_learnings query lessons by agent + context

> CRON SCHEDULE

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  OC ID     β”‚  Schedule        β”‚  Job                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  c6bd399a  β”‚  0 */4 * * *     β”‚  fleet-ge-signal-scan                β”‚
β”‚  10fd0f7d  β”‚  0 3   * * *     β”‚  theorex evolve-review (all agents)  β”‚
β”‚  4f7a8761  β”‚  */5 * * * *     β”‚  theorex-health-check                β”‚
β”‚  66ddb18c  β”‚  0 6   * * *     β”‚  monitor-partitions (daily)          β”‚
β”‚  5b65a0c7  β”‚  0 2   * * 0     β”‚  security-sweep (weekly)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

> QUICKSTART

git clone https://github.com/LORD-ZYTHOZ/Theorex
cd Theorex && bun install

theorex write --agent main "TTL invalidation prevents cache stampedes"
theorex search "cache invalidation" --agent main
theorex learn --agent nova --event decision \
  --context "direct LAN vs relay" \
  --pattern "direct LAN more reliable" \
  --outcome positive
theorex evolve-review --agent all
theorex boot-inject --top 50 --depth summary
theorex mcp-start --port 18800 --agent main

> STACK

Runtime        Bun 1.3+
Storage        PostgreSQL  ──  concepts Β· agent_spans Β· flash_events Β· outcomes
Semantic       nomic-embed-text-v1.5  via LM Studio :1234
Full-text      Postgres FTS5 + ts_rank
Compression    TokenJuice  ──  ~60–80% token reduction on stored spans
Vector quant   TurboQuant (ICLR 2026)  ──  4320 compressed embeddings
Large LLM      Qwen API  ──  Qwen Max / Qwen3.5-122B-A10B
Background     qwen-abliterated :8000  ──  fire-and-forget inference
Protocol       JSON-RPC 2.0 MCP :18800
Scheduling     OpenClaw cron (source of truth)  Β·  PM2 (theorex-scan only)

⚠️ TURBOQUANT_SEED = 42 is baked into all 4320 stored TurboCode vectors. Changing it invalidates ALL stored codes and requires a full backfill.



  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Memory that earns its keep. Built in Sydney.                β”‚
  β”‚  Self-improving since day one.                               β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

MIT License Β· Bun Β· TypeScript Β· PostgreSQL


About

🧠 3-lobe cognitive memory for AI agents β€” concept web with semantic decay, boot injection, closed learning loop. The reasoning core.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages