Minimal, verifiable implementation of persistent long-term memory for AI agents
Project description
๐ง Cognitive Kernel
๐ฐ๐ท ํ๊ตญ์ด | ๐บ๐ธ English
Minimal, verifiable implementation of persistent long-term memory for AI agents.
๊ธฐ์ต์ ์๊ฐ ์ธ์ฝ๋ฉ(Temporal Encoding), ์ค์๋ ๋ญํน(Importance Ranking), ์์ฌ๊ฒฐ์ ๋ฐ์(Decision Impact)์ ๊ฒฐํฉํ ๋ชจ๋ํ ์ธ์ง ํ๋ ์์ํฌ.
๐ฏ ์ ์ง๊ธ ํ์ํ๊ฐ?
ํ๋ LLM ์์ด์ ํธ์๋ ๊ตฌ์กฐํ๋ ์ฅ๊ธฐ ๊ธฐ์ต๊ณผ ์คํ ์ ์ด ๊ธฐ๋ฅ์ด ๋ถ์กฑํฉ๋๋ค.
Cognitive Kernel์ ์ด ๊ฐญ์ ๋ฉ์ฐ๊ธฐ ์ํ drop-in ์ธ์ง ์๋ธ์์คํ ์ ์ ๊ณตํฉ๋๋ค.
โ ๏ธ ์ฐ๊ตฌ ๋ฐ ์คํ ๋๊ตฌ์
๋๋ค.
์ค์ ๋์ ์์ ํ ๋ชจ๋ธ์ด ์๋๋ฉฐ, ์์ ์ง๋จ ๋๊ตฌ๊ฐ ์๋๋๋ค.
๐ This project does not claim biological equivalence to human memory.
It provides a computer-science definition of long-term memory:
persistent, structured, recallable, and decision-impacting.
โญ ํต์ฌ ๊ธฐ๋ฅ: 3์ค๋ก ์์ํ๋ ์ฅ๊ธฐ ๊ธฐ์ต
from cognitive_kernel import CognitiveKernel
with CognitiveKernel("my_brain") as kernel:
kernel.remember("meeting", {"topic": "project"}, importance=0.9)
memories = kernel.recall(k=5) # PageRank ๊ธฐ๋ฐ ์ค์๋ ํ์
decision = kernel.decide(["rest", "work"]) # Softmax ์์ฌ๊ฒฐ์
# ์๋ ์ ์ฅ๋จ โ ํ๋ก์ธ์ค ์ข
๋ฃ ํ์๋ ๊ธฐ์ต ์ ์ง
โ ์ด๊ฒ๋ง์ผ๋ก:
| ๊ธฐ๋ฅ | ์ค๋ช | ์๊ณ ๋ฆฌ์ฆ |
|---|---|---|
remember() |
๊ธฐ์ต ์ ์ฅ (์ฅ๊ธฐ ๊ธฐ์ต) | ์๊ฐ์ถ ์ ์ฅ + ์๋ ์์์ฑ |
recall() |
์ค์ํ ๊ธฐ์ต ํ์ | Google PageRank |
decide() |
์์ฌ๊ฒฐ์ | Softmax Utility |
โ ์ฅ๊ธฐ ๊ธฐ์ต ์์ธ ์ค๋ช
๐ ํต์ฌ ์์
1. ๊ธฐ์ต ์ค์๋ (MemoryRank)
Personalized PageRank ์๊ณ ๋ฆฌ์ฆ:
$$ \mathbf{r}^{(t+1)} = \alpha \cdot M \cdot \mathbf{r}^{(t)} + (1-\alpha) \cdot \mathbf{v} $$
- $\mathbf{r}$: ๊ธฐ์ต ์ค์๋ ๋ฒกํฐ
- $M$: ๊ธฐ์ต ์ ์ด ํ๋ ฌ (์ด ์ ๊ทํ)
- $\alpha$: ๊ฐ์ ๊ณ์ (๊ธฐ๋ณธ๊ฐ: 0.85)
- $\mathbf{v}$: ๊ฐ์ธํ ๋ฒกํฐ (recency, emotion, frequency ๊ฐ์ค์น)
2. ์๊ฐ ๊ฐ์ (Panorama)
์ง์ ๊ฐ์ ํจ์:
$$ S(t) = S_0 \cdot e^{-\lambda \cdot \Delta t}, \quad \lambda = \frac{\ln 2}{t_{1/2}} $$
- $S(t)$: ์๊ฐ $t$์์์ ์ค์๋
- $t_{1/2}$: ๋ฐ๊ฐ๊ธฐ (๊ธฐ๋ณธ๊ฐ: 3600์ด = 1์๊ฐ)
3. ์์ฌ๊ฒฐ์ (PFC)
Softmax ์ ํ ํ๋ฅ :
$$ P(a_i) = \frac{e^{U(a_i) / T}}{\sum_j e^{U(a_j) / T}} $$
- $U(a)$: ํ๋ $a$์ ํจ์ฉ = ๊ธฐ๋๋ณด์ - ๋น์ฉ - ์ํ
- $T$: ์จ๋ (ํ์ vs ์ฐฉ์ทจ ๊ท ํ)
๐พ ์ฅ๊ธฐ ๊ธฐ์ต์ด๋?
์ปดํจํฐ ๊ณตํ์ ์ ์
์์์ฑ(Persistence): ํ๋ก์ธ์ค ์ข ๋ฃ ํ์๋ ๋ฐ์ดํฐ๊ฐ ์ ์ง๋จ
Cognitive Kernel์ ๊ตฌํ
์ธ์
A (ํ๋ก์ธ์ค 1) ์ธ์
B (ํ๋ก์ธ์ค 2)
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
kernel.remember(...) โ ํ์ผ ์ ์ฅ
โ โ
ํ๋ก์ธ์ค ์ข
๋ฃ CognitiveKernel("my_brain")
โ
์๋ ๋ก๋ โ ๊ธฐ์ต ๋ณต๊ตฌ!
์ ์ฅ ๊ตฌ์กฐ
.cognitive_kernel/my_brain/
โโโ panorama.json # ์๊ฐ์ถ ์ด๋ฒคํธ (๊ธฐ์ต ๋ฐ์ดํฐ)
โโโ memoryrank.json # ์ค์๋ ๊ทธ๋ํ
โโโ edges.json # ๊ธฐ์ต ์ฐ๊ฒฐ ๊ด๊ณ
โโโ q_values.json # ์ต๊ด ํ์ต (Q-Learning)
โโโ meta.json # ์ธ์
๋ฉํ๋ฐ์ดํฐ
โ ์ฅ๊ธฐ ๊ธฐ์ต ๊ธฐ์ ๋ฌธ์
๐งช ํ ์คํธ ๊ฒฐ๊ณผ
์ฅ๊ธฐ ๊ธฐ์ต ์ฆ๋ช
# ํ
์คํธ ์คํ
cd /Users/jazzin/Desktop/00_BRAIN/Cognitive_Kernel
python3 cognitive_kernel.py
๊ฒฐ๊ณผ:
๐ฆ Session: test_session
๐ ๊ธฐ์ต ์ ์ฅ... 3๊ฐ
๐ ๊ธฐ์ต ํ์ (Top 3): idea(0.349), conversation(0.333), meeting(0.318)
๐ฏ ์์ฌ๊ฒฐ์ : rest (ํจ์ฉ: 0.250)
โ
์๋ ์ ์ฅ ์๋ฃ!
๐ ์ธ์
๋ณต๊ตฌ ํ
์คํธ...
๋ณต๊ตฌ๋ ์ด๋ฒคํธ: 3๊ฐ โ ํ๋ก์ธ์ค ์ข
๋ฃ ํ์๋ ์ ์ง๋จ!
7๊ฐ ์์ง ํตํฉ ์๋ฎฌ๋ ์ด์
| ์๋๋ฆฌ์ค | Stress Max | Hyperarousal | Efficiency | Alerts |
|---|---|---|---|---|
| Normal Day | 0.44 | 1ํ | 0.71 | 1๊ฐ |
| PTSD | 0.80 | 3ํ | 0.61 | 5๊ฐ |
๐ฆ ์ ์ฒด ๋ชจ๋ ๊ตฌ์ฑ
| ๋ชจ๋ | ์ญํ | ํต์ฌ ์๊ณ ๋ฆฌ์ฆ | ์์์ฑ |
|---|---|---|---|
| MemoryRank | ๊ธฐ์ต ์ค์๋ | PageRank | โ JSON/NPZ |
| Panorama | ์๊ฐ์ถ ๊ธฐ์ต | Exponential Decay | โ JSON/SQLite |
| PFC | ์์ฌ๊ฒฐ์ | Softmax Utility | |
| BasalGanglia | ์ต๊ด ํ์ต | TD-Learning | โ Q-values |
| Amygdala | ๊ฐ์ /์ํ | Rescorla-Wagner | |
| Hypothalamus | ์๋์ง/์คํธ๋ ์ค | HPA Dynamics | |
| Thalamus | ์ ๋ ฅ ํํฐ๋ง | Salience Gating |
๐ง ํ์ฉ ๋ฐฉํฅ
๐ฌ ์ฐ๊ตฌ์ฉ (Research)
- ์ธ์ง ๋ชจ๋ธ ์๋ฎฌ๋ ์ด์
- ๊ธฐ์ต-๊ฐ์ -์์ฌ๊ฒฐ์ ๋์ญํ ์ฐ๊ตฌ
- ๋ ์งํ ๋ฉ์ปค๋์ฆ ํ๊ตฌ (PTSD, ADHD ๋ฑ)
๐ญ ์ฐ์ ์ฉ (Industrial)
- AI ์์ด์ ํธ ๋ฉ๋ชจ๋ฆฌ ์๋ธ์์คํ
- RAG ๊ฒ์ ๊ฒฐ๊ณผ ํํฐ๋ง/๋ญํน
- LangChain/LlamaIndex ํตํฉ
๐ผ ์์ ์ฉ (Commercial)
- ๊ฐ์ธํ๋ AI ๋น์์ ๊ธฐ์ต ๋ ์ด์ด
- ๊ฒ์ NPC ํ๋ ์์ง
- ๊ต์ก์ฉ ์๋ฎฌ๋ ์ดํฐ
๐ ์ค๊ณ ์ฒ ํ
Edge AI First
โ
๊ฒฝ๋ ์๊ณ ๋ฆฌ์ฆ (NumPy ์ธ ํ์ ์์กด์ฑ ์์)
โ
๋ชจ๋๋ณ ๋
๋ฆฝ ์คํ ๊ฐ๋ฅ
โ
ํด๋ผ์ฐ๋ ์์กด์ฑ ์์
โ
ํ์ฅ ๊ฐ๋ฅํ ๊ตฌ์กฐ
๋ชจ๋ ์กฐํฉ
# 1๊ฐ๋ง ์ฌ์ฉ
from memoryrank import MemoryRankEngine
# ์กฐํฉํด์ ์ฌ์ฉ
from cognitive_kernel import CognitiveKernel
# ์ง์ ํ์ฅ
class MyBrain(CognitiveKernel):
def custom_recall(self): ...
๐ Quick Start
git clone https://github.com/qquartsco-svg/Cognitive_Kernel.git
cd Cognitive_Kernel
pip install numpy
# ์ฅ๊ธฐ ๊ธฐ์ต ํ
์คํธ
python3 cognitive_kernel.py
# 7๊ฐ ์์ง ํตํฉ ์๋ฎฌ๋ ์ด์
python3 examples/full_brain_simulation.py
# 4๊ฐ ํต์ฌ ํ์ดํ๋ผ์ธ
python3 examples/integrated_pipeline.py
๐ ๋ฌธ์
| ๋ฌธ์ | ์ค๋ช |
|---|---|
| LONG_TERM_MEMORY.md | ์ฅ๊ธฐ ๊ธฐ์ต ๊ธฐ์ ๋ฌธ์ |
| API_REFERENCE.md | API ๋ ํผ๋ฐ์ค |
| ARCHITECTURE.md | ์ด๋ก ์ ๊ธฐ๋ฐ, ์์, ์ฐธ๊ณ ๋ฌธํ |
| TEST_RESULTS.md | ์ ์ฒด ํ ์คํธ ๊ฒฐ๊ณผ |
| VERIFICATION_STATUS.md | ์ด๋ก โ ์ฝ๋ ์ผ์น ๊ฒ์ฆ |
๐ PHAM Blockchain Signature
๋ชจ๋ ํต์ฌ ๋ชจ๋์ PHAM (Proof of Honest Authorship & Merit) ๋ธ๋ก์ฒด์ธ์ผ๋ก ์๋ช :
| ๋ชจ๋ | ์๋ช | ๋ฑ๊ธ |
|---|---|---|
| cognitive_kernel.py | โ | A_HIGH (0.9998) |
| MemoryRank | โ | ์๋ช |
| Panorama | โ | ์๋ช |
| PFC | โ | ์๋ช |
๐ License
MIT License โ ์์ ๋กญ๊ฒ ์ฌ์ฉ, ์์ , ๋ฐฐํฌ ๊ฐ๋ฅ
๐ค Author
GNJz (Qquarts) โ @qquartsco-svg
English Version
๐ฐ๐ท ํ๊ตญ์ด | ๐บ๐ธ English
Minimal, verifiable implementation of persistent long-term memory for AI agents.
A modular cognitive framework combining Temporal Encoding, Importance Ranking, and Decision Impact.
๐ฏ Why Now?
Modern LLM agents lack structured long-term memory and executive control.
Cognitive Kernel provides drop-in cognitive subsystems to address this gap.
โ ๏ธ Research and experimentation tool.
NOT a complete model of the brain, nor a clinical diagnostic tool.
๐ This project does not claim biological equivalence to human memory.
It provides a computer-science definition of long-term memory:
persistent, structured, recallable, and decision-impacting.
โญ Core Feature: Long-term Memory in 3 Lines
from cognitive_kernel import CognitiveKernel
with CognitiveKernel("my_brain") as kernel:
kernel.remember("meeting", {"topic": "project"}, importance=0.9)
memories = kernel.recall(k=5) # PageRank-based importance recall
decision = kernel.decide(["rest", "work"]) # Softmax decision-making
# Auto-saved โ Memory persists after process termination
โ This gives you:
| Feature | Description | Algorithm |
|---|---|---|
remember() |
Store memory (long-term) | Timeline storage + auto-persistence |
recall() |
Recall important memories | Google PageRank |
decide() |
Decision making | Softmax Utility |
๐ Core Formulas
1. Memory Importance (MemoryRank)
Personalized PageRank algorithm:
$$ \mathbf{r}^{(t+1)} = \alpha \cdot M \cdot \mathbf{r}^{(t)} + (1-\alpha) \cdot \mathbf{v} $$
- $\mathbf{r}$: Memory importance vector
- $M$: Memory transition matrix (column-normalized)
- $\alpha$: Damping factor (default: 0.85)
- $\mathbf{v}$: Personalization vector (recency, emotion, frequency weights)
2. Temporal Decay (Panorama)
Exponential decay function:
$$ S(t) = S_0 \cdot e^{-\lambda \cdot \Delta t}, \quad \lambda = \frac{\ln 2}{t_{1/2}} $$
- $S(t)$: Importance at time $t$
- $t_{1/2}$: Half-life (default: 3600s = 1 hour)
3. Decision Making (PFC)
Softmax selection probability:
$$ P(a_i) = \frac{e^{U(a_i) / T}}{\sum_j e^{U(a_j) / T}} $$
- $U(a)$: Utility of action $a$ = expected reward - cost - risk
- $T$: Temperature (exploration vs exploitation balance)
๐พ What is Long-term Memory?
Computer Science Definition
Persistence: Data survives process termination
Cognitive Kernel Implementation
Session A (Process 1) Session B (Process 2)
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
kernel.remember(...) โ File saved
โ โ
Process terminates CognitiveKernel("my_brain")
โ
Auto-load โ Memory recovered!
Storage Structure
.cognitive_kernel/my_brain/
โโโ panorama.json # Timeline events (memory data)
โโโ memoryrank.json # Importance graph
โโโ edges.json # Memory connections
โโโ q_values.json # Habit learning (Q-Learning)
โโโ meta.json # Session metadata
โ Long-term Memory Technical Docs
๐งช Test Results
Long-term Memory Proof
# Run test
cd /Users/jazzin/Desktop/00_BRAIN/Cognitive_Kernel
python3 cognitive_kernel.py
Result:
๐ฆ Session: test_session
๐ Memories saved: 3
๐ Recall (Top 3): idea(0.349), conversation(0.333), meeting(0.318)
๐ฏ Decision: rest (utility: 0.250)
โ
Auto-saved!
๐ Session recovery test...
Recovered events: 3 โ Persists after process termination!
7-Engine Integration Simulation
| Scenario | Stress Max | Hyperarousal | Efficiency | Alerts |
|---|---|---|---|---|
| Normal Day | 0.44 | 1 | 0.71 | 1 |
| PTSD | 0.80 | 3 | 0.61 | 5 |
๐ฆ All Modules
| Module | Role | Core Algorithm | Persistence |
|---|---|---|---|
| MemoryRank | Memory importance | PageRank | โ JSON/NPZ |
| Panorama | Timeline memory | Exponential Decay | โ JSON/SQLite |
| PFC | Decision making | Softmax Utility | |
| BasalGanglia | Habit learning | TD-Learning | โ Q-values |
| Amygdala | Emotion/Threat | Rescorla-Wagner | |
| Hypothalamus | Energy/Stress | HPA Dynamics | |
| Thalamus | Input filtering | Salience Gating |
๐ง Use Cases
๐ฌ Research
- Cognitive model simulation
- Memory-emotion-decision dynamics research
- Brain disorder mechanism exploration (PTSD, ADHD, etc.)
๐ญ Industrial
- AI agent memory subsystem
- RAG result filtering/ranking
- LangChain/LlamaIndex integration
๐ผ Commercial
- Personalized AI assistant memory layer
- Game NPC behavior engine
- Educational simulators
๐ Design Philosophy
Edge AI First
โ
Lightweight algorithms (only NumPy dependency)
โ
Each module runs independently
โ
No cloud dependency
โ
Extensible structure
Module Composition
# Use one
from memoryrank import MemoryRankEngine
# Combine
from cognitive_kernel import CognitiveKernel
# Extend
class MyBrain(CognitiveKernel):
def custom_recall(self): ...
๐ Quick Start
git clone https://github.com/qquartsco-svg/Cognitive_Kernel.git
cd Cognitive_Kernel
pip install numpy
# Long-term memory test
python3 cognitive_kernel.py
# 7-engine simulation
python3 examples/full_brain_simulation.py
# 4-engine pipeline
python3 examples/integrated_pipeline.py
๐ Documentation
| Document | Description |
|---|---|
| LONG_TERM_MEMORY.md | Long-term memory technical docs |
| API_REFERENCE.md | API Reference |
| ARCHITECTURE.md | Theoretical foundation, formulas, references |
| TEST_RESULTS.md | Full test results |
| VERIFICATION_STATUS.md | Theory โ Code verification |
๐ PHAM Blockchain Signature
All core modules signed with PHAM (Proof of Honest Authorship & Merit) blockchain:
| Module | Signed | Grade |
|---|---|---|
| cognitive_kernel.py | โ | A_HIGH (0.9998) |
| MemoryRank | โ | Signature |
| Panorama | โ | Signature |
| PFC | โ | Signature |
๐ License
MIT License โ Free to use, modify, and distribute
๐ค Author
GNJz (Qquarts) โ @qquartsco-svg
๐ค Contributing
Contributions welcome! Please open an issue or submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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 cognitive_kernel-2.0.0.tar.gz.
File metadata
- Download URL: cognitive_kernel-2.0.0.tar.gz
- Upload date:
- Size: 99.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74d970a49a8a04f68286cf51fa6f9015cd400c6f8198763c73dc2cbe52c06c70
|
|
| MD5 |
c3653b206ed956892d8b4c0198ab756b
|
|
| BLAKE2b-256 |
c449ff14efe2bd900e9bb8b561eae657f150de155ef2a0d06648438387042d55
|
File details
Details for the file cognitive_kernel-2.0.0-py3-none-any.whl.
File metadata
- Download URL: cognitive_kernel-2.0.0-py3-none-any.whl
- Upload date:
- Size: 92.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e32c278fbe6fb39dba1a7da08d838e9b066be858421312a302774f0da3a605b4
|
|
| MD5 |
3a96c569a4648a249b82f6c75882bc04
|
|
| BLAKE2b-256 |
5d5c636dc759258dae40977e8038930ab755100bf2668a89d61f87aa575b9b1a
|