MSBA-379 · Lesson 5 of 12 · 23 min

Domain review: memory, state and execution

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

Manage memory, state and execution carries 10 to 15 percent of GH-600. It is one of the two lightest domains, but Priya warned Malik against treating it lightly. "Memory and state are where long agent tasks go wrong quietly," she said. "Nothing fails. The agent just forgets what it decided on Tuesday and does something different on Wednesday." Malik knew the feeling. In Memory, Evaluation and Multi-Agent Orchestration he had lost a day's agent work when his editor restarted and every decision the agent had made lived only in the conversation.

The domain has three skill groups: implement agent memory strategies; persist agent state and manage context drift; and ensure continuity of memory and state across tools and environments. Malik scored 3 of 4 on the baseline. His miss confused two things the exam keeps separate: memory, which is what an agent knows across tasks, and state, which is where a particular task has got to.

Domain 3 in three skill groups.
Skill groupKey bulletsFirst taught in
Implement agent memory strategiesChoose short-term, long-term or external memory; scope memory to the task; define expiration, pruning and reset rulesMemory and state
Persist state and manage context driftCapture progress and decisions as durable artifacts; resume without repeating or diverging; detect and correct driftPlanning and execution control
Continuity across tools and environmentsShare state; prevent conflicting context; prevent stale contextMemory and state; Operating agents in production

Three kinds of memory

The first bullet asks you to choose between short-term, long-term and external memory. The distinction is about where information lives and how long it lasts.

Short-term, long-term and external memory compared.
KindWhere it livesLastsGood forWatch out for
Short-termThe context window of the current session: the conversation, files read, tool resultsUntil the session ends or the context fillsWorking detail for the current stepLost on restart; crowded out in long sessions
Long-termPersistent memories the agent system keeps between sessions, such as Copilot MemoryAcross sessions, subject to expiry rulesRepository conventions and stable preferences learned over timeBecomes stale when code changes
ExternalDurable stores the agent reads and writes through tools: repository files, issues, pull requests, databases, documentationAs long as the store keeps itPlans, decisions, progress and shared factsNeeds retrieval; can conflict with other sources
Three concentric regions. The innermost is short-term memory, the context window of one session. The middle ring is long-term memory, facts kept between sessions with expiry. The outer ring is external memory: repository files, issues, pull requests and documentation, reached through tools. Arrows show the agent reading from all three and writing durable decisions to external memory.
The three kinds of memory. Durable decisions belong in the outer ring, where people can see them.

Choosing among them follows from the question each answers. Information needed only for the current step belongs in short-term memory and should leave it when the step is done. Stable facts about how a repository works, such as the test command, a naming convention or the fact that tests import from src and never from dist, belong in long-term memory or, better for anything important, in an instruction file such as AGENTS.md where people can review them. Information several agents or people must share, or that must survive a crash, belongs in external memory: an issue, a pull request description, a plan file or a decision record.

Copilot Memory is GitHub's long-term memory for Copilot's agents. It stores repository facts that agents learn while working, each with citations to the code that supports it, and it can also store user preferences. When an agent uses a memory, the citations are checked against the current branch, so a fact whose evidence has changed is not trusted blindly. Memories that are not used expire after 28 days. Repository administrators can review and delete memories, and GitHub has added deletion controls by scope during 2026. The cloud agent, Copilot CLI and Copilot code review use repository memories, and in September 2026 GitHub announced that agentic autofix uses them too. Copilot Memory was in public preview when the sprint ran; a question that depends on its exact availability should be read with that in mind.

Scoping memory to the task

More memory is not better memory. Everything in the context window competes for the model's attention, and irrelevant information pulls it in the wrong direction. Scoping memory to task-relevant information means giving the agent what this task needs and leaving out the rest. Path-specific instruction files help: Tidewater's tests.instructions.md applies only when the agent works on test files, so its rules do not crowd unrelated tasks. A task description that lists the relevant files is another form of scoping. So is a custom agent with a narrow purpose: the reviewer agent does not need to know the release process.

In a long session, scoping also means summarizing. When the agent has read twenty files to find the three that matter, a short summary of what it learned is more useful for the next step than the twenty files themselves. Several agent surfaces compact long conversations automatically; good practice is to make sure that whatever is compacted away is either unimportant or already written somewhere durable.

Expiration, pruning and reset

The third memory bullet asks you to define rules for expiration (when a memory stops being used), pruning (removing memories that are wrong, duplicated or no longer relevant) and reset (starting again from a clean state). Copilot Memory's 28-day expiry is an example of an expiration rule built into the product. Teams add their own rules on top. Tidewater's are simple: Dmitri reviews the repository's Copilot Memory facts and the instruction files on the first Thursday of each month and deletes anything wrong; any memory that contradicts an instruction file is deleted and, if it was right, moved into the instruction file; and after a major restructuring of a repository, memories are reset rather than trusted.

Worked problem

Memory or state?

On Monday, the cloud agent learned that the validator's tests must import from src. On Tuesday, a long refactoring task restarted halfway after a setup failure, and the agent redid two steps it had already completed. Which problem is memory and which is state, and what fixes each?

Show solution
  1. The import rule is a stable fact about the repository: memory. It belongs in long-term memory and, because it matters, in AGENTS.md or a path-specific instruction file.
  2. Redoing completed steps is a state problem: the task did not record its progress durably.
  3. The fix for state is a plan with checkboxes, or progress comments, in the pull request, read at the start of every resumed session.

Answer: The import rule is memory, fixed by a reviewed instruction; the repeated steps are state, fixed by recording progress as a durable artifact.

Persisting state as durable artifacts

State is the answer to three questions: what has been done, what was decided and what comes next. The outline asks you to capture task progress and decisions as durable artifacts, and in GitHub the natural places are the ones that already exist. The cloud agent keeps a checklist of its plan in the pull request description and updates it as it works, and its session log records each step. Commits record what changed with messages that say why. A decision that matters beyond the task belongs in a decision record in the repository, as Tidewater did for "agents may not edit workflow files". An agentic workflow can write its findings to an issue comment or a job summary.

Progress and decisions recorded in a pull request description. A resumed session reads this first.
## Progress
- [x] 1. Add isFutureDate to src/dates.js (commit 4e1a9c2)
- [x] 2. Call it from validateReport (commit b7d0f13)
- [ ] 3. Add three tests to test/validate.test.js

## Decisions
- Reports dated today are accepted at any time of day (Malik, comment on issue 214).
- Kept the existing error message format; changing it would break the volunteer upload tool.

Resuming work without repeating steps or diverging from prior decisions depends on this record. A resumed agent, or a person picking up the work, should start by reading the progress and decisions, confirming the current state of the branch matches them, and continuing from the first unfinished step. Steps should be idempotent where possible, so that redoing one by accident does no harm. And a decision recorded earlier should be treated as binding unless a person changes it; an agent that silently reopens a settled question is diverging.

Detecting and correcting drift

Context drift is the gradual movement of an agent away from its task during a long execution: the goal fades as the context fills with detail, early decisions are compacted away, and the agent begins to solve a different problem. Signs of drift are visible if you look for them: changes to files outside the plan, steps that do not appear in the plan, a pull request description that no longer matches the diff, a test strategy that changed midway, or a rising number of tool calls without progress.

Correcting drift has three parts. First, re-ground: restate the goal and the plan, either because the agent's instructions tell it to reread the plan at each step or because a person does. Second, check against the plan: compare the diff with the plan's file list and steps, and treat anything outside it as a question rather than a fact. Third, if drift has gone far, reset: close the session, keep the durable record, and start a fresh session from the last good state. Memory, Evaluation and Multi-Agent Orchestration taught Malik that a fresh session with a good plan is often faster than coaxing a confused one back on course.

Continuity across tools and environments

Agent work increasingly moves between surfaces. Malik might start a task in his editor, hand it to the cloud agent overnight, and read the result in Copilot CLI the next morning. The third skill group asks how state and memory survive those moves.

Sharing state means putting it where every surface can read it. A plan in an issue or pull request is visible to the editor, the cloud agent, the CLI and every person. A plan that lives in one editor's chat history is not. Repository memories in Copilot Memory are shared by the agents that use them. Instruction files in the repository are read by every Copilot surface that supports them.

Preventing conflicting context means avoiding two sources that say different things. The usual culprits are an instruction file and a memory that disagree, a personal instruction that contradicts the repository's, or two plans for the same task. The remedy is a single source of truth for each kind of information, with clear precedence. For instructions, repository and path-specific files are reviewed and owned through CODEOWNERS, as Tidewater does; personal preferences should not override repository rules. For plans, one task has one plan, linked from the issue.

Preventing stale context means noticing when information has stopped being true. Memories with citations help, because their evidence is checked against the current branch. Expiry helps. Instruction files need owners who update them when the code changes. A practical habit from the program is to date important statements: "as of the November 2026 refactor, dates are parsed in src/dates.js" is easier to recognize as stale later than an undated sentence.

Worked problem

Stale or conflicting?

After Tidewater moved the trail-units build from Rollup to a different bundler, the cloud agent kept adding Rollup configuration to new pull requests. AGENTS.md had been updated; a repository memory from August still said "build uses Rollup". What kind of problem is this, and what are the fixes?

Show solution
  1. The memory is stale: its evidence no longer matches the code, though citation checks should catch this and the agent should have preferred the instruction file.
  2. It also creates conflicting context with AGENTS.md.
  3. Delete the stale memory, confirm AGENTS.md states the current build tool, and after a major build change consider resetting repository memories.

Answer: Stale memory causing conflicting context. Prune the memory, keep the instruction file as the source of truth, and add "after major build changes, review memories" to the monthly check.

How the domain is tested

Expect short scenarios that describe a symptom, such as an agent repeating work, contradicting an earlier decision, using an outdated convention or behaving differently in two tools, and ask for the cause or the fix. The distractors tend to be fixes for the wrong problem: adding memory when the problem is state, enlarging the context window when the problem is drift, or writing a new instruction when the problem is a stale memory that contradicts the existing one. Name the problem first, using the vocabulary of this lesson, and the fix usually follows.

At the end of the session Malik reduced the domain to a card: "Memory is what the agent knows; state is where the task is. Keep both durable, scoped and fresh."

Common mistakes

  • MistakeTreating a long context window as a memory strategy.

    InsteadUse short-term memory for working detail and durable artifacts for anything that must survive.

  • MistakeRelying on long-term memory for rules that must always hold.

    InsteadPut important rules in reviewed instruction files, and back critical ones with controls.

  • MistakeLetting a confused session continue indefinitely.

    InsteadRe-ground against the plan, and reset from the last good state if drift persists.

  • MistakeKeeping plans in one tool's chat history.

    InsteadPut plans and progress in issues or pull requests that every surface can read.

  • MistakeNever pruning memories.

    InsteadDefine expiry, pruning and reset rules, with an owner who reviews them.

Summary and key terms

  • Domain 3 carries 10 to 15 percent and separates memory (what an agent knows) from state (where a task has got to).
  • Short-term memory is the session context; long-term memory persists between sessions; external memory lives in repository files, issues and pull requests.
  • Copilot Memory stores repository facts with citations checked against the current branch; unused memories expire after 28 days.
  • Record progress and decisions durably so work can resume without repeating steps or reopening decisions; detect drift by comparing the diff to the plan.
  • For continuity across tools, share state in GitHub, keep one source of truth with clear precedence, and prune or reset stale context.
Short-term memory
The information in an agent's current context window, lost when the session ends.
Long-term memory
Information an agent system keeps between sessions, such as Copilot Memory.
External memory
Durable stores outside the agent, such as files, issues and pull requests, reached through tools.
Context drift
The gradual movement of an agent away from its task during a long execution.
Stale context
Information given to or remembered by an agent that is no longer true.

Practice problems

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

  1. After how long do unused Copilot Memory entries expire?

    Show answer

    28 days.

  2. What makes Copilot Memory facts safer to use after code changes?

    Show answer

    Their citations are checked against the current branch.

  3. Name three signs of drift.

    Show answer

    Changes outside the plan, steps not in the plan, and a description that no longer matches the diff.

  4. What should a resumed session read first?

    Show answer

    The recorded progress and decisions, then confirm the branch matches them.

  5. What is the remedy for conflicting context?

    Show answer

    A single source of truth for each kind of information, with clear precedence.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz