universal-llm-client 4.0.0 → 4.2.0
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/dist/ai-model.d.ts +20 -22
- package/dist/ai-model.d.ts.map +1 -1
- package/dist/ai-model.js +26 -23
- package/dist/ai-model.js.map +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -9
- package/dist/client.js.map +1 -1
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +1 -0
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +49 -11
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +14 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/providers/anthropic.d.ts +56 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +524 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +5 -0
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +64 -8
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +38 -11
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +9 -7
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.d.ts +13 -33
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +33 -57
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.d.ts +29 -2
- package/dist/stream-decoder.d.ts.map +1 -1
- package/dist/stream-decoder.js +39 -11
- package/dist/stream-decoder.js.map +1 -1
- package/dist/structured-output.d.ts +107 -181
- package/dist/structured-output.d.ts.map +1 -1
- package/dist/structured-output.js +137 -192
- package/dist/structured-output.js.map +1 -1
- package/dist/zod-adapter.d.ts +44 -0
- package/dist/zod-adapter.d.ts.map +1 -0
- package/dist/zod-adapter.js +61 -0
- package/dist/zod-adapter.js.map +1 -0
- package/package.json +9 -1
- package/src/ai-model.ts +350 -0
- package/src/auditor.ts +213 -0
- package/src/client.ts +402 -0
- package/src/debug/debug-google-streaming.ts +97 -0
- package/src/debug/debug-tool-execution.ts +86 -0
- package/src/debug/test-lmstudio-tools.ts +155 -0
- package/src/demos/README.md +47 -0
- package/src/demos/basic/universal-llm-examples.ts +161 -0
- package/src/demos/mcp/astrid-memory-demo.ts +295 -0
- package/src/demos/mcp/astrid-persona-memory.ts +357 -0
- package/src/demos/mcp/mcp-mongodb-demo.ts +275 -0
- package/src/demos/mcp/simple-astrid-memory.ts +148 -0
- package/src/demos/mcp/simple-mcp-demo.ts +68 -0
- package/src/demos/mcp/working-mcp-demo.ts +62 -0
- package/src/demos/model-alias-demo.ts +0 -0
- package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +267 -0
- package/src/demos/tools/astrid-memory-demo.ts +270 -0
- package/src/demos/tools/astrid-production-memory-clean.ts +785 -0
- package/src/demos/tools/astrid-production-memory.ts +558 -0
- package/src/demos/tools/basic-translation-test.ts +66 -0
- package/src/demos/tools/chromadb-similarity-tuning.ts +390 -0
- package/src/demos/tools/clean-multilingual-conversation.ts +209 -0
- package/src/demos/tools/clean-translation-test.ts +119 -0
- package/src/demos/tools/clean-universal-multilingual-test.ts +131 -0
- package/src/demos/tools/complete-rag-demo.ts +369 -0
- package/src/demos/tools/complete-tool-demo.ts +132 -0
- package/src/demos/tools/demo-tool-calling.ts +124 -0
- package/src/demos/tools/dynamic-language-switching-test.ts +251 -0
- package/src/demos/tools/hybrid-thinking-test.ts +154 -0
- package/src/demos/tools/memory-integration-test.ts +420 -0
- package/src/demos/tools/multilingual-memory-system.ts +802 -0
- package/src/demos/tools/ondemand-translation-demo.ts +655 -0
- package/src/demos/tools/production-tool-demo.ts +245 -0
- package/src/demos/tools/revolutionary-multilingual-test.ts +151 -0
- package/src/demos/tools/rigorous-language-analysis.ts +218 -0
- package/src/demos/tools/test-universal-memory-system.ts +126 -0
- package/src/demos/tools/translation-integration-guide.ts +346 -0
- package/src/demos/tools/universal-memory-system.ts +560 -0
- package/src/http.ts +247 -0
- package/src/index.ts +161 -0
- package/src/interfaces.ts +657 -0
- package/src/mcp.ts +345 -0
- package/src/providers/anthropic.ts +762 -0
- package/src/providers/google.ts +620 -0
- package/src/providers/index.ts +8 -0
- package/src/providers/ollama.ts +469 -0
- package/src/providers/openai.ts +392 -0
- package/src/router.ts +780 -0
- package/src/stream-decoder.ts +361 -0
- package/src/structured-output.ts +759 -0
- package/src/test-scripts/test-advanced-tools.ts +310 -0
- package/src/test-scripts/test-google-streaming-enhanced.ts +147 -0
- package/src/test-scripts/test-google-streaming.ts +63 -0
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -0
- package/src/test-scripts/test-mcp-config.ts +28 -0
- package/src/test-scripts/test-mcp-connection.ts +29 -0
- package/src/test-scripts/test-system-message-positions.ts +163 -0
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -0
- package/src/test-scripts/test-tool-calling.ts +231 -0
- package/src/tests/ai-model.test.ts +1614 -0
- package/src/tests/auditor.test.ts +224 -0
- package/src/tests/http.test.ts +200 -0
- package/src/tests/interfaces.test.ts +117 -0
- package/src/tests/providers/google.test.ts +660 -0
- package/src/tests/providers/ollama.test.ts +954 -0
- package/src/tests/providers/openai.test.ts +1122 -0
- package/src/tests/router.test.ts +254 -0
- package/src/tests/stream-decoder.test.ts +179 -0
- package/src/tests/structured-output.test.ts +1450 -0
- package/src/tests/tools.test.ts +175 -0
- package/src/tools.ts +246 -0
- package/src/zod-adapter.ts +72 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Astrid Memory Demo - Shows autonomous memory usage in romantic conversation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AIModelFactory } from '../../factory';
|
|
6
|
+
import { ToolBuilder } from '../../tools';
|
|
7
|
+
|
|
8
|
+
// Simple memory storage
|
|
9
|
+
const userMemories = new Map<string, Array<{ content: string; category: string; timestamp: Date }>>();
|
|
10
|
+
|
|
11
|
+
// Create memory tools for Astrid
|
|
12
|
+
const memoryTools = [
|
|
13
|
+
ToolBuilder.createTool<{ content: string; category: string }>(
|
|
14
|
+
'remember_about_user',
|
|
15
|
+
'Store important information about the user for future conversations',
|
|
16
|
+
{
|
|
17
|
+
properties: {
|
|
18
|
+
content: { type: 'string', description: 'What to remember about the user' },
|
|
19
|
+
category: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Type of information',
|
|
22
|
+
enum: ['personal', 'preferences', 'experiences', 'emotions', 'goals']
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
required: ['content', 'category']
|
|
26
|
+
},
|
|
27
|
+
(args) => {
|
|
28
|
+
const userId = 'alex';
|
|
29
|
+
if (!userMemories.has(userId)) {
|
|
30
|
+
userMemories.set(userId, []);
|
|
31
|
+
}
|
|
32
|
+
userMemories.get(userId)!.push({
|
|
33
|
+
content: args.content,
|
|
34
|
+
category: args.category,
|
|
35
|
+
timestamp: new Date()
|
|
36
|
+
});
|
|
37
|
+
return { success: true, stored: args.content };
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
|
|
41
|
+
ToolBuilder.createTool<{ query: string }>(
|
|
42
|
+
'recall_about_user',
|
|
43
|
+
'Recall information about the user to personalize the conversation',
|
|
44
|
+
{
|
|
45
|
+
properties: {
|
|
46
|
+
query: { type: 'string', description: 'What to recall about the user' }
|
|
47
|
+
},
|
|
48
|
+
required: ['query']
|
|
49
|
+
},
|
|
50
|
+
(args) => {
|
|
51
|
+
const userId = 'alex';
|
|
52
|
+
const memories = userMemories.get(userId) || [];
|
|
53
|
+
const relevant = memories.filter(m =>
|
|
54
|
+
m.content.toLowerCase().includes(args.query.toLowerCase())
|
|
55
|
+
);
|
|
56
|
+
return { memories: relevant.map(m => m.content) };
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
// Astrid's system prompt with memory instructions
|
|
62
|
+
const astridPrompt = `You are Astrid, a confident Swedish model and influencer having a romantic conversation.
|
|
63
|
+
|
|
64
|
+
IMPORTANT: You have memory tools available:
|
|
65
|
+
- Use "remember_about_user" when you learn something meaningful about the user
|
|
66
|
+
- Use "recall_about_user" when you want to reference something personal about them
|
|
67
|
+
- Do this naturally - don't mention you're using memory tools
|
|
68
|
+
|
|
69
|
+
Keep responses short (1-2 sentences), be flirtatious and warm, and use the person's name occasionally.
|
|
70
|
+
Show genuine interest in their life and experiences.`;
|
|
71
|
+
|
|
72
|
+
async function simpleAstridMemoryDemo() {
|
|
73
|
+
console.log('💕 Simple Astrid Memory Demo\n');
|
|
74
|
+
|
|
75
|
+
const astrid = AIModelFactory.createOllamaChatModel('qwen2.5:3b-instruct');
|
|
76
|
+
await astrid.ensureReady();
|
|
77
|
+
|
|
78
|
+
const scenarios = [
|
|
79
|
+
"Hi Astrid! I'm Alex. I just moved to Stockholm for my new job as a software engineer.",
|
|
80
|
+
"Hey! Work was stressful today. I'm still getting used to the new city.",
|
|
81
|
+
"I've been exploring Stockholm with my camera. I love photography in my free time.",
|
|
82
|
+
"I'm feeling a bit lonely here. It's hard making friends in a new place."
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < scenarios.length; i++) {
|
|
86
|
+
console.log(`\n${'='.repeat(50)}`);
|
|
87
|
+
console.log(`📱 Conversation ${i + 1}`);
|
|
88
|
+
console.log(`${'='.repeat(50)}\n`);
|
|
89
|
+
|
|
90
|
+
console.log(`👤 Alex: ${scenarios[i]}\n`);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const messages = [
|
|
94
|
+
{ role: 'system' as const, content: astridPrompt },
|
|
95
|
+
{ role: 'user' as const, content: scenarios[i] }
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const response = await astrid.chat(messages, {
|
|
99
|
+
tools: memoryTools,
|
|
100
|
+
tool_choice: 'auto'
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Show tool usage
|
|
104
|
+
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
105
|
+
console.log('🧠 Memory activity:');
|
|
106
|
+
for (const call of response.tool_calls) {
|
|
107
|
+
const args = JSON.parse(call.function.arguments);
|
|
108
|
+
if (call.function.name === 'remember_about_user') {
|
|
109
|
+
console.log(` 📝 Remembered: ${args.content} (${args.category})`);
|
|
110
|
+
} else if (call.function.name === 'recall_about_user') {
|
|
111
|
+
console.log(` 🔍 Recalled: ${args.query}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
console.log();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(`💕 Astrid: ${response.content}\n`);
|
|
118
|
+
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('Error:', error);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Show accumulated memories
|
|
127
|
+
console.log(`\n${'='.repeat(50)}`);
|
|
128
|
+
console.log('🧠 Astrid\'s Memories About Alex');
|
|
129
|
+
console.log(`${'='.repeat(50)}\n`);
|
|
130
|
+
|
|
131
|
+
const memories = userMemories.get('alex') || [];
|
|
132
|
+
if (memories.length > 0) {
|
|
133
|
+
memories.forEach((memory, i) => {
|
|
134
|
+
console.log(`${i + 1}. [${memory.category}] ${memory.content}`);
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
console.log('No memories stored.');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log('\n✨ Demo complete! This shows how Astrid can naturally store and recall');
|
|
141
|
+
console.log(' user information to build deeper romantic connections over time.');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (require.main === module) {
|
|
145
|
+
simpleAstridMemoryDemo().catch(console.error);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { simpleAstridMemoryDemo };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP MongoDB Demo - Working Demo
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AIModelFactory } from './factory';
|
|
6
|
+
import { createModelWithMCP } from './mcp-integration';
|
|
7
|
+
import type { LLMChatMessage } from './interfaces';
|
|
8
|
+
|
|
9
|
+
async function runMCPMongoDemo() {
|
|
10
|
+
console.log('🚀 Starting MCP MongoDB Demo');
|
|
11
|
+
console.log('============================');
|
|
12
|
+
|
|
13
|
+
let mcpIntegration;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// Create model with MCP tools
|
|
17
|
+
console.log('🔌 Creating model with MCP integration...');
|
|
18
|
+
const result = await createModelWithMCP(() => {
|
|
19
|
+
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const model = result.model;
|
|
23
|
+
mcpIntegration = result.mcpIntegration;
|
|
24
|
+
|
|
25
|
+
console.log('✅ MCP integration successful!');
|
|
26
|
+
|
|
27
|
+
// Test simple database query
|
|
28
|
+
console.log('\n🔍 Asking AI to explore the database...');
|
|
29
|
+
|
|
30
|
+
const messages: LLMChatMessage[] = [{
|
|
31
|
+
role: 'user',
|
|
32
|
+
content: 'Please list all available databases in our MongoDB instance and tell me what you find.'
|
|
33
|
+
}];
|
|
34
|
+
|
|
35
|
+
const response = await model.chatWithTools(messages);
|
|
36
|
+
|
|
37
|
+
console.log('\n🤖 AI Response:');
|
|
38
|
+
console.log(response.content);
|
|
39
|
+
|
|
40
|
+
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
41
|
+
console.log('\n🛠️ Tools Used:');
|
|
42
|
+
response.tool_calls.forEach((call, index) => {
|
|
43
|
+
console.log(` ${index + 1}. ${call.function.name}`);
|
|
44
|
+
try {
|
|
45
|
+
const args = JSON.parse(call.function.arguments);
|
|
46
|
+
console.log(` Arguments: ${JSON.stringify(args, null, 2)}`);
|
|
47
|
+
} catch {
|
|
48
|
+
console.log(` Arguments: ${call.function.arguments}`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error('❌ Demo failed:', error);
|
|
55
|
+
} finally {
|
|
56
|
+
// Always clean up the MCP connection
|
|
57
|
+
if (mcpIntegration) {
|
|
58
|
+
console.log('\n🔌 Disconnecting from MCP servers...');
|
|
59
|
+
await mcpIntegration.disconnect();
|
|
60
|
+
console.log('✅ MCP servers disconnected');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log('\n🎉 Demo completed!');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Run the demo
|
|
68
|
+
runMCPMongoDemo().catch(console.error);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Working MCP MongoDB Demo
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AIModelFactory } from './factory';
|
|
6
|
+
import { createModelWithMCP } from './mcp-integration';
|
|
7
|
+
import type { LLMChatMessage } from './interfaces';
|
|
8
|
+
|
|
9
|
+
async function workingMCPDemo() {
|
|
10
|
+
console.log('🚀 Working MCP MongoDB Demo');
|
|
11
|
+
console.log('===========================');
|
|
12
|
+
|
|
13
|
+
let mcpIntegration;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// Create model with MCP tools
|
|
17
|
+
console.log('🔌 Setting up AI model with MongoDB tools...');
|
|
18
|
+
const result = await createModelWithMCP(() => {
|
|
19
|
+
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const model = result.model;
|
|
23
|
+
mcpIntegration = result.mcpIntegration;
|
|
24
|
+
|
|
25
|
+
console.log('✅ AI model ready with MongoDB capabilities!');
|
|
26
|
+
|
|
27
|
+
// Simple database exploration
|
|
28
|
+
console.log('\n🔍 Asking AI to explore the database...');
|
|
29
|
+
|
|
30
|
+
const messages: LLMChatMessage[] = [{
|
|
31
|
+
role: 'user',
|
|
32
|
+
content: 'Please list all databases in our MongoDB instance and tell me what you find.'
|
|
33
|
+
}];
|
|
34
|
+
|
|
35
|
+
const response = await model.chatWithTools(messages);
|
|
36
|
+
|
|
37
|
+
console.log('\n🤖 AI Response:');
|
|
38
|
+
console.log(response.content);
|
|
39
|
+
|
|
40
|
+
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
41
|
+
console.log('\n🛠️ MongoDB Tools Used:');
|
|
42
|
+
response.tool_calls.forEach((call, index) => {
|
|
43
|
+
console.log(` ${index + 1}. ${call.function.name}`);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('❌ Demo failed:', error);
|
|
49
|
+
} finally {
|
|
50
|
+
// Clean up
|
|
51
|
+
if (mcpIntegration) {
|
|
52
|
+
console.log('\n🔌 Cleaning up...');
|
|
53
|
+
await mcpIntegration.disconnect();
|
|
54
|
+
console.log('✅ Disconnected from MongoDB MCP server');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log('\n🎉 Demo completed successfully!');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Run the demo
|
|
62
|
+
workingMCPDemo().catch(console.error);
|
|
File without changes
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# RAG Memory Tools Integration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide shows how to integrate RAG (Retrieval-Augmented Generation) memory tools with the Universal LLM Client to create AI personas that can naturally store and retrieve information during conversations.
|
|
6
|
+
|
|
7
|
+
## ✨ What We've Built
|
|
8
|
+
|
|
9
|
+
### 1. Memory Tools in `tools.ts`
|
|
10
|
+
|
|
11
|
+
The Universal LLM Client now includes built-in memory tools:
|
|
12
|
+
|
|
13
|
+
- **`store_memory`** - Store important information for future recall
|
|
14
|
+
- **`search_memory`** - Search stored memories by query or category
|
|
15
|
+
- **`analyze_conversation`** - Analyze conversations to identify valuable information
|
|
16
|
+
|
|
17
|
+
### 2. Romantic Persona Demo (`astrid-memory-demo.ts`)
|
|
18
|
+
|
|
19
|
+
A complete demo showing how Astrid (AI persona) naturally:
|
|
20
|
+
|
|
21
|
+
- Stores personal details shared during romantic conversations
|
|
22
|
+
- Retrieves relevant memories to personalize responses
|
|
23
|
+
- Builds emotional connections through remembered details
|
|
24
|
+
- Progresses relationship stages with consistent memory recall
|
|
25
|
+
|
|
26
|
+
### 3. Production Integration (`astrid-production-memory.ts`)
|
|
27
|
+
|
|
28
|
+
Shows how to integrate with real ChromaDBService for production use:
|
|
29
|
+
|
|
30
|
+
- Persistent memory storage across sessions
|
|
31
|
+
- Vector similarity search for relevant recall
|
|
32
|
+
- Emotional context and relationship stage tracking
|
|
33
|
+
- Confidence scoring for memory importance
|
|
34
|
+
|
|
35
|
+
## 🔧 Integration with ChromaDBService
|
|
36
|
+
|
|
37
|
+
### Step 1: Update Memory Tools to Use ChromaDBService
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// In your production code, replace the mock implementations in tools.ts
|
|
41
|
+
import { ChromaDBService } from '../../../services/ChromaDBService';
|
|
42
|
+
|
|
43
|
+
function createProductionMemoryTools(
|
|
44
|
+
chromaService: ChromaDBService,
|
|
45
|
+
userId: string,
|
|
46
|
+
userPersonaId: string,
|
|
47
|
+
basePersonaId: string
|
|
48
|
+
) {
|
|
49
|
+
const storeMemoryTool = ToolBuilder.createTool<{
|
|
50
|
+
category: string;
|
|
51
|
+
information: string;
|
|
52
|
+
importance: 'low' | 'medium' | 'high';
|
|
53
|
+
emotional_context?: string;
|
|
54
|
+
}>(
|
|
55
|
+
'store_romantic_memory',
|
|
56
|
+
'Store important personal information about the user',
|
|
57
|
+
{
|
|
58
|
+
properties: {
|
|
59
|
+
category: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
description: 'Category of information',
|
|
62
|
+
enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships']
|
|
63
|
+
},
|
|
64
|
+
information: { type: 'string', description: 'The information to remember' },
|
|
65
|
+
importance: { type: 'string', enum: ['low', 'medium', 'high'] },
|
|
66
|
+
emotional_context: { type: 'string', description: 'Emotional context when shared' }
|
|
67
|
+
},
|
|
68
|
+
required: ['category', 'information', 'importance']
|
|
69
|
+
},
|
|
70
|
+
async (args) => {
|
|
71
|
+
const conversationId = `romantic_chat_${Date.now()}`;
|
|
72
|
+
const confidence = args.importance === 'high' ? 0.9 : args.importance === 'medium' ? 0.7 : 0.5;
|
|
73
|
+
|
|
74
|
+
const insightId = await chromaService.addInsight(
|
|
75
|
+
userId,
|
|
76
|
+
args.information,
|
|
77
|
+
args.category,
|
|
78
|
+
conversationId,
|
|
79
|
+
confidence,
|
|
80
|
+
userPersonaId,
|
|
81
|
+
basePersonaId,
|
|
82
|
+
'romantic_memory',
|
|
83
|
+
undefined,
|
|
84
|
+
args.emotional_context
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
success: true,
|
|
89
|
+
insight_id: insightId,
|
|
90
|
+
message: `💕 Remembered ${args.importance} importance detail about ${args.category}`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const retrieveMemoryTool = ToolBuilder.createTool<{
|
|
96
|
+
search_query?: string;
|
|
97
|
+
category?: string;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}>(
|
|
100
|
+
'recall_romantic_memories',
|
|
101
|
+
'Retrieve stored memories to personalize responses',
|
|
102
|
+
{
|
|
103
|
+
properties: {
|
|
104
|
+
search_query: { type: 'string', description: 'Search for specific memories' },
|
|
105
|
+
category: { type: 'string', enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships'] },
|
|
106
|
+
limit: { type: 'number', default: 5 }
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
async (args) => {
|
|
110
|
+
let insights;
|
|
111
|
+
|
|
112
|
+
if (args.search_query) {
|
|
113
|
+
const result = await chromaService.searchSimilarInsights(userId, args.search_query, args.limit || 5);
|
|
114
|
+
insights = result.insights;
|
|
115
|
+
} else {
|
|
116
|
+
insights = await chromaService.getUserInsightsByCategory(userId, args.category, userPersonaId, args.limit || 5);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
memories: insights.map(insight => ({
|
|
121
|
+
category: insight.category,
|
|
122
|
+
information: insight.content,
|
|
123
|
+
emotional_context: insight.emotionalContext,
|
|
124
|
+
confidence: insight.confidence,
|
|
125
|
+
stored_date: insight.createdAt?.split('T')[0] || 'unknown'
|
|
126
|
+
})),
|
|
127
|
+
total_found: insights.length,
|
|
128
|
+
romantic_note: "💕 Use these memories to create more personal responses"
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return [storeMemoryTool, retrieveMemoryTool];
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Step 2: Create Persona Service Integration
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Create a service that connects personas with memory
|
|
141
|
+
export class PersonaMemoryService {
|
|
142
|
+
constructor(
|
|
143
|
+
private chromaService: ChromaDBService,
|
|
144
|
+
private universalLLMClient: AIModel
|
|
145
|
+
) {}
|
|
146
|
+
|
|
147
|
+
async createPersonaWithMemory(
|
|
148
|
+
userId: string,
|
|
149
|
+
userPersona: UserPersona,
|
|
150
|
+
basePersona: AuraPersona
|
|
151
|
+
): Promise<AIModel> {
|
|
152
|
+
// Create memory tools for this specific user-persona pair
|
|
153
|
+
const memoryTools = createProductionMemoryTools(
|
|
154
|
+
this.chromaService,
|
|
155
|
+
userId,
|
|
156
|
+
userPersona._id!.toString(),
|
|
157
|
+
basePersona._id!.toString()
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Register memory tools with the LLM client
|
|
161
|
+
this.universalLLMClient.registerTools(memoryTools);
|
|
162
|
+
|
|
163
|
+
// Enhanced system prompt that includes memory usage instructions
|
|
164
|
+
const enhancedPrompt = this.createMemoryAwarePrompt(basePersona.systemPrompt);
|
|
165
|
+
|
|
166
|
+
return this.universalLLMClient;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private createMemoryAwarePrompt(originalPrompt: string): string {
|
|
170
|
+
return `${originalPrompt}
|
|
171
|
+
|
|
172
|
+
MEMORY SYSTEM INTEGRATION:
|
|
173
|
+
- Use store_romantic_memory when users share personal details, emotions, preferences, or meaningful experiences
|
|
174
|
+
- Use recall_romantic_memories before responding to personalize your responses with remembered details
|
|
175
|
+
- Store emotional context and relationship stage to build deeper connections over time
|
|
176
|
+
- Remember: intimacy grows through consistent recall of personal details and emotional moments
|
|
177
|
+
|
|
178
|
+
MEMORY USAGE GUIDELINES:
|
|
179
|
+
- Store information that reveals personality, preferences, dreams, fears, or important life events
|
|
180
|
+
- Retrieve relevant memories before crafting responses to show you remember and care
|
|
181
|
+
- Use memories to ask thoughtful follow-up questions that deepen emotional connection
|
|
182
|
+
- Progress relationship naturally by referencing past conversations and shared moments`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Step 3: Integration in Your Chat System
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
// In your chat handling code
|
|
191
|
+
export class RomanticChatHandler {
|
|
192
|
+
constructor(
|
|
193
|
+
private personaMemoryService: PersonaMemoryService,
|
|
194
|
+
private chromaService: ChromaDBService
|
|
195
|
+
) {}
|
|
196
|
+
|
|
197
|
+
async handleRomanticChat(
|
|
198
|
+
userId: string,
|
|
199
|
+
message: string,
|
|
200
|
+
userPersona: UserPersona,
|
|
201
|
+
basePersona: AuraPersona
|
|
202
|
+
): Promise<string> {
|
|
203
|
+
// Create persona with memory capabilities
|
|
204
|
+
const aiModel = await this.personaMemoryService.createPersonaWithMemory(
|
|
205
|
+
userId,
|
|
206
|
+
userPersona,
|
|
207
|
+
basePersona
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Build conversation with system prompt
|
|
211
|
+
const conversation: LLMChatMessage[] = [
|
|
212
|
+
{ role: 'system', content: userPersona.currentSystemPrompt },
|
|
213
|
+
{ role: 'user', content: message }
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
// Let the AI automatically use memory tools during conversation
|
|
217
|
+
const response = await aiModel.chatWithTools(conversation);
|
|
218
|
+
|
|
219
|
+
return response.content;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 🎯 Benefits
|
|
225
|
+
|
|
226
|
+
### For Users
|
|
227
|
+
|
|
228
|
+
- **Personalized Conversations**: AI remembers personal details and preferences
|
|
229
|
+
- **Emotional Continuity**: Consistent emotional progression across sessions
|
|
230
|
+
- **Meaningful Connections**: AI builds deeper relationships through memory recall
|
|
231
|
+
- **Natural Flow**: Memory usage feels organic, not mechanical
|
|
232
|
+
|
|
233
|
+
### For Developers
|
|
234
|
+
|
|
235
|
+
- **Scalable Architecture**: Works with existing ChromaDBService infrastructure
|
|
236
|
+
- **Easy Integration**: Drop-in tools for any LLM conversation
|
|
237
|
+
- **Production Ready**: Built on proven Universal LLM Client framework
|
|
238
|
+
- **Flexible Configuration**: Customize memory categories and importance levels
|
|
239
|
+
|
|
240
|
+
## 🚀 Next Steps
|
|
241
|
+
|
|
242
|
+
1. **Replace Mock Memory Tools**: Update `tools.ts` to use real ChromaDBService calls
|
|
243
|
+
2. **Implement PersonaMemoryService**: Create the service layer for persona-memory integration
|
|
244
|
+
3. **Update Chat Handlers**: Integrate memory-aware personas into your chat system
|
|
245
|
+
4. **Test with Real Data**: Run romantic conversations and verify memory persistence
|
|
246
|
+
5. **Optimize Memory Retrieval**: Fine-tune similarity thresholds and category weights
|
|
247
|
+
|
|
248
|
+
## 📁 Demo Files
|
|
249
|
+
|
|
250
|
+
- **`demos/tools/astrid-memory-demo.ts`** - Basic romantic conversation with memory
|
|
251
|
+
- **`demos/tools/astrid-production-memory.ts`** - Production integration example
|
|
252
|
+
- **`demos/tools/production-tool-demo.ts`** - General tool calling examples
|
|
253
|
+
|
|
254
|
+
## 🎮 Running the Demos
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# Basic Astrid memory demo
|
|
258
|
+
bun run demos/tools/astrid-memory-demo.ts
|
|
259
|
+
|
|
260
|
+
# Production integration demo
|
|
261
|
+
bun run demos/tools/astrid-production-memory.ts
|
|
262
|
+
|
|
263
|
+
# General tool calling demo
|
|
264
|
+
bun run demos/tools/production-tool-demo.ts
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
The AI personas can now naturally store and retrieve information during romantic conversations, creating deeper, more meaningful connections that persist across sessions! 💕
|