BotWire Memory from Node.js (via fetch)
Free · Open source (MIT) · Works with LangChain, CrewAI, AutoGen · No signup
Your Node.js AI agent works perfectly until you restart it — then it forgets everything. You need persistent memory that survives process restarts, but building a proper storage layer feels like overkill for simple key-value data. Here's how to add persistent memory to your Node.js AI agent using BotWire's HTTP API via fetch.
The Problem: Agent Memory Dies with Process Restarts
Most Node.js AI agents store conversation history and context in variables or Maps. This works during development, but breaks in production when processes restart, containers redeploy, or your agent runs across multiple instances.
// This memory dies when the process restarts
const agentMemory = new Map();
agentMemory.set('user-123-context', 'User prefers technical responses');
// After restart: Map is empty, context is lost
Your agent loses track of user preferences, conversation history, and accumulated knowledge. Users have to repeat themselves. Multi-turn conversations break. Your agent feels stupid and unreliable.
The Fix: HTTP API Calls to BotWire Memory
BotWire provides persistent key-value storage via HTTP API. No signups, no API keys, just fetch calls to https://botwire.dev.
# Install Python SDK (for reference)
pip install botwire
// Node.js persistent agent memory via fetch
class AgentMemory {
constructor(namespace) {
this.baseUrl = 'https://botwire.dev';
this.namespace = namespace;
}
async set(key, value) {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ value })
});
return response.ok;
}
async get(key) {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`);
if (!response.ok) return null;
const data = await response.json();
return data.value;
}
}
// Usage
const memory = new AgentMemory('my-agent-v1');
await memory.set('user-123-context', 'Prefers code examples over theory');
const context = await memory.get('user-123-context');
console.log(context); // "Prefers code examples over theory"
How It Works: Key-Value Storage with Namespaces
The namespace parameter isolates your agent's data from other agents. Think of it as a database name. Within a namespace, you store key-value pairs that persist across restarts.
class AgentMemory {
constructor(namespace) {
this.baseUrl = 'https://botwire.dev';
this.namespace = namespace;
}
async set(key, value, ttlSeconds = null) {
const payload = { value };
if (ttlSeconds) payload.ttl = ttlSeconds;
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
return response.ok;
}
async get(key) {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`);
if (response.status === 404) return null;
if (!response.ok) throw new Error(`Memory fetch failed: ${response.status}`);
const data = await response.json();
return data.value;
}
async delete(key) {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`, {
method: 'DELETE'
});
return response.ok;
}
async listKeys() {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}`);
if (!response.ok) return [];
const data = await response.json();
return data.keys;
}
}
Common patterns: use user-${userId} keys for per-user context, conversation-${sessionId} for chat history, config-${feature} for agent settings. TTL automatically cleans up temporary data like session tokens.
TypeScript Integration for Type Safety
TypeScript developers can add type safety to nodejs agent memory operations:
interface MemoryValue {
[key: string]: any;
}
class TypedAgentMemory {
private baseUrl = 'https://botwire.dev';
constructor(private namespace: string) {}
async set<T extends MemoryValue>(key: string, value: T, ttlSeconds?: number): Promise<boolean> {
const payload: any = { value };
if (ttlSeconds) payload.ttl = ttlSeconds;
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
return response.ok;
}
async get<T extends MemoryValue>(key: string): Promise<T | null> {
const response = await fetch(`${this.baseUrl}/memory/${this.namespace}/${key}`);
if (response.status === 404) return null;
if (!response.ok) throw new Error(`Fetch failed: ${response.status}`);
const data = await response.json();
return data.value as T;
}
}
// Usage with typescript ai memory
const memory = new TypedAgentMemory('agent-prod');
interface UserContext {
preferences: string[];
lastSeen: string;
}
await memory.set<UserContext>('user-456', {
preferences: ['technical', 'concise'],
lastSeen: new Date().toISOString()
});
When NOT to Use BotWire Memory
- Vector search: BotWire isn't a vector database. Use Pinecone/Weaviate for embedding similarity search.
- High throughput: Free tier caps at 1000 writes/day. Use Redis for thousands of writes per minute.
- Sub-millisecond latency: HTTP calls take ~50-200ms. Use in-memory caches for microsecond response times.
FAQ
Q: Why not just use Redis? A: Redis requires setup, hosting, authentication. BotWire works immediately with zero config.
Q: Is this actually free? A: Yes, 1000 writes/day per namespace forever. Unlimited reads. No credit card required.
Q: What about data privacy? A: It's open source (MIT license) and self-hostable. Or use namespaces that don't contain PII.
BotWire Memory solves persistent storage for Node.js AI agents without the infrastructure overhead. Your agent remembers context across restarts, deployments, and machines.
pip install botwire
Try it at botwire.dev — no signup required.