Skip to content

Repository files navigation

AI Memory Lab

A reference implementation of cognitive memory architectures for AI agents, built with Next.js and the Vercel AI SDK.

AI Memory Lab Banner

📖 Companion blog post: How Agents Actually Remember Things: The 4 Pillars of AI Memory


Key Implementations

  • Working Memory: Context-window management (src/store/chat-store.ts)
  • Semantic Memory: System prompt dynamic rule injection (src/app/api/chat/route.ts)
  • Procedural Memory: Progressive skill loading via tool calling (src/lib/memory/skills.ts, src/lib/skills-registry.ts)
  • Episodic Memory: Live, turn-by-turn conversational state distillation (src/lib/memory/episodic.ts)

Tech Stack

  • Next.js 16 (App Router, Turbopack, React Compiler)
  • Vercel AI SDK v7 (streamText, useChat)
  • OpenRouter (Model gateway API)
  • Zustand + Persist (Local storage state persistence)
  • Zod (Request boundary validation)
  • shadcn/ui + Base UI (Primitive component layouts)
  • tokenlens (Token and API cost calculations)
  • skills.sh (Live procedural skill registry)

Getting Started

Requires Bun.

git clone https://github.com/devyanshyadav/ai-memory-lab.git
cd ai-memory-lab
bun install
cp .env.example .env.local

Add your OpenRouter API key to .env.local:

OPENROUTER_API_KEY=sk-or-v1-...

Run the development server:

bun dev

Open http://localhost:3000.


Project Structure

src/
├── app/
│   ├── api/
│   │   ├── chat/route.ts              # System prompt builder and main stream endpoint
│   │   └── skills-registry/           # search & import API routes
│   └── page.tsx                       # UI components and message submission
├── components/
│   ├── memory-inspector.tsx           # Resizable memory debugger panel
│   └── skill-importer.tsx             # Skill registry search UI
├── lib/
│   ├── memory/
│   │   ├── skills.ts                  # Procedural skill schemas
│   │   └── episodic.ts                # Episodic memory consolidation logic
│   ├── skills-registry.ts             # skills.sh API wrapper
│   └── chat-schema.ts                 # Type definitions & Zod schemas
└── store/
    └── chat-store.ts                  # Zustand state persistence

Scripts

bun dev      # start dev server
bun build    # compile production bundle
bun start    # run production bundle
bun lint     # run Biome checks
bun format   # run Biome formatting

License

MIT © Devyansh Yadav

Author

Devyansh Yadavdevyanshyadav.com · GitHub

Releases

Packages

Contributors

Languages