π§ Architect a Personalized Multi-Agent System with Long-Term Memory
Inspired by Google's approach to multi-agent systems with long-term memory
The Vision π
Imagine a system where AI agents work together to manage your real estate tokenization platform, each with their own specialized role and the ability to remember and learn from past interactions.
This is exactly what we're building at MyZubster: a multi-agent system with long-term memory that handles everything from investor onboarding to asset tokenization.
ποΈ System Architecture
The Agent Team
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MULTI-AGENT SYSTEM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ORCHESTRATOR AGENT β β
β β β’ Coordinates all other agents β β
β β β’ Maintains conversation history β β
β β β’ Manages agent lifecycle β β
β βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β
β βΌ βΌ βΌ β
β βββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β INVESTOR β β LEGAL β β TECHNICAL β β
β β AGENT β β AGENT β β AGENT β β
β β β β β β β β
β β β’ Onboardingβ β β’ Compliance checks β β β’ Token deployment β β
β β β’ KYC/AML β β β’ Document review β β β’ Smart contracts β β
β β β’ Portfolio β β β’ Regulatory advice β β β’ Blockchain ops β β
β βββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MEMORY LAYER β β
β β β’ Vector database for long-term memory (Pinecone/Chroma) β β
β β β’ Conversation history (Redis/SQLite) β β
β β β’ User preferences and context β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
text
π§ The Memory System
Long-Term Memory Architecture
Inspired by Google's approach, we implement a three-tier memory system:
1. Short-Term Memory (Conversation Context)
javascript
// agents/memory/short-term.js
class ShortTermMemory {
constructor() {
this.context = [];
this.maxLength = 50;
}
add(entry) {
this.context.push(entry);
if (this.context.length > this.maxLength) {
this.context.shift();
}
}
get() {
return this.context.slice(-10); // Last 10 interactions
}
clear() {
this.context = [];
}
}
2. Long-Term Memory (Vector Database)
javascript
// agents/memory/long-term.js
const { Pinecone } = require('@pinecone-database/pinecone');
const { OpenAIEmbeddings } = require('langchain/embeddings/openai');
class LongTermMemory {
constructor() {
this.embeddings = new OpenAIEmbeddings();
this.pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT
});
this.index = this.pinecone.Index('myzubster-memory');
}
async store(key, value, metadata = {}) {
const embedding = await this.embeddings.embedQuery(value);
await this.index.upsert([{
id: key,
values: embedding,
metadata: {
text: value,
timestamp: new Date().toISOString(),
...metadata
}
}]);
}
async retrieve(query, topK = 5) {
const embedding = await this.embeddings.embedQuery(query);
const results = await this.index.query({
vector: embedding,
topK,
includeMetadata: true
});
return results.matches;
}
}
3. Episodic Memory (Event History)
javascript
// agents/memory/episodic.js
class EpisodicMemory {
constructor() {
this.events = [];
this.db = new SQLite3('memory.db');
}
async recordEvent(event) {
const { type, data, timestamp } = event;
await this.db.run(
'INSERT INTO events (type, data, timestamp) VALUES (?, ?, ?)',
[type, JSON.stringify(data), timestamp || new Date().toISOString()]
);
}
async recallEvents(type, limit = 10) {
const rows = await this.db.all(
'SELECT * FROM events WHERE type = ? ORDER BY timestamp DESC LIMIT ?',
[type, limit]
);
return rows.map(row => ({
...row,
data: JSON.parse(row.data)
}));
}
}
π€ Agent Implementation
Investor Agent (Onboarding & KYC)
javascript
// agents/investor-agent.js
const { Agent } = require('./base-agent');
const { LongTermMemory } = require('../memory/long-term');
const { KYCService } = require('../services/kyc');
class InvestorAgent extends Agent {
constructor() {
super({
name: 'Investor Agent',
role: 'Investor Onboarding & KYC',
memory: new LongTermMemory()
});
this.kyc = new KYCService();
}
async processInvestor(investorData) {
// 1. Check if investor is known
const existing = await this.memory.retrieve(
`investor:${investorData.email}`
);
if (existing.length > 0) {
// 2. Recall previous interactions
const history = await this.memory.retrieve(
`history:${investorData.email}`,
10
);
return this.handleReturningInvestor(investorData, history);
}
// 3. New investor - initiate KYC
const kycResult = await this.kyc.verify(investorData);
// 4. Store in memory
await this.memory.store(
`investor:${investorData.email}`,
JSON.stringify(investorData),
{ type: 'investor', status: kycResult.status }
);
return {
success: kycResult.status === 'verified',
message: kycResult.message,
investorId: investorData.id
};
}
async handleReturningInvestor(investorData, history) {
// Personalized onboarding based on history
const lastInteraction = history[0]?.text || 'No previous interactions';
return {
success: true,
message: `Welcome back! Based on your history, I've prepared your portfolio summary.`,
history: history
};
}
}
Legal Agent (Compliance & Documentation)
javascript
// agents/legal-agent.js
const { Agent } = require('./base-agent');
const { DocumentAnalyzer } = require('../services/document-analyzer');
class LegalAgent extends Agent {
constructor() {
super({
name: 'Legal Agent',
role: 'Compliance & Documentation',
memory: new LongTermMemory()
});
this.docAnalyzer = new DocumentAnalyzer();
}
async reviewToken(tokenData) {
// 1. Check compliance requirements
const compliance = await this.checkCompliance(tokenData);
// 2. Analyze legal documents
const docs = await this.docAnalyzer.analyze(tokenData.documents);
// 3. Store compliance record
await this.memory.store(
`compliance:${tokenData.id}`,
JSON.stringify(compliance),
{ type: 'legal-review', status: compliance.status }
);
return {
compliant: compliance.status === 'compliant',
issues: compliance.issues,
recommendations: compliance.recommendations
};
}
async checkCompliance(tokenData) {
// Singapore/Hong Kong regulatory checks
const checks = {
securities: this.isSecurity(tokenData),
accreditedInvestors: this.requiresAccredited(tokenData),
prospectusExemption: this.isExempt(tokenData),
kycAml: this.isCompliantKYC(tokenData)
};
return {
status: Object.values(checks).every(v => v) ? 'compliant' : 'needs-review',
issues: Object.entries(checks)
.filter(([_, v]) => !v)
.map(([key]) => key),
recommendations: this.getRecommendations(checks)
};
}
}
Technical Agent (Smart Contracts & Deployment)
javascript
// agents/technical-agent.js
const { Agent } = require('./base-agent');
const { Web3Service } = require('../services/web3');
class TechnicalAgent extends Agent {
constructor() {
super({
name: 'Technical Agent',
role: 'Token Deployment & Blockchain Operations',
memory: new LongTermMemory()
});
this.web3 = new Web3Service();
}
async deployToken(tokenConfig) {
// 1. Check if similar token exists
const similar = await this.memory.retrieve(
`token:${tokenConfig.symbol}`,
1
);
// 2. Deploy smart contract
const deployment = await this.web3.deployContract(tokenConfig);
// 3. Record deployment
await this.memory.store(
`token:${tokenConfig.symbol}`,
JSON.stringify(deployment),
{ type: 'deployment', status: deployment.success }
);
return {
success: deployment.success,
contractAddress: deployment.address,
txHash: deployment.txHash,
gasUsed: deployment.gasUsed
};
}
async auditContract(address) {
// 1. Retrieve contract history
const history = await this.memory.retrieve(
`audit:${address}`,
5
);
// 2. Perform security audit
const audit = await this.web3.auditContract(address);
// 3. Store audit results
await this.memory.store(
`audit:${address}`,
JSON.stringify(audit),
{ type: 'audit', status: audit.status }
);
return {
status: audit.status,
vulnerabilities: audit.vulnerabilities,
score: audit.score,
recommendations: audit.recommendations
};
}
}
π Orchestrator Agent
javascript
// agents/orchestrator.js
const { EventEmitter } = require('events');
const { LongTermMemory } = require('../memory/long-term');
class Orchestrator extends EventEmitter {
constructor() {
super();
this.agents = {};
this.memory = new LongTermMemory();
this.activeTasks = new Map();
}
registerAgent(name, agent) {
this.agents[name] = agent;
console.log(`β
Agent registered: ${name}`);
}
async executeTask(task) {
const { type, data, context } = task;
const taskId = `${type}:${Date.now()}`;
// 1. Check memory for similar tasks
const similar = await this.memory.retrieve(`task:${type}`, 3);
// 2. Route to appropriate agent
let agent = this.selectAgent(type);
if (!agent) {
throw new Error(`No agent available for task: ${type}`);
}
// 3. Execute with context
const result = await agent.process(data, {
...context,
history: similar
});
// 4. Store result
await this.memory.store(
`task:${taskId}`,
JSON.stringify(result),
{ type, status: result.success ? 'success' : 'failed' }
);
// 5. Notify completion
this.emit('task-complete', { taskId, result });
return result;
}
selectAgent(taskType) {
const mapping = {
'investor': 'Investor Agent',
'legal': 'Legal Agent',
'technical': 'Technical Agent',
'compliance': 'Legal Agent',
'deployment': 'Technical Agent',
'kyc': 'Investor Agent'
};
const agentName = mapping[taskType];
return this.agents[agentName] || null;
}
async getAgentStatus() {
const status = {};
for (const [name, agent] of Object.entries(this.agents)) {
status[name] = {
active: true,
memory: await agent.memory.getStats(),
lastTask: agent.lastTask || null
};
}
return status;
}
}
π» Integration Example
javascript
// server.js - Integrate multi-agent system
const express = require('express');
const { Orchestrator } = require('./agents/orchestrator');
const { InvestorAgent } = require('./agents/investor-agent');
const { LegalAgent } = require('./agents/legal-agent');
const { TechnicalAgent } = require('./agents/technical-agent');
const app = express();
const orchestrator = new Orchestrator();
// Register agents
orchestrator.registerAgent('Investor Agent', new InvestorAgent());
orchestrator.registerAgent('Legal Agent', new LegalAgent());
orchestrator.registerAgent('Technical Agent', new TechnicalAgent());
// API endpoint for investor onboarding
app.post('/api/investors/onboard', async (req, res) => {
try {
const result = await orchestrator.executeTask({
type: 'investor',
data: req.body,
context: {
source: 'api',
timestamp: new Date().toISOString()
}
});
res.json({
success: result.success,
message: result.message,
investorId: result.investorId
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
// API endpoint for token deployment
app.post('/api/tokens/deploy', async (req, res) => {
try {
// 1. Legal review
const legalResult = await orchestrator.executeTask({
type: 'legal',
data: req.body,
context: { action: 'review' }
});
if (!legalResult.compliant) {
return res.status(400).json({
success: false,
message: 'Token does not meet compliance requirements',
issues: legalResult.issues
});
}
// 2. Technical deployment
const deployResult = await orchestrator.executeTask({
type: 'deployment',
data: req.body,
context: { reviewed: true }
});
res.json({
success: true,
contractAddress: deployResult.contractAddress,
txHash: deployResult.txHash
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
π§ͺ Testing the Agents
javascript
// test/agents.test.js
const { Orchestrator } = require('../agents/orchestrator');
const { InvestorAgent } = require('../agents/investor-agent');
describe('Multi-Agent System', () => {
let orchestrator;
beforeEach(() => {
orchestrator = new Orchestrator();
orchestrator.registerAgent('Investor Agent', new InvestorAgent());
});
test('should onboard new investor with memory', async () => {
const result = await orchestrator.executeTask({
type: 'investor',
data: {
email: 'test@example.com',
name: 'Test User',
netWorth: 2000000
},
context: { source: 'test' }
});
expect(result.success).toBe(true);
expect(result.investorId).toBeDefined();
});
test('should recall returning investor', async () => {
// First interaction
await orchestrator.executeTask({
type: 'investor',
data: { email: 'returning@example.com', name: 'Returning User' },
context: { source: 'test' }
});
// Second interaction
const result = await orchestrator.executeTask({
type: 'investor',
data: { email: 'returning@example.com', name: 'Returning User' },
context: { source: 'test' }
});
expect(result.history).toBeDefined();
expect(result.history.length).toBeGreaterThan(0);
});
});
π Benefits of Multi-Agent System
Benefit Description
Specialization Each agent focuses on a specific domain
Memory Agents remember past interactions and learn
Scalability Easy to add new agents for new domains
Resilience Agent failure doesn't break the whole system
Personalization Agents adapt to user behavior over time
π οΈ Tech Stack
Component Technology
Agents Node.js + TypeScript
Memory Pinecone/Chroma (vector DB)
Context Redis/SQLite
LLM OpenAI/Groq/Ollama
Orchestration Custom event-driven
π Connect With Me
Platform Link
Telegram Bot @myzubster_bot
GitHub github.com/DanielIoni-creator
Twitter/X @MyZubster
YouTube youtube.com/@myzubster
Dev.to dev.to/danielioni
Built with β€οΈ by Daniel Ioni and the MyZubster team.
Last updated: July 27, 2026

Top comments (0)