-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Memory and Graph
Ruflo agents remember across sessions using a vector database (HNSW) and knowledge graph (ADR-130). This is the foundation for learning and discovery.
Memory Store (SQL.js)
├── Text entries + metadata (ttl, tags, source)
├── HNSW index (150x-12,500x faster search)
├── RaBitQ 1-bit quantization (32x compression)
└── Causal graph (temporal edges)
Knowledge Graph (ADR-130)
├── Nodes (entities, decisions, patterns)
├── Temporal edges (confidence, decay, last_reinforced, witness_id)
├── PQ-compressed embeddings
└── Pathfinding algorithms (shortest path, PageRank, influence)
npx ruflo@latest memory store \
--key "auth-jwt-pattern" \
--value "JWT with refresh tokens and blacklist" \
--namespace patterns \
--tags "authentication,security"npx ruflo@latest memory search \
--query "authentication best practices" \
--namespace patterns \
--limit 5Returns the top 5 most similar entries, ranked by cosine similarity.
npx ruflo@latest memory retrieve \
--key "auth-jwt-pattern" \
--namespace patterns| Namespace | Purpose | Example |
|---|---|---|
default |
General agent knowledge | Feature requests, discussions |
patterns |
Learned implementation patterns | "JWT auth with refresh", "pagination cursor" |
tasks |
Task outcomes and metrics | "feature #123 completed in 3 hours" |
feedback |
Quality feedback from agents | "Q=0.95" (90% success rate on similar tasks) |
claude-memories |
Imported from Claude Code auto-memory | Cross-project knowledge |
collaboration |
Shared team state | Dual-mode architecture results |
Beyond flat memory, Ruflo includes a temporal knowledge graph with causal edges.
Each edge (node → node) has metadata:
{
relation: "caused" | "preceded" | "depends-on" | "supersedes",
confidence: 0.0 - 1.0, // How certain is the relationship?
decay: 0.001, // Exponential decay per day
last_reinforced: timestamp, // When was this last used?
witness_id: string // Who verified this? (ADR-103)
}# A caused B (e.g., a security fix that resolved an issue)
npx ruflo@latest agentdb causal-edge \
--source-id "fix-sql-injection" \
--target-id "security-audit-pass" \
--relation "caused" \
--weight 0.95Find the shortest causal chain from one memory to another:
npx ruflo@latest agentdb causal-path \
--from "user-login-bug" \
--to "jwt-implementation" \
--algorithm shortest-pathAlgorithms available:
- shortest-path — Fewest hops
- highest-confidence — Maximum edge weights
- highest-impact — PageRank-weighted influence
- most-recent — Newest edges first
- least-decayed — Strongest evidence (temporal)
- multi-hop-influence — Transitive impact scoring
npx ruflo@latest agentdb pattern-store \
--pattern "Use async/await for I/O-bound tasks to avoid callback hell" \
--type "performance" \
--confidence 0.92npx ruflo@latest agentdb pattern-search \
--query "concurrency and performance" \
--min-confidence 0.8 \
--top-k 3AgentDB organizes memory by urgency:
| Tier | Purpose | Scope | TTL |
|---|---|---|---|
| working | Current session focus | Hot facts (agent state, task context) | 1 hour |
| episodic | Recent events | Task outcomes, decisions made | 7 days |
| semantic | General knowledge | Patterns, rules, learned behavior | ∞ |
# Store to episodic tier (task outcomes)
npx ruflo@latest agentdb hierarchical-store \
--key "task-123-result" \
--value "Feature completed ahead of schedule" \
--tier episodic
# Recall from all tiers
npx ruflo@latest agentdb hierarchical-recall \
--query "completed tasks" \
--tier episodic \
--top-k 5Agents improve by receiving quality scores:
# After task completion, provide feedback
npx ruflo@latest agentdb feedback \
--task-id "task-123" \
--agent "my-coder" \
--success true \
--quality 0.95 # 95% success rateThis trains the neural router to prefer similar agents on similar tasks.
Check what you've stored:
npx ruflo@latest memory statsOutput:
Total entries: 1,247
Total storage: 3.2 MB
HNSW index size: 1.5 MB
Average entry size: 2.6 KB
Oldest entry: 14 days ago
Most recent: 2 seconds ago
Namespace breakdown:
- patterns: 342
- tasks: 856
- feedback: 49
npx ruflo@latest memory delete \
--key "obsolete-pattern" \
--namespace patternsnpx ruflo@latest memory cleanup --dry-run
npx ruflo@latest memory cleanup # Actually delete# Backup all memories
npx ruflo@latest memory export --output backup.json
# Restore from backup
npx ruflo@latest memory import --input backup.jsonMemories automatically persist across sessions:
- Session End: Current patterns + feedback stored
- Session Start: Memories from past sessions loaded and indexed
- New Task: Memory search finds relevant past patterns automatically
No manual work required — the learning loop is automatic.
When spawning an agent:
Task({
prompt: `Implement a REST API. First, search shared memory for past API patterns.
Then design the endpoints. Use SendMessage when done.`,
subagent_type: "backend-dev",
name: "api-dev",
run_in_background: true
})The agent can:
-
memory_search— Find similar past implementations -
agentdb_pattern-search— Discover best practices -
agentdb_causal-path— Trace decisions that led to success/failure -
agentdb_feedback— Store the outcome for future learning
| Operation | Latency | Note |
|---|---|---|
| Vector search (HNSW) | 0.5–2ms | 150x faster than brute-force |
| Causal pathfinding | 1–5ms | 6 algorithms, up to 5-hop chains |
| Pattern recall | <1ms | Cached, in-memory |
| Memory store | <10ms | SQLite write |
| Graph consolidation | 100–500ms | Nightly, automatic |
For complex reasoning, use the full temporal graph:
import { GraphIntelligence } from "@claude-flow/agentdb";
const gi = new GraphIntelligence();
// Find all decisions that led to a success
const chain = await gi.traceInfluence(
"feature-launch-success",
{ depth: 3, algorithm: "least-decayed" }
);
// Impact analysis: how does changing this affect downstream?
const impact = await gi.deltaImplications(
"auth-module",
{ timeWindow: "7d" }
);Every causal edge can be signed (ADR-103):
npx ruflo@latest witness sign \
--manifest memories.json \
--private-key ~/.ruflo/signing-keyEnables:
- Audit trails (who claimed this pattern works?)
- Cross-org collaboration (trusted partners only)
- Compliance (immutable decision records)
Ruflo v3.10.1 · GitHub
Ruflo v3.10.1 · npm · GitHub · Benchmarks