Neural-network-inspired memory engine for AI agents. Uses Hebbian learning, spreading activation, and a working memory queue instead of traditional database queries.
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Adapter Layer (per-host) β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β OpenCode β β OpenClaw β β CLI/API β β
β β Adapter β β Adapter β β (future) β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ β
βββββββββΌβββββββββββββββΌβββββββββββββββΌβββββββββββββ€
β βββββββββββββββββββββββββββββββββββββββββββ β
β β Core Engine β β
β β β’ Graph (nodes + synapses) β β
β β β’ Spreading Activation β β
β β β’ Hebbian Learning / Decay β β
β β β’ Working Memory Queue β β
β β β’ Session Abstraction β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
βββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β βββββββββββββββββββββββββββββββββββββββββββ β
β β Storage Layer (pluggable) β β
β β β’ SQLite + FTS5 (default) β β
β β β’ Custom StorageProvider β β
β βββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
| Package | Description |
|---|---|
@ai-agent-local-memory/core |
Host-agnostic engine: graph, Hebbian learning, spreading activation, working memory |
@ai-agent-local-memory/storage-sqlite |
SQLite + FTS5 storage implementation |
@ai-agent-local-memory/adapter-opencode |
OpenCode plugin adapter |
@ai-agent-local-memory/adapter-openclaw |
OpenClaw plugin adapter |
Nodes (Neurons): Memory units with types:
conceptβ Key entity extracted from conversationassertionβ Composite claim from multiple conceptsdefinitionβ Definition-style descriptionfillerβ Low-priority contextepisodeβ Full conversation referencemetaβ Hub node (consolidated summary)
Synapses (Edges): Weighted connections with types:
entityβ Shared named entitytemporalβ Co-occurrence in time windowlexicalβ Word overlap (Jaccard 0.2β0.55)semanticβ Embedding similaritycausalβ Causal relationshipcompositionalβ Composition (concepts β assertion)
Edges strengthen on co-activation: Ξw = Ξ· Γ (1 - w) (asymptotic, never exceeds 1). Edges decay over time: w = w Γ exp(-Ξ» Γ Ξt). Weak, old, rarely-used edges get pruned.
- Check working memory queue (recently/frequently accessed nodes)
- If found β use as seeds for spreading activation
- If not β full-text search (FTS5) β top results become seeds
- Spreading activation propagates through graph edges with hop decay
LRU-frequency hybrid queue (default 1000 items). Score = frequency Γ exp(-0.01 Γ hours_since_access). Lowest-score items evicted when full.
Add to opencode.json or opencode.jsonc:
{
"plugin": ["ai-agent-local-memory"]
}Restart OpenCode β it will automatically download and load the plugin.
Clone and build:
git clone https://github.com/jackieju/AIAgentLocalMemory.git
cd AIAgentLocalMemory
bun install
bun build packages/adapter-opencode/src/index.ts --outdir dist --target bun --external @opencode-ai/plugin
mkdir -p ~/.config/opencode/plugins
cp dist/index.js ~/.config/opencode/plugins/ai-agent-local-memory.jsRestart OpenCode β the plugin is loaded automatically from the plugins/ directory.
The plugin is installed globally but you can control behavior per-project:
| Scenario | How |
|---|---|
| All projects: use alongside magic-context (default) | No config needed β auto-detected |
| This project: AIAgentLocalMemory fully takes over | Create neural-context.json in project root with {"coexistWithMagicContext": false} and remove magic-context from project-level opencode.json |
| This project: disable AIAgentLocalMemory | Add a project-level opencode.json that doesn't load the plugin |
| Tool | Description |
|---|---|
neural_remember |
Store a memory node (concept, assertion, definition, etc.) |
neural_recall |
Query memories via spreading activation |
neural_forget |
Remove a memory node by ID |
neural_status |
View engine stats and working memory |
Create neural-context.json in your project root or .opencode/ directory:
{
"injectSystemPrompt": true,
"contextWindowTokens": 128000,
"budgetRatio": 0.6
}| Option | Default | Description |
|---|---|---|
injectSystemPrompt |
true |
Inject relevant memories into the system prompt each turn |
contextWindowTokens |
128000 |
Context window size in tokens for budget calculation |
budgetRatio |
0.6 |
Fraction of context window allocated to history |
coexistWithMagicContext |
auto-detected | Force coexistence mode on/off |
| Tool | Description |
|---|---|
neural_remember |
Store a memory node (concept, assertion, definition, etc.) |
neural_recall |
Find memories by ASSOCIATION via graph traversal + spreading activation |
neural_forget |
Remove a memory node by ID |
neural_note |
Save durable facts/notes (session/project/global scope) |
neural_reduce |
Drop tagged content (suppress from rendering) |
neural_pin |
Pin content to always show at full fidelity |
neural_expand |
Expand compressed/elided content back to full text |
neural_status |
View engine stats and working memory |
Automatic coexistence detection: When this plugin detects magic-context in your opencode.json, it automatically enters coexistence mode:
messages.transformis disabled (magic-context handles context compression)- Memory content injection is disabled (avoids double injection)
- Tool usage guide is still injected (so the agent knows neural_* tools exist)
- All
neural_*tools remain fully functional for associative memory
In this mode, magic-context handles the "context window management" while AIAgentLocalMemory provides "associative memory" β a complementary relationship.
Replace magic-context entirely in opencode.json:
{
"plugin": ["@ai-agent-local-memory/adapter-opencode"],
"compaction": { "auto": false, "prune": false }
}In standalone mode, this plugin handles:
- Conversation history compression (activation-based fidelity rendering)
- Cross-session memory (neural graph with Hebbian learning)
- Session facts and notes
- Full context window management
openclaw plugins install @ai-agent-local-memory/adapter-openclaw
openclaw gateway restartConfigure in ~/.openclaw/openclaw.json:
{
"plugins": {
"slots": {
"memory": "neural-context"
},
"entries": {
"neural-context": {
"enabled": true,
"hooks": {
"allowPromptInjection": true,
"allowConversationAccess": true
},
"config": {
"autoRecall": true,
"autoCapture": true,
"maxRecallResults": 10
}
}
}
}
}| Option | Default | Description |
|---|---|---|
storageDir |
~/.local/share/ai-agent-local-memory |
Custom storage directory |
autoRecall |
true |
Inject relevant memories before every AI turn via spreading activation |
autoCapture |
true |
Store conversations and build associative edges after every turn |
maxRecallResults |
10 |
Maximum memories injected into context per turn |
debug |
false |
Enable verbose debug logs |
| Tool | Description |
|---|---|
neural_recall |
Find memories by ASSOCIATION via graph traversal + spreading activation |
neural_remember |
Store information with automatic associative linking |
neural_forget |
Remove a memory node by ID |
neural_note |
Save durable facts/notes that persist across sessions |
neural_status |
View engine stats and working memory |
If you install AIAgentLocalMemory in both OpenCode and OpenClaw, they share the same memory graph by default:
~/.local/share/ai-agent-local-memory/
βββ graph.db β shared by both adapters
βββ episodes/ β shared
Memories stored via OpenClaw are immediately available in OpenCode and vice versa. Both adapters use projectId: "global" and the same default storage path.
SQLite WAL mode handles concurrent reads. Concurrent writes are rare (only on agent_end) and are retried automatically via SQLite's busy timeout.
To use separate memory stores, set a custom storageDir in one adapter's config.
bun install
bun run --filter='*' build
bun run --filter='*' testThe original design session for this project is in OpenCode. To resume:
opencode --session ses_166d0e7b9ffeBpCjAtqVkPPkP4Note: This session was started in /Users/I027910/Projects/HanziZombieDefense directory.
MIT