Featured image of post Agent Memory on GitHub Copilot

Agent Memory on GitHub Copilot

Agent memory helps GitHub Copilot remember context across sessions. This post explores how it works and which tools you can use to add persistent memory to your AI workflows.

When you work with GitHub Copilot in agent mode, every conversation starts with a limited context window. The model can only see what fits inside that window. If you switch threads, close the editor, or come back the next day, Copilot forgets the details you already explained. This is where agent memory becomes useful.

Agent memory gives your AI assistant a way to remember facts, preferences, and project context across sessions. Instead of repeating yourself, you can let Copilot store and retrieve important information when it needs it.

In this post, we will look at how agent memory works in GitHub Copilot and explore some popular tools that help you manage it.

Why Agent Memory Matters

Large language models are stateless. They do not remember anything between requests unless you send the previous conversation along with the new prompt. That works fine for short tasks, but it becomes painful for long-running projects.

Here are a few common problems:

  • Repeated explanations: You have to describe your coding style, project structure, or preferences every time.
  • Lost context: Decisions made in earlier sessions disappear, so Copilot suggests things that conflict with what you already agreed on.
  • Inconsistent output: Without memory, generated code drifts between sessions because the model has no stable reference.

Agent memory solves these problems by storing facts outside the model and loading them back into the context when needed.

How GitHub Copilot Handles Memory

GitHub Copilot supports memory through the Model Context Protocol (MCP). MCP is an open standard that lets Copilot connect to external tools and data sources. One of those tools is a memory server.

A memory server acts like a simple database for facts. When Copilot learns something useful during a conversation, it can ask the memory server to save it. Later, when a new conversation starts, Copilot can query the memory server to load relevant facts back into the context.

This approach has a few benefits:

  • Persistence: Memory survives across sessions, projects, and even devices.
  • Control: You decide what gets stored and what gets retrieved.
  • Portability: Because MCP is a standard, the same memory server can work with other clients that support MCP.

GitHub Copilot does not ship with a built-in memory store. You configure it by adding an MCP server to your setup. Each memory tool below can be added to Copilot independently, so you can choose the one that fits your workflow.

How MCP Servers Connect to Copilot

MCP servers are small programs that Copilot starts and talks to through standard input and output. In VS Code, you register an MCP server by adding an entry under the mcp.servers setting in settings.json. Copilot then discovers the tools exposed by that server and can call them during a chat session.

A typical MCP server entry looks like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "mcp": {
    "servers": {
      "my-memory": {
        "command": "npx",
        "args": ["-y", "package-name"],
        "env": {
          "SOME_API_KEY": "your-key"
        }
      }
    }
  }
}

You can add more than one memory server, but they will each have their own storage. In practice, pick one and use it consistently so Copilot does not get confused about where to store or retrieve facts.

The sections below show how to set up each tool separately in GitHub Copilot.

1. Server Memory

Server Memory is the official reference MCP server for memory. It stores facts as plain text in a JSON file on disk and exposes remember, recall, and forget tools.

Install and run

You do not need a global install. npx downloads and runs it on demand:

1
npx -y @modelcontextprotocol/server-memory

If you prefer, install it globally:

1
npm install -g @modelcontextprotocol/server-memory

Add to GitHub Copilot

Open VS Code settings (Ctrl + , or Cmd + ,), search for mcp, and add a server. Or edit settings.json directly:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "mcp": {
    "servers": {
      "memory": {
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-memory"],
        "env": {
          "MEMORY_FILE_PATH": "C:\\Users\\YourName\\.copilot-memory.json"
        }
      }
    }
  }
}

On macOS or Linux, use a path like /Users/YourName/.copilot-memory.json or /home/YourName/.copilot-memory.json.

Use in chat

Ask Copilot to store a fact:

Remember that this project uses MediatR for commands and queries.

In a later session, retrieve it:

What patterns does this project use?

You can also ask Copilot to forget something:

Forget that I wanted to use Dapper for data access.

When to use it

Choose Server Memory when you want a zero-dependency, file-based memory store. It is the fastest way to get persistent memory in Copilot and works offline.

2. Mem0

Mem0 is an open-source memory layer with a hosted option. It stores memories as structured entities and supports semantic search, so Copilot can find relevant facts even when the wording changes.

Install and run

Mem0 provides an MCP server package. Run it with npx:

1
npx -y @mem0/mcp

If you use the hosted version, create an API key at mem0.ai. For self-hosting, follow the Mem0 documentation to run the platform locally.

Add to GitHub Copilot

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "mcp": {
    "servers": {
      "mem0": {
        "command": "npx",
        "args": ["-y", "@mem0/mcp"],
        "env": {
          "MEM0_API_KEY": "your-api-key"
        }
      }
    }
  }
}

If you self-host, you may also need to set MEM0_API_URL to your local endpoint.

Use in chat

Mem0 understands user and project context. You can store preferences:

Remember that I prefer minimal XML documentation in C#.

Later, ask:

Generate a public method for this class.

Copilot can retrieve the preference and keep the XML docs light.

When to use it

Choose Mem0 when you want semantic search, user-specific memory, and a memory layer that improves over time. It is a good middle ground between simplicity and power.

3. Zep

Zep is a memory server built for conversational AI. Instead of storing raw messages, it extracts facts, summaries, and intent from conversations.

Install and run

You can run Zep locally with Docker:

1
docker run -d -p 8000:8000 -e ZEP_AUTH_SECRET=your-secret getzep/zep

Or use the hosted Zep Cloud and get an API key from the Zep dashboard.

Add to GitHub Copilot

For local Zep:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "mcp": {
    "servers": {
      "zep": {
        "command": "npx",
        "args": ["-y", "zep-mcp"],
        "env": {
          "ZEP_URL": "http://localhost:8000",
          "ZEP_API_KEY": "your-secret"
        }
      }
    }
  }
}

For Zep Cloud, replace ZEP_URL with the cloud endpoint and use your cloud API key.

Use in chat

Zep is designed around sessions. Start a thread, work with Copilot, and Zep will summarize the conversation automatically. In a new session, ask:

What did we decide about the authentication flow yesterday?

Copilot queries Zep and gets a summary instead of a raw message log.

When to use it

Choose Zep when your main problem is long conversation coherence. It is especially useful if you have extended back-and-forth sessions and want Copilot to remember what was decided without resending everything.

4. LangMem

LangMem is a memory framework from the LangChain team. It is built for LangGraph agents and treats memory as part of the agent graph.

Install and run

LangMem is primarily a Python library. Install it with pip:

1
pip install langmem

To use it with GitHub Copilot, you need to wrap LangMem in a small custom MCP server. A minimal wrapper exposes store_memory and retrieve_memory tools that call LangMem under the hood.

Example wrapper structure:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from mcp.server import Server
from langmem import MemoryManager

server = Server("langmem-copilot")
manager = MemoryManager()

@server.tool()
def store_memory(content: str):
    manager.add(content)
    return "stored"

@server.tool()
def retrieve_memory(query: str):
    return manager.search(query)

if __name__ == "__main__":
    server.run()

Save this as langmem_mcp.py and run it with Python.

Add to GitHub Copilot

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "mcp": {
    "servers": {
      "langmem": {
        "command": "python",
        "args": ["C:\\Users\\YourName\\tools\\langmem_mcp.py"],
        "env": {}
      }
    }
  }
}

Use in chat

Because LangMem is graph-oriented, you can store structured facts:

Remember that the payment service must be idempotent and uses Stripe webhooks.

Later:

How should the payment webhook handler behave?

Copilot retrieves the structured fact and applies it.

When to use it

Choose LangMem if you are already building agents with LangGraph and want memory to be a first-class node in your agent design. It requires more setup than the other options but gives you the most control.

5. Vercel AI SDK Memory

The Vercel AI SDK is not a direct Copilot plugin. It is a TypeScript toolkit for building AI applications, and it includes patterns for managing message history and long-term memory.

How it fits with Copilot

You cannot add the Vercel AI SDK to VS Code Copilot through an MCP server. Instead, you use it when you build your own Copilot-like web application. In that app, you store conversation history in a database and pass it back to the model on each request.

Example using the Vercel AI SDK with a Postgres message store:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import { getMessages, saveMessages } from './message-store';

export async function POST(req: Request) {
  const { message, sessionId } = await req.json();
  const history = await getMessages(sessionId);
  const messages = [...history, { role: 'user', content: message }];

  const result = streamText({
    model: openai('gpt-4o'),
    messages,
  });

  await saveMessages(sessionId, messages);
  return result.toDataStreamResponse();
}

When to use it

Choose the Vercel AI SDK when you are building a custom web application with AI chat and want full control over message history, storage, and retrieval. It is not a replacement for the MCP-based memory tools above, but it is the right tool if you are creating your own product.

Comparing the Options

Tool Best For Complexity Integration
Server Memory Quick setup, simple facts Low MCP
Mem0 Rich user and project memory Medium SDK or API
Zep Long conversation coherence Medium API
LangMem LangGraph agent workflows Medium to High LangChain
Vercel AI SDK Memory Custom web apps Medium TypeScript SDK

The right choice depends on your setup. If you just want Copilot to remember your preferences, start with server memory. If you are building a product with agents, Mem0 or Zep may be a better fit. If you are deep into LangGraph, LangMem is the natural choice.

When to Use Agent Memory

Agent memory is not always necessary. For one-off questions or small scripts, the default context window is enough. But memory becomes valuable when:

  • You work on the same codebase over many sessions.
  • You have strong conventions that Copilot should follow.
  • You want Copilot to learn from corrections and feedback.
  • You are building an agent that interacts with users over time.

Start small. Store a few key facts about your project and see if Copilot’s suggestions improve. You can always expand later.

Conclusion

Agent memory turns GitHub Copilot from a stateless assistant into a tool that learns and adapts to your project. By using an MCP memory server or a dedicated memory tool, you can keep important context alive across sessions.

Server memory is the simplest way to get started. If you need more power, tools like Mem0, Zep, and LangMem offer richer memory models. Choose the one that matches your architecture and how much control you need.

Memory is still an evolving area in AI tooling. The best approach today is to experiment, store what matters, and keep your memory layer simple enough to understand and maintain.

Built with Hugo
Theme Stack designed by Jimmy