agentis
Version:
A TypeScript framework for building sophisticated multi-agent systems
66 lines (65 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VectorMemoryClient = void 0;
const SupabaseClient_1 = require("../utils/SupabaseClient");
class VectorMemoryClient {
constructor(dimension = 1536) {
this.dimension = dimension;
}
async getMemory(agentId) {
const { data, error } = await SupabaseClient_1.supabase
.from('agent_memory')
.select('*')
.eq('agent_id', agentId);
if (error) {
console.error("Error fetching memory:", error);
return [];
}
return data || [];
}
async saveMemory(agentId, content, embedding) {
try {
const { error } = await SupabaseClient_1.supabase
.from('agent_memory')
.insert([{
agent_id: agentId,
content,
embedding: embedding ? embedding : null,
created_at: new Date().toISOString()
}]);
if (error) {
console.error("Error saving memory:", error);
throw error;
}
// Also save to messages table for conversation tracking
const { error: msgError } = await SupabaseClient_1.supabase
.from('messages')
.insert([{
id: `msg-${Date.now()}`,
sender_id: agentId,
recipient_id: 'system',
content,
timestamp: new Date().toISOString()
}]);
if (msgError) {
console.error("Error saving message:", msgError);
}
}
catch (error) {
console.error("Error in saveMemory:", error);
throw error;
}
}
async searchSimilar(agentId, embedding, limit = 5, threshold = 0.8) {
const { data, error } = await SupabaseClient_1.supabase.rpc('match_memories', {
query_embedding: embedding,
match_threshold: threshold,
match_count: limit,
p_agent_id: agentId
});
if (error)
throw error;
return data || [];
}
}
exports.VectorMemoryClient = VectorMemoryClient;