redis / redis/agent-memory-server

getWorkingMemory returning empty messages (TypeScript SDK)

Open
#185 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug javascript
Dominant language
Python
Stars
316
Forks
63
Avg merge
14d 23h
Merged PRs (30d)
1

Description

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);
};

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the self-contained Bun reproduction against the Redis and agent-memory-server Docker containers. Compare the messages returned by putWorkingMemory with those from getWorkingMemory after listing the session. Done means the persisted session returns the messages that were written, or the intended empty-message behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, docker, redis, typescript
Domain
api, backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.