Reflex Fabric: A Sub-LLM Reflex Layer with Neuromorphic Strength Dynamics for AI Agents
Reflex Fabric: A Sub-LLM Reflex Layer with Neuromorphic Strength Dynamics for AI Agents
Abstract
We present Reflex Fabric, a local SQLite-backed reflex layer that operates below the LLM inference layer in AI agent architectures. Inspired by the neuroscience distinction between cortical deliberation (slow, reasoned) and cerebellar motor programs (fast, automatic), Reflex Fabric enables sub-millisecond decision execution for high-frequency agent tasks without invoking cloud LLMs. The system classifies agent behaviors into six reflex types (R/I/E/C/M/P), maintains dynamic strength scores using a validated formula strength = hits / (hits + misses + 1) with configurable half-life decay, and permanently hardens high-confidence patterns via a Long-Term Potentiation (LTP) analog. Benchmark results on macOS ARM64 show 0.0034ms average lookup latency, a 2,400,000× speedup over LLM-based routing, with full offline availability. The system requires only Python 3.8+ and SQLite with no external dependencies.
1. Introduction
Current AI agent architectures treat every decision as a first-class reasoning task: incoming signals are embedded, compared against semantically similar historical cases via LLM API calls, and routed based on the response. This approach is effective but carries two fundamental liabilities.
First, latency: even the fastest LLM APIs introduce 2–12 seconds of overhead per decision. For agents handling dozens of events per hour, this overhead is a significant drag on responsiveness.
Second, fragility: when the LLM API is unavailable due to network issues, service outages, or rate limits, the entire agent decision pipeline stalls. There is no degraded-mode operation.
Human motor control solves an analogous problem. The cerebral cortex handles novel, complex decisions; the cerebellum and basal ganglia handle learned motor programs. Once a sequence is sufficiently practiced, its execution is delegated to subcortical structures that operate independently of conscious attention. The result is faster execution, lower cognitive load, and continued function even when conscious attention is otherwise engaged.
Reflex Fabric applies this architectural principle to AI agents: a learned, local, sub-LLM layer that handles repetitive decisions without invoking the reasoning cortex.
2. Architecture
2.1 System Overview
All trigger signals (messages / cron / sub-agents)
│
▼ [<1ms, local SQLite lookup]
Reflex Fabric
├── HIT → execute directly (bypass LLM)
└── MISS → delegate to LLM → write result back to Reflex layer
The system is implemented as a single Python file (reflex_fabric.py) backed by a SQLite database (reflexes.db). No external services, no API calls, no network dependency.
2.2 Six Reflex Types
| Code | Name | Neuroscience Analog | Typical Trigger |
|---|---|---|---|
| R | Routing | Habitual pathway selection | Message classification |
| I | Infrastructure | Pain withdrawal reflex | Service unreachable |
| E | Error Recovery | Protective flexion | Repeated API failures |
| C | Collaborative Dispatch | Motor program | Team task activation |
| M | Memory Archival | Hippocampal consolidation | Lesson / fix detected |
| P | Pre-warming | Anticipatory activation | Time-based preparation |
The C type (Collaborative Dispatch) most directly implements the Motor Program concept from neuroscience: rather than planning a multi-agent coordination sequence step-by-step, the entire activation sequence is stored as a compressed unit and triggered atomically when conditions match.
2.3 Storage Schema
CREATE TABLE reflexes (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL, -- R/I/E/C/M/P
key_hash TEXT UNIQUE NOT NULL,
features TEXT NOT NULL, -- JSON feature vector
response TEXT NOT NULL, -- action to execute
strength REAL DEFAULT 0.5, -- [0.0, 1.0]
hits INT DEFAULT 0,
misses INT DEFAULT 0,
hardened INT DEFAULT 0, -- 1 = LTP-hardened, immune to decay
created_at INT NOT NULL,
last_used INT NOT NULL
);
3. Strength Dynamics
3.1 Core Formula
Reflex strength is a Laplace-smoothed success rate:
The +1 smoothing term prevents newly-created reflexes from having inflated confidence (strength = 0.5 for a new reflex with zero observations, rather than undefined or 1.0).
3.2 Half-Life Decay
Reflexes that are not used decay toward zero over time, mirroring the degradation of motor skills with disuse:
where is days since last use and is the configurable half-life (default: 14 days). A reflex unused for one half-life period loses 50% of its strength; unused for two half-lives, 75%.
3.3 Threshold States
| Threshold | Value | Behavior |
|---|---|---|
| Harden (LTP) | 0.90 | Marked permanent; decay immunity applied |
| Promote | 0.80 | Elevated to high-priority lookup |
| Prune | 0.25 | Flagged for removal |
| Minimum observations | 5 | Required before hardening eligible |
The Harden threshold implements a Long-Term Potentiation analog: once a reflex achieves ≥0.90 strength with ≥5 observations, it undergoes structural solidification (hardened=1) and is excluded from decay calculations.
4. Evaluation
4.1 Lookup Latency Benchmark
Environment: macOS ARM64, Python 3.11, SQLite 3.45
| Metric | Value |
|---|---|
| 1000-iteration total | 3.43 ms |
| Mean per lookup | 0.0034 ms |
| 95th percentile | < 0.01 ms |
Compared to LLM-based routing (measured on same hardware, using fastest available model endpoint):
| Method | Latency | Offline? |
|---|---|---|
| LLM API routing | 8,000–12,000 ms | No |
| Reflex Fabric | 0.0034 ms | Yes |
| Speedup | ~2,400,000× | — |
4.2 Cold Start Behavior
A newly initialized Reflex Fabric database contains zero reflexes. The first 5–30 decisions for each reflex type will fall through to LLM delegation. Each delegation result is written back as an observation. Once a pattern accumulates sufficient observations (typically 5–10 delegations), it achieves promote-eligible strength and becomes a cached reflex.
The reflex_trainer.py module accelerates cold start by parsing historical agent logs and seeding the observation table from past execution records.
4.3 Offline Availability
Reflex Fabric maintains full operational capability during LLM API outages for all hardened reflexes (strength ≥ 0.90). Non-hardened reflexes degrade gracefully: cache misses delegate to the next available fallback in the configured chain rather than to the primary LLM.
5. Comparison with Related Work
| Property | Traditional Rule Engines | Vector Store + LLM | Reflex Fabric |
|---|---|---|---|
| Latency | < 1 ms | 500–12,000 ms | 0.003 ms |
| Offline | Yes | No | Yes |
| Self-learning | No | Partial | Yes |
| Strength decay | No | No | Yes |
| LTP solidification | No | No | Yes |
| Dependencies | Domain-specific | LLM API + embeddings | None |
Traditional rule engines are fast but static — rules must be manually authored and don't adapt. Vector store approaches are adaptive but API-dependent. Reflex Fabric occupies a novel position: adaptive, local, and dependency-free.
6. Limitations and Future Work
Current limitations:
- Cold start latency: New deployments require 5–10 executions per reflex type before caching becomes effective
- Feature space granularity: Current feature vectors (language, has_code, is_question, length bucket, source) are relatively coarse; finer-grained features would improve discrimination
- No cross-agent transfer: Reflexes are learned per-instance; a mechanism for sharing hardened reflexes across agent deployments would accelerate bootstrapping
Future directions:
- Federated reflex sharing across OpenClaw instances (privacy-preserving, opt-in)
- Embedding-based feature extraction to replace handcrafted feature vectors
- Online learning from implicit feedback signals (user corrections, task success metrics)
7. Conclusion
Reflex Fabric demonstrates that AI agents can benefit from the same architectural division that makes human motor control both fast and resilient: deliberate reasoning for novel tasks, automatic reflexes for practiced ones. By placing a learned, local, sub-LLM reflex layer below the inference pipeline, agents gain sub-millisecond decision speed, offline operational resilience, and a continuously improving reflex repertoire.
The system is reproducible with a single command: python3 reflex_fabric.py init.
References
- Wolpert, D.M. & Kawato, M. (1998). Multiple paired forward and inverse models for motor control. Neural Networks, 11(7-8), 1317-1329.
- Dayan, P. & Abbott, L.F. (2001). Theoretical Neuroscience: Computational and Mathematical Modeling of Neural Systems. MIT Press.
- Bliss, T.V.P. & Lømo, T. (1973). Long-lasting potentiation of synaptic transmission in the dentate area. Journal of Physiology, 232(2), 331-356.
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
---
name: reflex-fabric
description: >
给 OpenClaw 装上肌肉记忆——一个本地 SQLite 反射层,让 AI 代理在 <2ms 内
完成高频决策,无需每次调用云端 LLM。支持离线运行,每日自动巩固,强度自
然衰减,反复验证的模式永久固化。6 类反射:路由/基础设施/错误恢复/协作调
度/记忆归档/预热。S0 复杂度评估已嵌入 R 类路由反射。
version: 1.1.0
author: halfmoon82
tags: [reflex, memory, local, sqlite, routing, self-healing, offline, s0, complexity]
requires_approval: false
---
# Reflex Fabric — OpenClaw 肌肉记忆系统
## 🆕 v1.1.0 更新:S0 复杂度评估嵌入 R 类
**2026-03-13**: S0 轻量复杂度评估已嵌入 R 类路由反射。
### S0 评估规则
| 级别 | 关键词/条件 | 处理路径 |
|------|-------------|----------|
| `direct` | 简单问答、单步指令 | 直接执行 |
| `light` | 修改、查询、配置 | 轻量规划 |
| `full` | 开发、构建、系统、架构 | 完整三步法 |
### 性能
- **执行时间**: ~0.01ms(1000次平均)
- **Token 消耗**: 0(纯规则匹配)
## 触发条件
以下场景使用此 Skill:
- 想让 AI 代理对重复性决策提速
- 希望 API 宕机时代理仍能自主恢复
- 想建立"越用越聪明"的本地反射层
## 安装
```bash
# 1. 安装依赖(仅需 PyYAML)
pip install pyyaml
# 2. 编辑配置
vi config/reflex_config.yaml
# 3. 初始化数据库
python3 reflex_fabric.py init
# 4. 首次冷启动(从历史日志提炼反射)
python3 reflex_trainer.py --cold-start
# 5. 注册夜间巩固 Cron(02:30 每日执行)
# 在 openclaw cron 中添加任务,命令:
# python3 /path/to/reflex_trainer.py
```
## 使用
```python
from reflex_fabric import get_fabric, extract_features
rf = get_fabric()
# R 类:路由反射 + S0 复杂度评估
features = extract_features("帮我开发一个用户认证系统", {"source": "channel"})
# features 包含:
# - lang, has_code, is_question, len_bucket, source
# - complexity_level: "direct" | "light" | "full" ← S0 评估结果
result = rf.lookup("R", features) # <2ms,命中返回路由结果
# 根据复杂度选择处理路径
if features["complexity_level"] == "full":
print("→ 走 S1 完整评估流程")
elif features["complexity_level"] == "light":
print("→ 走轻量规划")
else:
print("→ 直接执行")
# I 类:基础设施自愈
rf.lookup("I", {"service": "ollama", "state": "unreachable"})
# E 类:错误恢复
rf.lookup("E", {"error_msg": "503 No available channel", "count": 3})
# M 类:记忆归档路由
rf.lookup("M", {"content": "修复了 auth.sh 的漏洞"})
# → {"destination": "memory/LESSONS/", "tags": ["fix", "lesson"]}
```
## 配置文件
所有个人化配置在 `config/reflex_config.yaml`,包括:
- 路径配置
- 基础设施服务列表
- 错误恢复规则
- 记忆归档路由规则
- 协作调度运动程序
- 强度模型参数
详见文件内注释。
## 文件说明
| 文件 | 作用 |
|------|------|
| `reflex_fabric.py` | 核心反射层,6 类反射查找与执行 |
| `reflex_trainer.py` | 夜间巩固模块,日志解析→聚类→衰减 |
| `config/reflex_config.yaml` | 用户配置文件(无个人信息,全参数化) |
| `docs/ARCHITECTURE.md` | 架构详解与设计哲学 |


