Agents Memory Client

Classes

Classes

AgentMemoryClient

Agent Memory Client

Manages conversation memory using Redis Agent Memory Server (AMS)

Constructor

constructor(config: AgentMemoryClientConfig)

Parameters:

ParameterTypeRequiredDescription
configAgentMemoryClientConfigYes- Client configuration

Methods

healthCheck

Check if Agent Memory Server is healthy

healthCheck(): Promise<boolean>

Returns:

Promise<boolean> - Promise<boolean> - True if healthy, false otherwise

readWorkingMemory

Read working memory from AMS

readWorkingMemory(sessionId: string, namespace?: string | undefined): Promise<AmsMemory | null>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes- Session ID to retrieve memory for
namespacestring | undefinedNo- Optional namespace (defaults to configured defaultNamespace)

Returns:

Promise<AmsMemory \| null> - Promise<AmsMemory | null> - Memory object or null if not found

replaceWorkingMemory

Replace working memory in AMS

Uses PUT /v1/working-memory/{session_id}

replaceWorkingMemory(sessionId: string, contextWindowMax: number, memory: AmsMemory, namespace?: string | undefined): Promise<AmsMemory | null>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes- Session ID to update
contextWindowMaxnumberYes- Maximum context window size in tokens
memoryAmsMemoryYes- Memory object to store
namespacestring | undefinedNo- Optional namespace (defaults to configured defaultNamespace)

Returns:

Promise<AmsMemory \| null> - Promise<AmsMemory | null> - Updated memory object or null on failure

removeWorkingMemory

Remove working memory from AMS

Uses DELETE /v1/working-memory/{session_id}?namespace=xxx

removeWorkingMemory(sessionId: string, namespace?: string | undefined): Promise<boolean>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes- Session ID to remove
namespacestring | undefinedNo- Optional namespace (defaults to configured defaultNamespace)

Returns:

Promise<boolean> - Promise<boolean> - True if removed successfully, false otherwise

addMessage

Add a message to AMS and get updated memory

This method:

  1. GETs existing memory for the session
  2. Appends the new message to the messages array
  3. PUTs the updated memory back to AMS

AMS will automatically summarize if context window is exceeded.

addMessage(sessionId: string, namespace: string, role: AmsRole, content: string, contextWindowMax?: number | undefined): Promise<AmsMemory | null>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes- Session ID to add message to
namespacestringYes- Namespace for this session
roleAmsRoleYes- Role of the message (user, assistant, system)
contentstringYes- Content of the message
contextWindowMaxnumber | undefinedNo- Optional context window max (uses config default if not provided)

Returns:

Promise<AmsMemory \| null> - Promise<AmsMemory | null> - Updated memory object or null on failure

getMemoryPrompt

Get memory-enhanced prompt ready for LLM

Uses AMS Memory Prompt API to build messages with conversation context POST /v1/memory/prompt

getMemoryPrompt(params: MemoryPromptRequest): Promise<MemoryPromptResponse | null>

Parameters:

ParameterTypeRequiredDescription
paramsMemoryPromptRequestYes- Memory prompt parameters

Returns:

Promise<MemoryPromptResponse \| null> - Promise<MemoryPromptResponse | null> - Messages array or null on failure

listSessions

List all sessions for a namespace

GET /v1/working-memory?namespace=xxx

listSessions(namespace: string, options?: ListSessionsOptions | undefined): Promise<SessionListResponse>

Parameters:

ParameterTypeRequiredDescription
namespacestringYes- Namespace to list sessions for
optionsListSessionsOptions | undefinedNo- Optional filtering and pagination

Returns:

Promise<SessionListResponse> - Promise<SessionListResponse> - List of sessions

createLongTermMemories

Create one or more long-term memories

POST /v1/long-term-memory/

createLongTermMemories(memories: CreateLongTermMemoryParams[]): Promise<LongTermMemory[]>

Parameters:

ParameterTypeRequiredDescription
memoriesCreateLongTermMemoryParams[]Yes- Array of memories to create

Returns:

Promise<LongTermMemory[]> - Promise<LongTermMemory[]> - Created memories

createLongTermMemory

Create a single long-term memory

Convenience wrapper around createLongTermMemories

createLongTermMemory(params: CreateLongTermMemoryParams): Promise<LongTermMemory | null>

Parameters:

ParameterTypeRequiredDescription
paramsCreateLongTermMemoryParamsYes- Memory parameters

Returns:

Promise<LongTermMemory \| null> - Promise<LongTermMemory | null> - Created memory or null on failure

searchLongTermMemory

Search long-term memories

POST /v1/long-term-memory/search

searchLongTermMemory(params: SearchLongTermMemoryParams): Promise<SearchLongTermMemoryResponse>

Parameters:

ParameterTypeRequiredDescription
paramsSearchLongTermMemoryParamsYes- Search parameters

Returns:

Promise<SearchLongTermMemoryResponse> - Promise<SearchLongTermMemoryResponse> - Search results

forgetMemories

Forget (delete) long-term memories based on policy

POST /v1/long-term-memory/forget

forgetMemories(params: ForgetMemoriesParams): Promise<ForgetMemoriesResponse>

Parameters:

ParameterTypeRequiredDescription
paramsForgetMemoriesParamsYes- Forget parameters with policy and filters

Returns:

Promise<ForgetMemoriesResponse> - Promise<ForgetMemoriesResponse> - Deletion results

deleteLongTermMemory

Delete a specific long-term memory by ID

Convenience method that uses forgetMemories with a specific memory ID filter

deleteLongTermMemory(memoryId: string, namespace: string): Promise<boolean>

Parameters:

ParameterTypeRequiredDescription
memoryIdstringYes- ID of the memory to delete
namespacestringYes- Namespace the memory belongs to

Returns:

Promise<boolean> - Promise<boolean> - True if deleted successfully

searchAllMemory

Search across all memory types (working memory and long-term memory)

Performs parallel searches across both memory stores and combines results. For working memory, performs client-side text matching on session messages. For long-term memory, uses semantic vector search via AMS API.

searchAllMemory(params: SearchAllMemoryParams): Promise<SearchAllMemoryResponse>

Parameters:

ParameterTypeRequiredDescription
paramsSearchAllMemoryParamsYes- Search parameters

Returns:

Promise<SearchAllMemoryResponse> - Promise<SearchAllMemoryResponse> - Combined search results

Examples:

const results = await client.searchAllMemory({
  query: 'user preferences for dark mode',
  namespace: 'org-123',
  includeLongTermMemory: true,
  includeWorkingMemory: true,
  limit: 10,
});

results.results.forEach(result => {
  console.log(`[${result.source}] ${result.text} (score: ${result.score})`);
});

buildContextPrompt

Build a formatted context prompt from memory

Useful for constructing prompts with conversation history

buildContextPrompt(memory: AmsMemory): string

Parameters:

ParameterTypeRequiredDescription
memoryAmsMemoryYes- Memory object from AMS

Returns:

string - string - Formatted context prompt

getConfig

Get the current configuration

getConfig(): Readonly<Required<Omit<AgentMemoryClientConfig, "authToken">> & Pick<AgentMemoryClientConfig, "authToken">>

Returns:

Readonly<Required<Omit<AgentMemoryClientConfig, "authToken">> & Pick<AgentMemoryClientConfig, "authToken">> - AgentMemoryClientConfig - Current configuration

Examples:

const client = new AgentMemoryClient({
  baseUrl: 'http://agent-memory-server:8000',
  contextWindowMax: 10000,
});

// Check health
const isHealthy = await client.healthCheck();

// Add a message
const memory = await client.addMessage(
  'session-123',
  'default',
  AmsRole.USER,
  'Hello, how are you?'
);

// Read working memory
const currentMemory = await client.readWorkingMemory('session-123', 'default');
Previous
Types