I'm running into an issue with Agent Memory Server while using the TypeScript SDK. I'm not sure if it's an issue or a misunderstanding on my part about how things work. My workflow goes as follows:
wm = getOrCreateWorkingMemory(...)
messages = [...] // bunch of messages
putWorkingMemory(wm.session_id...)
wait(15s)
sessions = listSessions(...)
for sessionId in sessions:
sessionWm = getWorkingMemory(sessionId)
log(sessionWm.messages.length)
For some reason sessionWm.messages.length is always 0. Is this intended? I have a test file that reproduces this I can show if needed. I figure it has to be something silly. I'm using the latest AMS docker image and latest SDK.
Here's a self-contained file you can run with bun to reproduce:
import { $ } from "bun";
await $`bun install agent-memory-client redis >/dev/null`;
const { MemoryAPIClient } = await import("agent-memory-client");
const { createClient } = await import("redis");
const AMS_URL = "http://localhost:8000";
const NAMESPACE = "ams-test";
const SESSION_ID = `test-session-${Date.now()}`;
function wait(ms = 1000) {
return new Promise(r => setTimeout(r, ms));
}
async function waitForAMS(maxRetries = 30, delayMs = 1000) {
const client = new MemoryAPIClient({ baseUrl: AMS_URL });
for (let i = 0; i < maxRetries; i++) {
try {
await client.healthCheck();
console.log("agent-memory-server is healthy");
return;
} catch {
console.log(
`Waiting for agent-memory-server... (${i + 1}/${maxRetries})`,
);
await wait(delayMs);
}
}
throw new Error("agent-memory-server failed to start");
}
async function main() {
console.log("Starting Redis and agent-memory-server...");
try {
await $`docker container stop ams-test-redis ams-test-ams >/dev/null`;
} catch {}
try {
await $`docker container remove ams-test-redis ams-test-ams >/dev/null`;
} catch {}
try {
await $`docker network rm ams-test >/dev/null`;
} catch {}
await $`docker network create ams-test >/dev/null`;
await $`docker run \
-p 6379:6379 \
--name ams-test-redis \
--network ams-test \
-d \
redis:alpine \
>/dev/null`;
for (let i = 0; i < 5; ++i) {
console.log(
`Waiting for redis to start... (${i + 1}/${5})`,
);
await wait(1000);
}
const redis = await createClient().connect();
await redis.flushDb();
await $`docker run \
-p 8000:8000 \
--name ams-test-ams \
--network ams-test \
-e REDIS_URL='redis://ams-test-redis:6379' \
-d \
redislabs/agent-memory-server:latest \
>/dev/null`;
await waitForAMS();
const client = new MemoryAPIClient({ baseUrl: AMS_URL });
console.log(`\nCreating working memory for session: ${SESSION_ID}`);
const wm = await client.getOrCreateWorkingMemory(SESSION_ID, {
namespace: NAMESPACE,
userId: "test-user",
});
console.log("Created working memory:", wm.session_id, "new:", wm.new_session);
const messages: { role: string; content: string }[] = [
{ role: "user", content: "Hello, how are you?" },
{
role: "assistant",
content: "I'm doing well, thanks for asking! How can I help you today?",
},
{ role: "user", content: "What's the capital of France?" },
{
role: "assistant",
content:
"The capital of France is Paris. It's known as the City of Light!",
},
{ role: "user", content: "Tell me a fun fact about Paris." },
{
role: "assistant",
content:
"The Eiffel Tower was originally intended to be a temporary structure, built for the 1889 World's Fair.",
},
];
console.log(`\nPutting ${messages.length} messages into working memory...`);
const updated = await client.putWorkingMemory(
wm.session_id,
{ messages, user_id: "test-user" },
{ namespace: wm.namespace! },
);
console.log(
"putWorkingMemory complete. Message count:",
updated.messages?.length,
);
for (let i = 0; i < 15; ++i) {
console.log(
`Waiting for agent-memory-server... (${i + 1}/${15})`,
);
await wait(1000);
}
console.log("\nListing sessions...");
const { sessions, total } = await client.listSessions({
namespace: NAMESPACE,
});
console.log(`Found ${total} session(s):\n`);
for (const sessionId of sessions) {
const sessionWm = await client.getWorkingMemory(sessionId, {
namespace: NAMESPACE,
});
console.log("=".repeat(60));
console.log(`Session: ${sessionId}`);
console.log(`Messages: ${sessionWm?.messages?.length ?? 0}`);
console.log(`Tokens: ${sessionWm?.tokens ?? "N/A"}`);
if (sessionWm?.messages) {
for (const msg of sessionWm.messages) {
console.log(` [${msg.role}] ${msg.content}`);
}
}
console.log("=".repeat(60));
}
await redis.close();
await $`docker container stop ams-test-redis ams-test-ams >/dev/null`;
await $`docker container remove ams-test-redis ams-test-ams >/dev/null`;
await $`docker network rm ams-test >/dev/null`;
await $`bun remove agent-memory-client redis >/dev/null`;
await $`rm -rf node_modules package.json >/dev/null`;
console.log("\nDone!");
}
try {
await main();
} catch (err) {
console.error("Test failed:", err);
process.exit(1);
};
I'm running into an issue with Agent Memory Server while using the TypeScript SDK. I'm not sure if it's an issue or a misunderstanding on my part about how things work. My workflow goes as follows:
For some reason
sessionWm.messages.lengthis always 0. Is this intended? I have a test file that reproduces this I can show if needed. I figure it has to be something silly. I'm using the latest AMS docker image and latest SDK.Here's a self-contained file you can run with
bunto reproduce: