Urgent.News

What's breaking now, across thousands of outlets.

Tech

Agent Memory in TypeScript: Short-Term, Long-Term, and What to Throw Away

Book: AI That Plans The series: AI in TypeScript — 5 books, from your first LLM call to agents in production — all five here My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub "Agent memory" gets implemented as one array of messages that grows until something truncates it. That single array is doing three jobs that…

Abstract editorial illustration

The implementation of "agent memory" in TypeScript is represented by a single array of messages that expands until a certain point, at which point something forces it to truncate. This one array handles three tasks with varying durations of relevance, access patterns, and failure points, which is why the truncation always appears to be random. In order to resolve this issue, it is recommended to separate the three functions, each with its own distinct lifetime and access pattern.

There are three distinct types of memory: working memory, long-term memory, and episodic memory. Working memory contains the message window sent in the current turn and is only available to the model during that specific run. Long-term memory retains durable information about the user or the domain, which is not sent to the model all at once but retrieved selectively. Episodic memory records previous runs and is mainly used for debugging, analytics, and evaluations, rarely sent to the model.

Separating these three types of memory into their respective interfaces – WorkingMemory, LongTermMemory, and EpisodicMemory – clarifies their distinct purposes and eliminates the common mistake of conflating them. The WorkingMemory interface includes functions to manage the message window, append new messages, and compact the memory based on a given budget.

The LongTermMemory interface allows for recalling, remembering, and forgetting facts, while the EpisodicMemory interface provides methods for recording and finding specific runs.

By implementing separate interfaces for each type of memory, it becomes clear that a single Memory interface with get/set methods is the root cause of the confusion. The working memory, with its budget, handles the current message window, while long-term memory deals with durable user or domain facts and episodic memory stores records of past runs for various purposes.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Citations That Survive a TypeScript Refactor

Book: AI That Reads The series: AI in TypeScript — 5 books, from your first LLM call to agents in production — all five here My project: Hermes IDE | GitHub — an IDE for developers who ship with…

  • Citations break when chunk size or reranker changes
  • SourceRef type includes docId, contentHash, start, end, revision
  • Cited<T> ensures every claim has a source

More from Thursday 6 August →