npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@namitjain.india/agent-memory-react

v0.3.0

Published

React hook utilities for agent-memory

Readme

@namitjain.india/agent-memory-react

npm version License: MIT GitHub stars

React hook utilities for @namitjain.india/agent-memory. Provides easy stateful integration with React applications.

GitHub | Report Bug | Request Feature

Installation

npm install @namitjain.india/agent-memory-react react

Usage

import { useMemory } from "@namitjain.india/agent-memory-react";

function Chat() {
  const {
    messages,
    setMessages,
    remember,
    recall,
    forget,
    inject,
    memory
  } = useMemory("user-123", {
    embedding: {
      embedFn: async (text) => [text.length / 100, 0.5]
    }
  });

  const onUserMessage = async (content: string) => {
    // Remember the user message
    await remember({ role: "user", content });

    // Recall relevant memories
    const context = await recall(content, { topK: 4 });

    // Inject context into messages and send to LLM
    const enhancedMessages = await inject([
      ...messages,
      { role: "user", content }
    ], { query: content });

    // ... send to LLM and get response
  };

  return (
    <div>
      <p>Messages: {messages.length}</p>
      <p>Memory items: {(await memory.getBySession()).length}</p>
    </div>
  );
}

useMemory

const result = useMemory(sessionId, options);

Parameters

| Parameter | Type | Description | |-----------|------|-------------| | sessionId | string | Unique session identifier | | options | UseMemoryOptions | Configuration options |

Options

Extends AgentMemoryOptions from the core package, with these additions:

| Option | Type | Description | |--------|------|-------------| | memory | AgentMemory | Provide custom AgentMemory instance | | initialMessages | MemoryMessage[] | Initial messages array |

Return Value

| Property | Type | Description | |----------|------|-------------| | messages | MemoryMessage[] | Current message state | | setMessages | Dispatch<SetStateAction<MemoryMessage[]>> | Set messages directly | | remember | (input) => Promise<MemoryItem> | Store a memory | | recall | (query, options?) => Promise<RecallResult[]> | Retrieve memories | | forget | (id: string) => Promise<void> | Delete a memory | | inject | (messages, options?) => Promise<MemoryMessage[]> | Inject memories into messages | | memory | AgentMemory | Direct access to AgentMemory instance |

remember

Store memories. Automatically updates the messages array for entries.

// Store conversation entry
await remember({
  role: "user",
  content: "Hello!",
  importance: 0.8
});

// Store a fact
await remember({
  kind: "fact",
  key: "preferred_language",
  value: "TypeScript"
});

recall

Retrieve relevant memories using semantic search.

const results = await recall("What do I prefer?", {
  topK: 3,
  kinds: ["entry", "fact"]
});

forget

Delete a memory by ID.

await forget("memory-entry-id");

inject

Inject retrieved memories as a system message.

const enhanced = await inject(currentMessages, {
  query: "last message content",
  topK: 3
});

Direct Memory Access

For advanced use cases, access the underlying AgentMemory instance:

const { memory } = useMemory("session-1");

// Call any AgentMemory method directly
await memory.summarise({ sessionId: "session-1" });
const allMemories = await memory.getBySession();

Example: Complete Chat Component

import { useState } from "react";
import { useMemory } from "@namitjain.india/agent-memory-react";

export function Chat() {
  const [input, setInput] = useState("");
  const { messages, remember, recall, inject, memory } = useMemory("chat-1", {
    embedding: { embedFn: async (t) => [t.length / 100] }
  });

  const sendMessage = async () => {
    if (!input.trim()) return;

    // Store user message
    await remember({ role: "user", content: input });

    // Inject context and prepare for LLM
    const withContext = await inject(
      [...messages, { role: "user", content: input }],
      { topK: 5 }
    );

    // Simulate LLM call
    const response = "I remember you prefer TypeScript!";

    // Store assistant response
    await remember({ role: "assistant", content: response });

    setInput("");
  };

  return (
    <div>
      <div className="messages">
        {messages.map((m, i) => (
          <div key={i} className={m.role}>
            {m.content}
          </div>
        ))}
      </div>
      <input
        value={input}
        onChange={(e) => setInput(e.target.value)}
        onKeyDown={(e) => e.key === "Enter" && sendMessage()}
      />
      <button onClick={sendMessage}>Send</button>
    </div>
  );
}

Requirements

  • React >= 18.0.0 or React >= 19.0.0
  • @namitjain.india/agent-memory >= 0.1.0

Contributing & Collaboration

We welcome contributions, feedback, and feature requests!

If this project helps you, please consider starring it on GitHub!

License

MIT