Home/AI/ML Notes/Basics of Agents/Agent Memory & Context Management
⌂ Main Page
Basics of Agents

Agent Memory & Context Management

Short- and long-term memory, cross-agent memory, and why context management is a hard necessity.

On this page

AI Agent Memory

Persistent memory across sessions => users don’t repeatedly explain project context, preferences, and past decisions.

Types

Working Memory - Short-term, in-context scratchpad to hold the current task state, parameters, intermediate thoughts, and next steps while the agent reasons (to prevent context bloating)

Long-Term Memory - Persistent storage across sessions to retain knowledge and experience so the agent can recall information later.

Memory Operations
Working m. - Save task state (offload progress), load task state (resume work). Long-term m. - retrieve from long-term memory (contextual recall), and save to long-term memory (persist new knowledge).

Storage Options

Memory Flow

Limitations: memory bloat over time (needs pruning strategies), remove outdated memory, embedding quality affects retrieval accuracy

Cross-Agent Memory

Memory enhancement for multi-agent ecosystem (like GitHub Copilot which spans coding, CLI, code review, security, debugging, deployment, maintenance agents) - cross-agent memory allows agents to remember / learn across the entire development cycle, reducing the need to re-establish context at the start of each session by allowing validated information to persist across agentic workflows.

Cross-Agent Memory Lifecycle

  1. Creation: Agents invoke Memory API’s store_memory tool to store a fact in the Memory DB when LLM discovers actionable patterns (e.g., a special logging convention or how to handle databases). Decentralized learning: example - Copilot code review finds a pattern (e.g., "Log files must follow app-YYYYMMDD.log"). Copilot coding agent later verifies and applies it to a new service. Copilot CLI uses it to locate debug logs.

  2. Storage with Citations: Memories include references to specific code locations supporting the fact.

{ subject: "API version synchronization",
fact: "API version must match between client SDK, server routes, and documentation.",
citations: ["src/client/sdk/constants.ts:12", "server/routes/api.go:8", "docs/api-reference.md:37"],
reason: "If the API version is not kept properly synchronized, the integration can fail or exhibit subtle bugs. Remembering these locations will help ensure they are kept syncronized in future updates." }

  1. Retrieval: At session start, the system retrieves recent repository memories and injects them into the agent prompt.

  2. Verification: At retrieval time before use, agents verify citations dynamically against the current codebase to ensure info is relevant and to prevent invalid data (from abandoned branches) or memory attacks.

A diagram of a memory process AI-generated content may be incorrect.

Reference: https://github.blog/ai-and-ml/github-copilot/building-an-agentic-memory-system-for-github-copilot/

Context Management - not optimization, but a necessity (OpenAI)

Tool calling is easy, context survival is the real challenge. Successful agents - long-run context, tools, memory and caching stay stable as complexity grows. Manus AI solved it => Meta purchase them.

Source: here (see attached pdf there for details).