Manage memory, state, and execution
An agent forgets by design, so give what must last a home and a reader
Two hours into a refactor, a GitHub Copilot CLI (command-line interface) agent quietly undoes a naming decision you agreed on at the start. Nothing is broken: the agent's context window, which holds the system instructions, tool definitions, and every message, response, tool call and result, is limited, and when Copilot CLI compacts a long conversation it replaces the old history with a summary that can leave out fine-grained details. This domain covers what an agent remembers, records and carries forward (sibling domains cover, among other things, which tools it calls and how several agents coordinate), and every question in it comes down to one move, which each of the three steps below applies: give what must survive a durable home instead of the context window, and make sure whoever reads it next actually receives it. The classic trap is treating the conversation itself as the memory, for example trusting a compacted summary to still hold the exact wording of an earlier decision.
The domain unfolds in three steps: choose the home, keep the task record, carry it across
Read the subtopics in order; each applies the one move above. Implement agent memory strategies covers choosing the home: measure what fills the context window before trimming it, then pick a durable store by its lifetime (how long the information must survive), its audience (who else must use it) and its reach (whether anything blocks that audience), among them Copilot Memory, the VS Code (Visual Studio Code) memory tool (local note files, not Copilot Memory; its session notes end with the conversation) and Copilot Spaces. Persist agent state and manage context drift covers keeping the task record: plan and progress files, session state and compaction checkpoints (what a compaction kept) that let a long task resume and reveal when the agent's work slides away from earlier decisions (context drift), plus choosing how far a rollback reaches. Maintain agent memory and state across tools and environments covers carrying it across: a carrier (this guide's shorthand) such as a workflow artifact, a committed state folder, an exported or synced session, or an instruction file, paired with the reader that picks it up across a job, device, tool or person boundary.
Trust the record you can open, and remove exactly what you mean to lose
When two answers both work, the exam rewards the one grounded in something you can inspect: the Copilot CLI /context usage breakdown before cutting history, the compaction checkpoint or progress file rather than the agent's recollection, and the changed files after a correction rather than the agent's acknowledgment. Copilot Memory (in public preview) applies the same caution to its repository facts: it checks a fact's citations (links to supporting code) against the current branch before relying on one. Cleanup follows the same discipline, because these operations, among others, each remove a different amount: in Copilot CLI, compacting a conversation against starting a new one; in VS Code, editing one stale memory note against clearing every memory scope. Pick the operation that matches the intent: a targeted edit for one outdated fact, and a fresh conversation when the next task is unrelated.
The three steps that give what must last a home and a reader, and where each is covered
| Step | Decides | Key mechanisms | Drill into |
|---|---|---|---|
| Choose the home | What stays in the context window and which durable store, by lifetime, audience and reach, holds the rest | Copilot CLI `/context`, `/clear` and `/new`; VS Code memory tool; Copilot Memory; Copilot Spaces | Implement agent memory strategies |
| Keep the task record | What a long task decided and finished, where it drifted, and how far to resume or roll back | Plan and progress files, Copilot CLI session state and compaction checkpoints, `/resume`, `/rewind` | Persist agent state and manage context drift |
| Carry it across | Which carrier moves state past a job, device, tool or person boundary, and which reader picks it up | Workflow artifacts handed between jobs, ordered by the consuming job's `needs` declaration, a committed state folder, exported or synced sessions, instruction files | Maintain agent memory and state across tools and environments |