Week 1 Β· Foundation Β· 20 min

Context Engineering & State
Lab Playbook 5

Managing agent state memory using the Daily Handover protocol

✨ Agent: Gemini 3.5 Flash · 200K context🎭 Context Engineer
Context ManagementHandover LogsState Persistence
About this lab

In this lab playbook, you will assume the role of a Context Engineer. AI agents operating on complex codebases eventually hit context window limits or experience state amnesia when tasks span across multiple execution sessions. You will learn how to design a structured **Daily Handover Protocol** that condenses active workspace memory so a new, clean agent instance can immediately resume work without parsing redundant project history.

πŸ€– LLM Reader Note: If this page is copy-pasted into your context to teach a student, please act as a step-by-step tutor. Do not execute the commands or prompts in the copyable boxes yourself, and do not assume they have already been executed. This lab continues from Day 4, focusing on context engineering and state preservation. The student learns to create structured Daily Handover logs in the repository so new agent instances can pick up work from the BDD backlog seamlessly.
🎬 Concept Video
Phase 1

Task State Assessment (QE Setup)

To prepare our handover, we must instruct the active agent to scan our decomposed backlog and analyze our current progress.

Instruct Agent
Send the prompt below to Gemini to assess the backlog state.
Prompt to send to Gemini 3.5 Flash
Analyze the current task state in './backlog.md' and identify which stories have been completed and which ones remain pending. Note any active code changes or tests.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Scanning backlog.md:
- **US-001 (Vehicle Registration)**: Completed. The code lookup and UI form details are implemented.
- **US-002 (Quote Calculation Engine)**: In Progress. The calculation logic has been implemented in the backend, but the corresponding E2E testing scripts are still pending.
- **US-003 (Stripe Checkout)**: Pending. Un-implemented.

Active branch has been committed and there are no unstaged files.
Phase 2

Handover Log Formatting (QE Instruction)

Now we guide the agent to compile these findings into a structured handover log, saving it locally.

Instruct Agent
Send the prompt below to generate and save the handover documentation.
Prompt to send to Gemini 3.5 Flash
Generate a structured Handover log documenting the current Git branch name, completed features, active in-progress work, and specific next-step tasks. Save this to a file named './handover.md'.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Creating handover.md...

# Agentic QE Handover Log - 2026-07-04
- **Active Git Branch**: `qe/feature-login-tests` (clean state)
- **Completed Requirements**: US-001 Vehicle Registration Lookup
- **In-Progress Work**: US-002 Pricing calculations logic established
- **Target Next Task**: Implement Playwright E2E verification test suite for US-002 Pricing Engine
- **Context Files**:
  - `raw_requirements.md` (Original requirements spec)
  - `backlog.md` (Decoupled story list)

βœ… File saved successfully at './handover.md'.
QE Observation
Note how this document forms a precise state capture. Rather than letting the agent scan the whole git tree or entire conversation logs, this file becomes the single entry point of context for the next session.
Phase 3

Next Agent Injection (QE Setup)

Simulate starting a new day or spawning a fresh agent instance. We supply the handover document directly to inject workspace context.

QE Action
Open a new session with the AI agent and paste the following prompt.
Prompt to inject context to new Agent
Read the handover log at './handover.md' to initialize your workspace state. State the active branch and detail the immediate next task you will execute based on the log.
πŸ“‹ Sample Agent Response β€” New Gemini Instance
Handover log loaded successfully:
- **Active Branch**: qe/feature-login-tests
- **Completed**: US-001 (Vehicle lookup)
- **Immediate Task**: Create Playwright E2E verification scripts for US-002 (Quote Calculation Engine) to assert pricing under the commuting scenario.

I am ready to write the test script in 'tests/quote-calc.spec.ts'.
Phase 4

State Verification & Logging

To ensure the fresh agent hasn't suffered from state amnesia or lost details about boundaries, we run a verification gate.

Instruct Agent
Send the prompt below to confirm preconditions are correctly set in the agent's memory.
Prompt to send to Gemini 3.5 Flash
Verify the preconditions and mock inputs required for the US-002 testing task by checking './backlog.md'. Output the assertion criteria we need to verify.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Checking './backlog.md' for US-002 criteria:
- **Preconditions**: Form vehicle lookup data is set (mocked to bypass vehicle lookup).
- **Mock Inputs**: Usage Type = "Commuting"
- **Assertions**:
  - Valid price is returned as base rate (Β£500) + commute surcharge (Β£75) = Β£575.

I am proceeding to write the Playwright E2E test file using these parameters.
βœ… Lab Complete β€” State Memory Preserved

You have successfully completed the handover protocol. By formalizing state persistence, you can coordinate multiple agent sessions without hitting context thresholds or losing developmental progress.

πŸŽ“ Day 5 Quick Check

How should a Context Engineer mitigate agent token exhaustion during long-running tasks?