MSBA-371 · Lesson 1 of 12 · 27 min

Memory and state

▶ Video coming soon A video version of this lesson is on the way.

The Thursday agent design sessions at Tidewater Trail Guides in Moncton did not stop when the first course ended. Priya Nair kept the same afternoon, the same meeting room with the whiteboard that never quite erases, and the same regulars: Malik Osei, who maintains the volunteer-built trail-report tools; Dmitri Kovac, who wrote the trail-units action; and Lena Fischer, who had finished the Actions clinic and now wanted the agent certification as well. Seraphine Kowalik-Duarte, the application security engineer from Skerry Outdoor Group, the retailer that sponsors Tidewater's TrailCheck app, still joined some sessions by video to show how a company with more than a thousand developers handles the same questions.

The first course, Agentic AI in the Software Lifecycle: Architecture and Tools, covered what agents are, how they use tools and the Model Context Protocol, how they are contained, and how the GitHub Copilot cloud agent and custom agents work. This course takes the four GH-600 domains that remain: managing memory, state and execution; evaluation, error analysis and tuning; orchestrating several agents; and guardrails and accountability. It ends with a case study in which Tidewater and Skerry design an agent team for code review.

Malik opened the first session with a complaint. On Tuesday he had asked an agent in his editor to move the trail-report validator's date parsing into its own module and add tests. The session ran long, the editor restarted for an update, and when he asked the agent to carry on it started again from the beginning: it re-read every file, proposed a different module name, and began rewriting a test he had already accepted. Nothing was lost in the repository, because Git still held his commits, but forty minutes of reasoning had vanished. "It had no idea what it had already decided," he said. That sentence is the subject of this lesson.

Why agents need memory at all

A language model has no memory of its own between calls. Each time the controller sends a request, the model sees only what is in that request: the system prompt, the instructions, the conversation so far, the results of tool calls, and anything else the controller chose to include. Everything an agent appears to remember is something the controller put back into the context, or something the agent can read again with a tool. When people say an agent remembers, they mean one of those two things.

That makes memory a design decision rather than a property of the model. Someone, either the product team that built the agent or the team that configures it, decides what is kept, where it is kept, for how long, who can see it and when it is thrown away. The GH-600 study guide puts these decisions in its domain on managing memory, state and execution, worth 10 to 15 percent of the exam, and asks candidates to choose between short-term, long-term and external memory, to scope memory to what the task needs, and to define rules for expiry, pruning and reset.

Four kinds of memory

It helps to separate four kinds of memory, because each fails in a different way and each is controlled by different settings.

Four kinds of agent memory. Short-term memory is rebuilt at every step; external memory is the only kind people can read and correct with ordinary tools.
KindWhere it livesHow long it lastsTypical failure
Working context (short-term)The current context window: instructions, conversation, recent tool resultsOne model call; rebuilt by the controller for every stepOverflows or gets summarized, so early decisions drop out
Session stateThe controller's record of the session: plan, steps taken, files touched, session logOne session; sometimes resumableLost on restart, or resumed against a repository that has since changed
Long-term memoryA store the product keeps across sessions, such as Copilot MemoryDays to weeks, under expiry rulesStale or wrong facts carried into later work
External memoryOrdinary artifacts the agent reads and writes: files, issues, pull requests, commit messages, wikisAs long as the artifact existsNobody updates it, or two artifacts disagree
Four horizontal bands stacked from top to bottom: working context, session state, long-term memory and external memory. An arrow on the left runs from short-lived at the top to durable at the bottom. On the right each band lists an example: the current prompt and tool results, the plan and session log, Copilot Memory facts, and files, issues and pull requests.
The four kinds of memory from shortest-lived to most durable. Each band is controlled by different settings.

Working context is what the model sees in a single call. It is limited by the model's context window, and the controller fills it with a mixture of fixed material (system prompt, custom instructions, the task) and growing material (the conversation and tool results). When the growing part gets too large the controller must drop or summarize something. Many agent products compact the history automatically, replacing old turns with a summary. Compaction keeps the session going but it is lossy: a decision explained in one long tool result may survive only as a phrase, or not at all.

Session state is the controller's own record. For the Copilot cloud agent it includes the branch, the commits it has pushed, the plan it is following and the session log that anyone with access can read. For an editor agent it may be the chat history saved with the workspace. Session state usually survives a pause, but not always a crash, an update or a move to another tool, which is exactly what happened to Malik.

Long-term memory is kept by the product across sessions. GitHub's version is Copilot Memory, described below. Long-term memory saves the agent from rediscovering the same facts in every session, but it can also carry yesterday's truth into today's work.

External memory is anything in the world the agent can read and write with its ordinary tools. A plan written to a file in the branch, a checklist in the pull request description, a comment on the issue, a commit message that explains a decision: all of these are memory, and they have one large advantage over the other kinds. People can read them, review them, correct them and keep them under version control.

Copilot Memory

Copilot Memory is GitHub's long-term memory for its agents. It was in public preview at the time of writing; GitHub announced the preview on January 15, 2026, turned it on by default for Copilot Pro and Pro+ users on March 4, 2026 and added more deletion controls on May 28, 2026. It stores two kinds of information.

Repository facts are things Copilot has learned about a particular repository while working in it: coding conventions, architecture decisions, build and test commands, and project rules. A repository fact can be used only in that repository, and it is stored with a citation that links it to the code that supports it. Before Copilot uses a fact it validates the citation against the current branch, and it uses only facts that validate. If the code that supported a fact has changed, the fact is not used. Facts learned from a pull request that was closed without merging are validated in the same way, so they cannot leak unmerged ideas into later work unless the code supports them.

User preferences are things Copilot has learned about how a particular person likes to work. They follow the user across repositories.

Several Copilot features share the same memory. The Copilot cloud agent and Copilot CLI use both repository facts and user preferences; Copilot code review uses repository facts only; agentic autofix also draws on memory. A fact learned by one feature can be used by another, so a build command the cloud agent discovered on Monday can help Copilot code review on Tuesday.

Copilot Memory as documented by GitHub in 2026, when it was in public preview on all paid Copilot plans. Check the current documentation before relying on preview details.
QuestionWhat GitHub documents
What is stored?Repository facts (conventions, architecture decisions, build commands, project rules) and user preferences
Where can a repository fact be used?Only in the repository it came from, and only if its citation validates against the current branch
How long does an entry last?Entries that are not used are deleted automatically after 28 days; successful validation and use reset the timer
Who turns it on?It is enabled per user; on by default for individual plans, while organization and enterprise plans need an administrator policy first, after which users can opt out
Who can delete entries?Users delete their own preferences; Copilot Business and Enterprise administrators can export or delete them; repository owners review and delete repository facts
Which features use it?The cloud agent and Copilot CLI (both kinds), Copilot code review (repository facts only) and agentic autofix

Two design choices in Copilot Memory answer exam objectives directly. The 28-day expiry is an expiration rule: memory that is not used fades on its own, so the store does not fill with facts about a build system the team abandoned last spring. Citation validation is a guard against stale context: a fact is only as good as the code that supports it, and when that code changes the fact stops being used. Both are worth copying when you design memory for your own agents.

Scoping memory to the task

More memory is not better memory. Every fact placed in the context competes for the model's attention with the task itself, and irrelevant facts can steer an agent the wrong way. A model told that the project uses tabs, that Owen prefers British-style quotation marks in guidebook prose and that the deploy workflow needs a manual approval may apply the quotation-mark rule to JavaScript strings. The exam phrase is scoping memory to task-relevant information, and it has three practical parts.

Scope by place. Facts about one repository should be available only in that repository. Copilot Memory does this for repository facts. Path-specific instruction files do it inside a repository: rules for test files live in a file whose front matter applies only to test paths, so they appear in the context only when the agent works on tests.

Scope by role. A custom agent that writes documentation does not need the release checklist, and a security reviewer does not need the guidebook style guide. Giving each custom agent its own instructions and tool list keeps each context small.

Scope by time. Some facts are true only for a while: a feature freeze before a release, a temporarily disabled test, a migration in progress. Write them where they will expire with the work, such as the issue or pull request, rather than in permanent instructions that someone must remember to edit later.

Expiry, pruning and reset

Every memory store needs three rules, and the exam asks for all three by name.

An expiration rule says when an entry stops being trusted. It can be time-based, like Copilot Memory's 28 days without use, or event-based, such as "forget facts about the build when the build files change".

A pruning rule says how the store is kept small and accurate while entries are still valid. For a context window, pruning means dropping or summarizing old tool output that no longer matters. For a team's external memory it means someone reviews the notes file, the instructions and the stored facts, and removes what is wrong or duplicated. Repository owners can review and delete repository facts in Copilot Memory for exactly this reason.

A reset rule says when to start clean. Reset is the right answer when memory is contaminated: the agent has absorbed a wrong assumption and keeps acting on it, a prompt injection has planted instructions in the conversation, or the task has changed so much that the old context does more harm than good. Starting a new session with a short, correct summary is often faster than arguing with a long, confused one.

Worked problem

Writing memory rules for TrailCheck

Priya asked the group to write expiry, pruning and reset rules for the TrailCheck repository, which uses the Copilot cloud agent, Copilot code review and Copilot Memory.

Show solution
  1. Expiry: Lena noted that Copilot Memory already expires unused facts after 28 days and validates citations. The team added one event-based rule of its own: when package.json or the workflow files change, whoever reviews the pull request also checks the build section of AGENTS.md.
  2. Pruning: Dmitri volunteered to review the repository facts list and the instruction files on the first Thursday of each month, removing duplicates and anything contradicted by the code. He noted that a stale instruction file is worse than a stale memory entry, because instructions are never validated against the code.
  3. Reset: Malik wrote the rule he had wanted on Tuesday, in reverse. If an agent repeats work it has already done, or argues for an approach the team has rejected, stop the session and start a new one from the written plan rather than correcting it turn by turn.
  4. Scope: rules that apply only to the map tiles went into a path-specific instruction file for that folder rather than the repository-wide file.

Durable artifacts: writing state down

The second objective in this domain is to persist agent state and manage context drift. The most reliable way to persist state is to write it into ordinary artifacts as the work happens. When Malik's editor restarted, everything the agent had decided lived only in the conversation. If the agent had kept a short plan in a file in the branch, with each step ticked as it was finished and each decision noted with a reason, the new session could have read that file and carried on.

The Copilot cloud agent works this way by design. It records its plan and progress in the pull request description as a checklist, pushes commits as it goes, and keeps a session log. A reviewer or a later session can see what was planned, what is done and what is left. You can ask any agent to do the same: keep a progress file, update it after each step, and record decisions with their reasons.

A progress file kept in the branch (PLAN.md). Ticked steps, recorded decisions and open questions let a new session resume without repeating or diverging.
# Plan: move date parsing out of validate.js

Goal: date parsing lives in src/dates.js with its own tests; results unchanged.

## Steps
- [x] 1. Add src/dates.js with parseReportDate() copied from validate.js
- [x] 2. Point validate.js at the new module
- [ ] 3. Move the six date tests to test/dates.test.js
- [ ] 4. Add tests for 29 February and two-digit years
- [ ] 5. Run npm test and npm run lint

## Decisions
- Module name is dates.js, not date-utils.js (matches src/units.js naming). Agreed by Malik.
- Keep the old export in validate.js for one release; the trail-report action imports it.

## Open questions
- Should two-digit years be rejected or read as 20xx? Asked on the issue.

A good progress artifact has a few properties. It states the goal and what done means. It lists steps small enough to tick off. It records decisions with reasons, because a later session that sees only the outcome may undo it. It lists open questions so that nobody, human or agent, quietly answers them by guessing. And it lives with the work, in the branch or the pull request, so it moves with the code and is reviewed with it.

Commit messages are a second durable record. An agent that commits after each step, with a message that says what changed and why, leaves a trail that both people and later sessions can follow with ordinary Git commands.

Resuming without repeating or diverging

Resuming means starting a new context from durable state rather than from nothing. A good resume has three steps. First, read the record: the plan file, the pull request description, recent commits and any review comments. Second, check the record against reality: is the branch still where the record says? Have others pushed commits? Has the base branch moved? Third, continue from the first unfinished step, re-running checks on finished steps only if something has changed underneath them.

The check against reality matters because a record can go stale while the session is paused. If Dmitri merged a change to validate.js on Wednesday, Malik's plan from Tuesday may now be wrong. An agent that resumes without checking will carry on confidently with a plan that no longer fits, which is a form of context drift.

Context drift

Context drift is the gradual divergence between what the agent believes and what is true, or between what the agent is doing and what it was asked to do. It has several sources: compaction that loses early decisions, a base branch that moves under a long session, tool results that the agent misread and then built on, a user's later message that quietly changes the goal, and instructions that conflict with each other.

Drift is easiest to detect against a written goal. Signals include the agent touching files outside the plan, re-opening decisions already recorded, proposing names or structures different from the ones it chose earlier, repeating steps it has already finished, and a growing gap between the plan's checklist and the commits. Reviewers can compare the diff with the plan; the controller can compare the files changed with the files the plan named.

Correcting drift depends on how far it has gone. A small drift can be corrected with a steering message that restates the goal and the recorded decision. A larger drift, especially one built on a wrong assumption, usually needs a reset: stop the session, fix the plan file so the wrong assumption is gone, and start a new session from the corrected plan.

Continuity across tools and environments

Tidewater's developers move between tools during the same piece of work. Malik might start a task in his editor, hand it to the cloud agent overnight, and look at the result in Copilot CLI on a train. The GH-600 outline asks how to share state across tools and environments while preventing conflicting and stale context.

The answer is mostly external memory again. Each tool has its own session state, and those states do not merge. What every tool can read is the repository and its pull requests and issues. So the shared state should live there: the plan file in the branch, decisions in the pull request, the definition of done in AGENTS.md or the repository instructions, and conventions in files every agent reads.

Conflicting context happens when two sources disagree: the repository instructions say to use the built-in test runner while an older AGENTS.md in a subfolder still mentions Jest, or a user preference says one thing and a path-specific rule says another. Prevent it by keeping one source of truth for each topic and pointing to it from the others, and by reviewing instruction files like code. Stale context happens when a source was once right and is now wrong. Prevent it with expiry and validation, like Copilot Memory's citations, and by putting short-lived facts where they expire with the work.

Three tool boxes across the top: editor agent, cloud agent and Copilot CLI. Each has its own small box labelled session state that does not connect to the others. Arrows from all three tools lead down to one shared box labelled repository and pull request, containing plan file, commits, PR description and instructions.
Each tool keeps its own session state, but all of them can read the repository and pull request. Shared state belongs there.

Seraphine added Skerry's version. Skerry's developers use several agents, including the Copilot cloud agent and third-party agents allowed by the enterprise, and their platform team decided early that no agent's private memory would be treated as the source of truth. Anything an agent learns that matters must end up in a reviewed file or on the pull request. "Private memory is a cache," she said. "The repository is the record."

Common mistakes

  • MistakeAssuming the model remembers previous sessions on its own.

    InsteadModels are stateless between calls; memory is whatever the controller puts back into the context or the agent reads with a tool.

  • MistakePutting every known fact into the repository-wide instructions.

    InsteadScope memory by place, role and time: path-specific files, per-agent instructions, and short-lived facts on the issue or pull request.

  • MistakeCorrecting a confused session turn by turn for an hour.

    InsteadReset: fix the written plan and start a new session from it.

  • MistakeResuming from a plan file without checking whether the branch or base has moved.

    InsteadRead the record, check it against the repository, then continue from the first unfinished step.

  • MistakeTreating an agent's private long-term memory as the team's record of decisions.

    InsteadWrite decisions into reviewed artifacts such as the plan, the pull request and instruction files.

Summary and key terms

  • Agents remember only what the controller puts back in the context or what they can read again with tools.
  • Working context, session state, long-term memory and external memory last for different times and fail in different ways.
  • Copilot Memory stores validated, cited repository facts and user preferences, and deletes unused entries after 28 days.
  • Memory needs expiry, pruning and reset rules, and should be scoped by place, role and time.
  • Durable artifacts such as a plan file, the pull request checklist and commit messages let work resume without repeating or diverging.
  • Context drift is detected against a written goal and corrected by steering or, when it is deep, by a reset.
  • Shared state across tools belongs in the repository and pull request, with one source of truth per topic.
Working context
Everything the model sees in a single call, rebuilt by the controller at each step.
Session state
The controller's record of one session, such as its plan, steps, commits and log.
Long-term memory
A store kept across sessions by the agent product, such as Copilot Memory.
External memory
Ordinary artifacts the agent reads and writes, such as files, issues and pull requests.
Compaction
Replacing older parts of a long conversation with a summary to stay within the context window.
Copilot Memory
GitHub's long-term memory of cited repository facts and user preferences, shared by several Copilot features.
Context drift
Growing divergence between what an agent believes or does and what is true or was asked.
Reset rule
A rule for when to discard a session's context and start again from a clean, correct summary.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why did Malik's agent repeat its work after the editor restarted?

    Show answer

    Its decisions lived only in the conversation, which was session state that did not survive; nothing durable recorded the plan or decisions.

  2. What two mechanisms keep Copilot Memory from using stale repository facts?

    Show answer

    Citation validation against the current branch, and automatic deletion of entries unused for 28 days.

  3. Name three signals of context drift.

    Show answer

    Any three of: touching files outside the plan, re-opening recorded decisions, repeating finished steps, inconsistent names, commits that do not match the checklist.

  4. Where should a temporary feature-freeze rule be written?

    Show answer

    Somewhere that expires with the work, such as the issue or pull request, not the permanent instructions.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz