agentic-flow 1.6.6 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/test-neural.md +5 -0
- package/.claude/settings.json +20 -19
- package/.claude/skills/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude/skills/.claude-flow/metrics/performance.json +87 -0
- package/.claude/skills/.claude-flow/metrics/task-metrics.json +10 -0
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +166 -0
- package/.claude/skills/agentdb-vector-search/SKILL.md +126 -0
- package/.claude/skills/agentic-flow/agentdb-memory-patterns/SKILL.md +166 -0
- package/.claude/skills/agentic-flow/agentdb-vector-search/SKILL.md +126 -0
- package/.claude/skills/agentic-flow/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/agentic-flow/swarm-orchestration/SKILL.md +179 -0
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +87 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +10 -0
- package/.claude/skills/skill-builder/README.md +308 -0
- package/.claude/skills/skill-builder/SKILL.md +910 -0
- package/.claude/skills/skill-builder/docs/SPECIFICATION.md +358 -0
- package/.claude/skills/skill-builder/resources/schemas/skill-frontmatter.schema.json +41 -0
- package/.claude/skills/skill-builder/resources/templates/full-skill.template +118 -0
- package/.claude/skills/skill-builder/resources/templates/minimal-skill.template +38 -0
- package/.claude/skills/skill-builder/scripts/generate-skill.sh +334 -0
- package/.claude/skills/skill-builder/scripts/validate-skill.sh +198 -0
- package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
- package/CHANGELOG.md +61 -0
- package/README.md +79 -1
- package/dist/cli/skills-manager.js +1295 -0
- package/dist/cli/update-message.js +175 -0
- package/dist/cli-proxy.js +8 -1
- package/dist/utils/cli.js +17 -0
- package/package.json +2 -2
- package/.claude/answer.md +0 -1
package/.claude/settings.json
CHANGED
|
@@ -9,32 +9,33 @@
|
|
|
9
9
|
},
|
|
10
10
|
"permissions": {
|
|
11
11
|
"allow": [
|
|
12
|
-
"Bash(npx claude-flow
|
|
12
|
+
"Bash(npx claude-flow:*)",
|
|
13
13
|
"Bash(npm run lint)",
|
|
14
14
|
"Bash(npm run test:*)",
|
|
15
|
-
"Bash(npm test
|
|
15
|
+
"Bash(npm test:*)",
|
|
16
16
|
"Bash(git status)",
|
|
17
|
-
"Bash(git diff
|
|
18
|
-
"Bash(git log
|
|
19
|
-
"Bash(git add
|
|
20
|
-
"Bash(git commit
|
|
17
|
+
"Bash(git diff:*)",
|
|
18
|
+
"Bash(git log:*)",
|
|
19
|
+
"Bash(git add:*)",
|
|
20
|
+
"Bash(git commit:*)",
|
|
21
21
|
"Bash(git push)",
|
|
22
|
-
"Bash(git config
|
|
23
|
-
"Bash(git tag
|
|
24
|
-
"Bash(git branch
|
|
25
|
-
"Bash(git checkout
|
|
26
|
-
"Bash(git stash
|
|
27
|
-
"Bash(jq
|
|
28
|
-
"Bash(node
|
|
29
|
-
"Bash(which
|
|
22
|
+
"Bash(git config:*)",
|
|
23
|
+
"Bash(git tag:*)",
|
|
24
|
+
"Bash(git branch:*)",
|
|
25
|
+
"Bash(git checkout:*)",
|
|
26
|
+
"Bash(git stash:*)",
|
|
27
|
+
"Bash(jq:*)",
|
|
28
|
+
"Bash(node:*)",
|
|
29
|
+
"Bash(which:*)",
|
|
30
30
|
"Bash(pwd)",
|
|
31
|
-
"Bash(ls
|
|
31
|
+
"Bash(ls:*)",
|
|
32
|
+
"mcp__ruv-swarm",
|
|
33
|
+
"mcp__claude-flow@alpha",
|
|
34
|
+
"mcp__flow-nexus",
|
|
35
|
+
"WebSearch"
|
|
32
36
|
],
|
|
33
37
|
"deny": [
|
|
34
|
-
"Bash(rm -rf /)"
|
|
35
|
-
"Bash(curl * | bash)",
|
|
36
|
-
"Bash(wget * | sh)",
|
|
37
|
-
"Bash(eval *)"
|
|
38
|
+
"Bash(rm -rf /)"
|
|
38
39
|
]
|
|
39
40
|
},
|
|
40
41
|
"hooks": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"startTime": 1760906504131,
|
|
3
|
+
"sessionId": "session-1760906504131",
|
|
4
|
+
"lastActivity": 1760906504131,
|
|
5
|
+
"sessionDuration": 0,
|
|
6
|
+
"totalTasks": 1,
|
|
7
|
+
"successfulTasks": 1,
|
|
8
|
+
"failedTasks": 0,
|
|
9
|
+
"totalAgents": 0,
|
|
10
|
+
"activeAgents": 0,
|
|
11
|
+
"neuralEvents": 0,
|
|
12
|
+
"memoryMode": {
|
|
13
|
+
"reasoningbankOperations": 0,
|
|
14
|
+
"basicOperations": 0,
|
|
15
|
+
"autoModeSelections": 0,
|
|
16
|
+
"modeOverrides": 0,
|
|
17
|
+
"currentMode": "auto"
|
|
18
|
+
},
|
|
19
|
+
"operations": {
|
|
20
|
+
"store": {
|
|
21
|
+
"count": 0,
|
|
22
|
+
"totalDuration": 0,
|
|
23
|
+
"errors": 0
|
|
24
|
+
},
|
|
25
|
+
"retrieve": {
|
|
26
|
+
"count": 0,
|
|
27
|
+
"totalDuration": 0,
|
|
28
|
+
"errors": 0
|
|
29
|
+
},
|
|
30
|
+
"query": {
|
|
31
|
+
"count": 0,
|
|
32
|
+
"totalDuration": 0,
|
|
33
|
+
"errors": 0
|
|
34
|
+
},
|
|
35
|
+
"list": {
|
|
36
|
+
"count": 0,
|
|
37
|
+
"totalDuration": 0,
|
|
38
|
+
"errors": 0
|
|
39
|
+
},
|
|
40
|
+
"delete": {
|
|
41
|
+
"count": 0,
|
|
42
|
+
"totalDuration": 0,
|
|
43
|
+
"errors": 0
|
|
44
|
+
},
|
|
45
|
+
"search": {
|
|
46
|
+
"count": 0,
|
|
47
|
+
"totalDuration": 0,
|
|
48
|
+
"errors": 0
|
|
49
|
+
},
|
|
50
|
+
"init": {
|
|
51
|
+
"count": 0,
|
|
52
|
+
"totalDuration": 0,
|
|
53
|
+
"errors": 0
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"performance": {
|
|
57
|
+
"avgOperationDuration": 0,
|
|
58
|
+
"minOperationDuration": null,
|
|
59
|
+
"maxOperationDuration": null,
|
|
60
|
+
"slowOperations": 0,
|
|
61
|
+
"fastOperations": 0,
|
|
62
|
+
"totalOperationTime": 0
|
|
63
|
+
},
|
|
64
|
+
"storage": {
|
|
65
|
+
"totalEntries": 0,
|
|
66
|
+
"reasoningbankEntries": 0,
|
|
67
|
+
"basicEntries": 0,
|
|
68
|
+
"databaseSize": 0,
|
|
69
|
+
"lastBackup": null,
|
|
70
|
+
"growthRate": 0
|
|
71
|
+
},
|
|
72
|
+
"errors": {
|
|
73
|
+
"total": 0,
|
|
74
|
+
"byType": {},
|
|
75
|
+
"byOperation": {},
|
|
76
|
+
"recent": []
|
|
77
|
+
},
|
|
78
|
+
"reasoningbank": {
|
|
79
|
+
"semanticSearches": 0,
|
|
80
|
+
"sqlFallbacks": 0,
|
|
81
|
+
"embeddingGenerated": 0,
|
|
82
|
+
"consolidations": 0,
|
|
83
|
+
"avgQueryTime": 0,
|
|
84
|
+
"cacheHits": 0,
|
|
85
|
+
"cacheMisses": 0
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "AgentDB Memory Patterns"
|
|
3
|
+
description: "Implement persistent memory patterns for AI agents using AgentDB. Includes session memory, long-term storage, pattern learning, and context management. Use when building stateful agents, chat systems, or intelligent assistants."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AgentDB Memory Patterns
|
|
7
|
+
|
|
8
|
+
## What This Skill Does
|
|
9
|
+
|
|
10
|
+
Provides memory management patterns for AI agents using AgentDB's persistent storage and ReasoningBank integration. Enables agents to remember conversations, learn from interactions, and maintain context across sessions.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- agentic-flow v1.5.11+ or agentdb v1.0.4+
|
|
15
|
+
- Node.js 18+
|
|
16
|
+
- Understanding of agent architectures
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { AgentDB, MemoryManager } from 'agentdb';
|
|
22
|
+
|
|
23
|
+
// Initialize memory system
|
|
24
|
+
const memory = new MemoryManager({
|
|
25
|
+
agentId: 'assistant-001',
|
|
26
|
+
persist: true,
|
|
27
|
+
ttl: 3600 * 24 * 30 // 30 days
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Store interaction
|
|
31
|
+
await memory.store({
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: 'What is the capital of France?',
|
|
34
|
+
timestamp: Date.now()
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await memory.store({
|
|
38
|
+
role: 'assistant',
|
|
39
|
+
content: 'The capital of France is Paris.',
|
|
40
|
+
timestamp: Date.now()
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Retrieve context
|
|
44
|
+
const context = await memory.getRecentContext({ limit: 10 });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Memory Patterns
|
|
48
|
+
|
|
49
|
+
### 1. Session Memory
|
|
50
|
+
```typescript
|
|
51
|
+
class SessionMemory {
|
|
52
|
+
async storeMessage(role: string, content: string) {
|
|
53
|
+
return await db.storeMemory({
|
|
54
|
+
sessionId: this.sessionId,
|
|
55
|
+
role,
|
|
56
|
+
content,
|
|
57
|
+
timestamp: Date.now()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getSessionHistory(limit = 20) {
|
|
62
|
+
return await db.query({
|
|
63
|
+
filters: { sessionId: this.sessionId },
|
|
64
|
+
orderBy: 'timestamp',
|
|
65
|
+
limit
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Long-Term Memory
|
|
72
|
+
```typescript
|
|
73
|
+
// Store important facts
|
|
74
|
+
await db.storeFact({
|
|
75
|
+
category: 'user_preference',
|
|
76
|
+
key: 'language',
|
|
77
|
+
value: 'English',
|
|
78
|
+
confidence: 1.0,
|
|
79
|
+
source: 'explicit'
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Retrieve facts
|
|
83
|
+
const prefs = await db.getFacts({
|
|
84
|
+
category: 'user_preference'
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. Pattern Learning
|
|
89
|
+
```typescript
|
|
90
|
+
// Learn from successful interactions
|
|
91
|
+
await db.storePattern({
|
|
92
|
+
trigger: 'user_asks_time',
|
|
93
|
+
response: 'provide_formatted_time',
|
|
94
|
+
success: true,
|
|
95
|
+
context: { timezone: 'UTC' }
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Apply learned patterns
|
|
99
|
+
const pattern = await db.matchPattern(currentContext);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Advanced Patterns
|
|
103
|
+
|
|
104
|
+
### Hierarchical Memory
|
|
105
|
+
```typescript
|
|
106
|
+
// Organize memory in hierarchy
|
|
107
|
+
await memory.organize({
|
|
108
|
+
immediate: recentMessages, // Last 10 messages
|
|
109
|
+
shortTerm: sessionContext, // Current session
|
|
110
|
+
longTerm: importantFacts, // Persistent facts
|
|
111
|
+
semantic: embeddedKnowledge // Vector search
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Memory Consolidation
|
|
116
|
+
```typescript
|
|
117
|
+
// Periodically consolidate memories
|
|
118
|
+
await memory.consolidate({
|
|
119
|
+
strategy: 'importance', // Keep important memories
|
|
120
|
+
maxSize: 10000, // Size limit
|
|
121
|
+
minScore: 0.5 // Relevance threshold
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Integration with ReasoningBank
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { ReasoningBank } from 'agentic-flow/reasoningbank';
|
|
129
|
+
|
|
130
|
+
// Connect memory to reasoning
|
|
131
|
+
const rb = new ReasoningBank({
|
|
132
|
+
memory: memory,
|
|
133
|
+
learningRate: 0.1
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Learn from outcomes
|
|
137
|
+
await rb.recordOutcome({
|
|
138
|
+
task: 'summarize_document',
|
|
139
|
+
approach: 'extractive',
|
|
140
|
+
success: true,
|
|
141
|
+
metrics: { accuracy: 0.95 }
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Get optimal strategy
|
|
145
|
+
const strategy = await rb.getOptimalStrategy('summarize_document');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Best Practices
|
|
149
|
+
|
|
150
|
+
1. **Prune regularly**: Remove outdated or low-value memories
|
|
151
|
+
2. **Use TTL**: Set time-to-live for ephemeral data
|
|
152
|
+
3. **Index metadata**: Enable fast filtering by sessionId, userId
|
|
153
|
+
4. **Compress old data**: Archive infrequently accessed memories
|
|
154
|
+
|
|
155
|
+
## Troubleshooting
|
|
156
|
+
|
|
157
|
+
### Issue: Memory growing too large
|
|
158
|
+
**Solution**: Enable auto-pruning or set TTL values
|
|
159
|
+
|
|
160
|
+
### Issue: Context not relevant
|
|
161
|
+
**Solution**: Use vector search for semantic memory retrieval
|
|
162
|
+
|
|
163
|
+
## Learn More
|
|
164
|
+
|
|
165
|
+
- Memory API: packages/agentdb/docs/memory-api.md
|
|
166
|
+
- ReasoningBank: agentic-flow/src/reasoningbank/README.md
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "AgentDB Vector Search"
|
|
3
|
+
description: "Implement semantic vector search with AgentDB for intelligent document retrieval, similarity matching, and context-aware querying. Use when building RAG systems, semantic search engines, or intelligent knowledge bases."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AgentDB Vector Search
|
|
7
|
+
|
|
8
|
+
## What This Skill Does
|
|
9
|
+
|
|
10
|
+
Implements vector-based semantic search using AgentDB's high-performance vector database with 150x-12,500x faster operations than traditional solutions. Enables similarity search, hybrid search (vector + metadata), and real-time embedding generation.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- agentic-flow v1.5.11+ or agentdb v1.0.4+
|
|
15
|
+
- Node.js 18+
|
|
16
|
+
- OpenAI API key (for embeddings) or custom embedding model
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { AgentDB } from 'agentdb';
|
|
22
|
+
|
|
23
|
+
// Initialize AgentDB with vector support
|
|
24
|
+
const db = new AgentDB({
|
|
25
|
+
persist: true,
|
|
26
|
+
vectorDimensions: 1536, // OpenAI ada-002 dimensions
|
|
27
|
+
enableVectorIndex: true
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Store documents with vectors
|
|
31
|
+
await db.storeMemory({
|
|
32
|
+
text: "The quantum computer achieved 100 qubits",
|
|
33
|
+
metadata: { category: "technology", date: "2025-01-15" },
|
|
34
|
+
embedding: await generateEmbedding(text) // Your embedding function
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Semantic search
|
|
38
|
+
const results = await db.searchSimilar(
|
|
39
|
+
queryEmbedding,
|
|
40
|
+
{ limit: 10, threshold: 0.7 }
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Core Features
|
|
45
|
+
|
|
46
|
+
### 1. Vector Storage
|
|
47
|
+
```typescript
|
|
48
|
+
// Store with automatic embedding
|
|
49
|
+
await db.storeWithEmbedding({
|
|
50
|
+
content: "Your document text",
|
|
51
|
+
metadata: { source: "docs", page: 42 }
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Similarity Search
|
|
56
|
+
```typescript
|
|
57
|
+
// Find similar documents
|
|
58
|
+
const similar = await db.findSimilar("quantum computing", {
|
|
59
|
+
limit: 5,
|
|
60
|
+
minScore: 0.75
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 3. Hybrid Search (Vector + Metadata)
|
|
65
|
+
```typescript
|
|
66
|
+
// Combine vector similarity with metadata filtering
|
|
67
|
+
const results = await db.hybridSearch({
|
|
68
|
+
query: "machine learning models",
|
|
69
|
+
filters: {
|
|
70
|
+
category: "research",
|
|
71
|
+
date: { $gte: "2024-01-01" }
|
|
72
|
+
},
|
|
73
|
+
limit: 20
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Advanced Usage
|
|
78
|
+
|
|
79
|
+
### RAG (Retrieval Augmented Generation)
|
|
80
|
+
```typescript
|
|
81
|
+
// Build RAG pipeline
|
|
82
|
+
async function ragQuery(question: string) {
|
|
83
|
+
// 1. Get relevant context
|
|
84
|
+
const context = await db.searchSimilar(
|
|
85
|
+
await embed(question),
|
|
86
|
+
{ limit: 5, threshold: 0.7 }
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// 2. Generate answer with context
|
|
90
|
+
const prompt = `Context: ${context.map(c => c.text).join('\n')}
|
|
91
|
+
Question: ${question}`;
|
|
92
|
+
|
|
93
|
+
return await llm.generate(prompt);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Batch Operations
|
|
98
|
+
```typescript
|
|
99
|
+
// Efficient batch storage
|
|
100
|
+
await db.batchStore(documents.map(doc => ({
|
|
101
|
+
text: doc.content,
|
|
102
|
+
embedding: doc.vector,
|
|
103
|
+
metadata: doc.meta
|
|
104
|
+
})));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Performance Tips
|
|
108
|
+
|
|
109
|
+
- **Indexing**: Enable vector index for 10-100x faster searches
|
|
110
|
+
- **Batch Size**: Use batch operations for 1000+ documents
|
|
111
|
+
- **Dimensions**: Match embedding model (1536 for OpenAI ada-002)
|
|
112
|
+
- **Threshold**: Start at 0.7 for quality results
|
|
113
|
+
|
|
114
|
+
## Troubleshooting
|
|
115
|
+
|
|
116
|
+
### Issue: Slow search performance
|
|
117
|
+
**Solution**: Enable vector index: `enableVectorIndex: true`
|
|
118
|
+
|
|
119
|
+
### Issue: Poor relevance
|
|
120
|
+
**Solution**: Adjust similarity threshold or use hybrid search
|
|
121
|
+
|
|
122
|
+
## Learn More
|
|
123
|
+
|
|
124
|
+
- AgentDB Docs: packages/agentdb/README.md
|
|
125
|
+
- Vector DB API: packages/agentdb/docs/vector-api.md
|
|
126
|
+
- Performance Guide: docs/agentdb/performance.md
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "AgentDB Memory Patterns"
|
|
3
|
+
description: "Implement persistent memory patterns for AI agents using AgentDB. Includes session memory, long-term storage, pattern learning, and context management. Use when building stateful agents, chat systems, or intelligent assistants."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AgentDB Memory Patterns
|
|
7
|
+
|
|
8
|
+
## What This Skill Does
|
|
9
|
+
|
|
10
|
+
Provides memory management patterns for AI agents using AgentDB's persistent storage and ReasoningBank integration. Enables agents to remember conversations, learn from interactions, and maintain context across sessions.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- agentic-flow v1.5.11+ or agentdb v1.0.4+
|
|
15
|
+
- Node.js 18+
|
|
16
|
+
- Understanding of agent architectures
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { AgentDB, MemoryManager } from 'agentdb';
|
|
22
|
+
|
|
23
|
+
// Initialize memory system
|
|
24
|
+
const memory = new MemoryManager({
|
|
25
|
+
agentId: 'assistant-001',
|
|
26
|
+
persist: true,
|
|
27
|
+
ttl: 3600 * 24 * 30 // 30 days
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Store interaction
|
|
31
|
+
await memory.store({
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: 'What is the capital of France?',
|
|
34
|
+
timestamp: Date.now()
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await memory.store({
|
|
38
|
+
role: 'assistant',
|
|
39
|
+
content: 'The capital of France is Paris.',
|
|
40
|
+
timestamp: Date.now()
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Retrieve context
|
|
44
|
+
const context = await memory.getRecentContext({ limit: 10 });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Memory Patterns
|
|
48
|
+
|
|
49
|
+
### 1. Session Memory
|
|
50
|
+
```typescript
|
|
51
|
+
class SessionMemory {
|
|
52
|
+
async storeMessage(role: string, content: string) {
|
|
53
|
+
return await db.storeMemory({
|
|
54
|
+
sessionId: this.sessionId,
|
|
55
|
+
role,
|
|
56
|
+
content,
|
|
57
|
+
timestamp: Date.now()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getSessionHistory(limit = 20) {
|
|
62
|
+
return await db.query({
|
|
63
|
+
filters: { sessionId: this.sessionId },
|
|
64
|
+
orderBy: 'timestamp',
|
|
65
|
+
limit
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Long-Term Memory
|
|
72
|
+
```typescript
|
|
73
|
+
// Store important facts
|
|
74
|
+
await db.storeFact({
|
|
75
|
+
category: 'user_preference',
|
|
76
|
+
key: 'language',
|
|
77
|
+
value: 'English',
|
|
78
|
+
confidence: 1.0,
|
|
79
|
+
source: 'explicit'
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Retrieve facts
|
|
83
|
+
const prefs = await db.getFacts({
|
|
84
|
+
category: 'user_preference'
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. Pattern Learning
|
|
89
|
+
```typescript
|
|
90
|
+
// Learn from successful interactions
|
|
91
|
+
await db.storePattern({
|
|
92
|
+
trigger: 'user_asks_time',
|
|
93
|
+
response: 'provide_formatted_time',
|
|
94
|
+
success: true,
|
|
95
|
+
context: { timezone: 'UTC' }
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Apply learned patterns
|
|
99
|
+
const pattern = await db.matchPattern(currentContext);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Advanced Patterns
|
|
103
|
+
|
|
104
|
+
### Hierarchical Memory
|
|
105
|
+
```typescript
|
|
106
|
+
// Organize memory in hierarchy
|
|
107
|
+
await memory.organize({
|
|
108
|
+
immediate: recentMessages, // Last 10 messages
|
|
109
|
+
shortTerm: sessionContext, // Current session
|
|
110
|
+
longTerm: importantFacts, // Persistent facts
|
|
111
|
+
semantic: embeddedKnowledge // Vector search
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Memory Consolidation
|
|
116
|
+
```typescript
|
|
117
|
+
// Periodically consolidate memories
|
|
118
|
+
await memory.consolidate({
|
|
119
|
+
strategy: 'importance', // Keep important memories
|
|
120
|
+
maxSize: 10000, // Size limit
|
|
121
|
+
minScore: 0.5 // Relevance threshold
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Integration with ReasoningBank
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { ReasoningBank } from 'agentic-flow/reasoningbank';
|
|
129
|
+
|
|
130
|
+
// Connect memory to reasoning
|
|
131
|
+
const rb = new ReasoningBank({
|
|
132
|
+
memory: memory,
|
|
133
|
+
learningRate: 0.1
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Learn from outcomes
|
|
137
|
+
await rb.recordOutcome({
|
|
138
|
+
task: 'summarize_document',
|
|
139
|
+
approach: 'extractive',
|
|
140
|
+
success: true,
|
|
141
|
+
metrics: { accuracy: 0.95 }
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Get optimal strategy
|
|
145
|
+
const strategy = await rb.getOptimalStrategy('summarize_document');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Best Practices
|
|
149
|
+
|
|
150
|
+
1. **Prune regularly**: Remove outdated or low-value memories
|
|
151
|
+
2. **Use TTL**: Set time-to-live for ephemeral data
|
|
152
|
+
3. **Index metadata**: Enable fast filtering by sessionId, userId
|
|
153
|
+
4. **Compress old data**: Archive infrequently accessed memories
|
|
154
|
+
|
|
155
|
+
## Troubleshooting
|
|
156
|
+
|
|
157
|
+
### Issue: Memory growing too large
|
|
158
|
+
**Solution**: Enable auto-pruning or set TTL values
|
|
159
|
+
|
|
160
|
+
### Issue: Context not relevant
|
|
161
|
+
**Solution**: Use vector search for semantic memory retrieval
|
|
162
|
+
|
|
163
|
+
## Learn More
|
|
164
|
+
|
|
165
|
+
- Memory API: packages/agentdb/docs/memory-api.md
|
|
166
|
+
- ReasoningBank: agentic-flow/src/reasoningbank/README.md
|