Domain 4 of 6 · Chapter 2 of 3

Persist agent state and manage context drift

Unlock the complete study guide.

Bundled into the existing Developing in Agentic AI Systems premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • Why task state has to live outside the conversation
  • What compaction keeps, what it loses and how to steer it
  • Diagnosing drift and correcting course
  • The Copilot CLI session-state directory
  • Resuming and forking a Copilot CLI session
  • Rolling back conversation, files and history
  • The upgrade scenario folder: which file answers which question
  • Acting on an existing scenario folder
  • Exam reasoning: evidence over recollection

Which record or command answers which question, and the tempting answer that does not

What you need to knowWhat answers itTempting answer that does not
Which upgrade steps and validations actually finished`tasks.md`, updated with every step's statusThe upgrade `plan.md`, which records the intended approach, not completion
What strategy was confirmed during the upgrade assessment`upgrade-options.md``assessment.md`, which records findings and scope
Which breaking changes and API problems the analysis found`assessment.md``tasks.md`, which tracks execution status
How one resumed upgrade task went, in detail`tasks/{taskId}/progress-details.md`The step status in `tasks.md` alone
What one upgrade task was meant to cover`tasks/{taskId}/task.md`The scenario-wide `plan.md`
Upgrade preferences that must outlast the chat`scenario-instructions.md`A chat message that ends with the exchange
The complete recorded Copilot CLI session`events.jsonl` in the session-state directoryA Copilot CLI compaction checkpoint summary
Metadata about a Copilot CLI session`workspace.yaml``events.jsonl` or `plan.md`
What a Copilot CLI compaction kept`/session checkpoints NUMBER`Assuming the active summary is lossless
The current CLI implementation plan`/session plan`, or `plan.md` in the session-state directoryReconstructing the steps from memory
Working files that must stay out of the repositorySession artifacts listed by `/session files`Committing scratch files to the repository
Which session `copilot --continue` opensThe latest in the current directory, else the global latestAlways the session for the task you had in mind

Decision tree

What has to berecovered or fixed?Copilot CLI agent contradictsan earlier decision?/session checkpoints NUMBER: what was keptCompare with the decision's own evidenceCorrect course, then re-check files and testsNeed a detail the CopilotCLI summary dropped?A finished compaction cannot be reversedRecover it from original evidenceFull CLI history: events.jsonlContinue earlierCLI work?/resume: pick from a list or session ID--continue: this directory's latest first/fork (/branch): new session, not a Git branchReturn to anearlier point?/rewind: Conversation only, or + filesVS Code: editing a request reverts onwardGit, not chat checkpoints, is permanentResume an interrupted.NET upgrade?tasks.md: step status and validationprogress-details.md: one task's resultsupgrade-options.md: confirmed decisions

Cheat sheet

  • Read assessment.md for the analyzed upgrade scope and compatibility findings
  • Read upgrade-options.md to recover confirmed upgrade decisions
  • Read plan.md for the upgrade specification derived from the assessment and approved options
  • Read tasks.md for individual upgrade-step status and validation progress
  • Use scenario-instructions.md for persistent scenario-specific agent memory
  • Use the per-task task.md file to recover a task's scope and context
  • Read progress-details.md for a task's detailed execution notes and results
  • Choose explicitly whether to continue an existing upgrade scenario or start fresh
  • Update generated upgrade artifacts before advancing when the intended work changes
  • Use events.jsonl for the full saved CLI session history
  • Use workspace.yaml for session metadata rather than the session history
  • Recover the CLI implementation plan from its session plan.md artifact
  • Use session files for working artifacts that should not be repository content
  • Maintain a file-backed checklist as each migration issue is resolved
  • Compaction creates saved checkpoints that can be inspected individually
  • Compact a continuing CLI task to preserve essential progress in less context
  • Do not treat a compaction summary as a lossless record
  • Provide focus instructions when a compaction summary must emphasize a particular decision
  • Inspect compaction checkpoints when the agent diverges from earlier decisions
  • Use the conversation-summary setting to control automatic VS Code compaction
  • A CLI compaction checkpoint is not an undo control for completed compaction
  • Redirect an off-course agent with corrected context and verify the resulting changes
  • Resuming restores a saved CLI session's work context instead of an empty conversation
  • Account for working-directory selection when automatically continuing a CLI session
  • Fork a CLI session to explore an alternative without replacing the original conversation
  • Choose whether a CLI rewind should restore files as well as conversation state
  • Editing an earlier VS Code request reverts its changes and later changes before resubmission
  • Use Git rather than temporary VS Code chat checkpoints for permanent version history
  • Rebuild focused context in a fresh chat from a saved and reviewed implementation plan
  • Continue a task in its saved CLI session, not in an unrelated one

Unlock with Premium — includes all practice exams and the complete study guide.