TypeScript SDK¶
The TypeScript SDK (agent-memory-client) provides a type-safe client for integrating memory capabilities into Node.js and browser applications.
Version: 0.3.2+ Requirements: Node.js 20.0.0 or higher
Installation¶
Quick Start¶
import { MemoryAPIClient, UserId, Topics } from "agent-memory-client";
// Create client
const client = new MemoryAPIClient({
baseUrl: "http://localhost:8000",
defaultNamespace: "my-app",
});
// Store a memory
await client.createLongTermMemory([
{
text: "User prefers morning meetings",
memory_type: "semantic",
topics: ["scheduling", "preferences"],
user_id: "alice",
},
]);
// Search memories with filters
const results = await client.searchLongTermMemory({
text: "when does user prefer meetings",
userId: new UserId({ eq: "alice" }),
topics: new Topics({ any: ["scheduling"] }),
limit: 5,
});
for (const memory of results.memories) {
console.log(`${memory.text} (distance: ${memory.dist})`);
}
// Clean up
client.close();
Client Configuration¶
import { MemoryAPIClient, type MemoryClientConfig } from "agent-memory-client";
const config: MemoryClientConfig = {
baseUrl: "http://localhost:8000", // Required
timeout: 30000, // Request timeout (ms)
defaultNamespace: "production", // Default namespace
defaultModelName: "gpt-4o", // For auto-summarization
defaultContextWindowMax: 128000, // Context window limit
apiKey: "your-api-key", // Optional API key auth
bearerToken: "your-jwt", // Optional JWT auth
};
const client = new MemoryAPIClient(config);
Memory Operations¶
Creating Memories¶
import type { MemoryRecord } from "agent-memory-client";
const memories: MemoryRecord[] = [
{
text: "User works as a software engineer at TechCorp",
memory_type: "semantic",
topics: ["career", "work"],
entities: ["TechCorp"],
user_id: "alice",
},
];
await client.createLongTermMemory(memories);
Searching with Filters¶
The SDK provides type-safe filter classes:
import {
SessionId,
Namespace,
UserId,
Topics,
Entities,
CreatedAt,
LastAccessed,
MemoryType,
} from "agent-memory-client";
// Basic semantic search (default)
const results = await client.searchLongTermMemory({
text: "user preferences",
limit: 10,
});
// Keyword search - full-text matching
const keywordResults = await client.searchLongTermMemory({
text: "TechCorp engineer",
searchMode: "keyword",
limit: 10,
});