--- theme: seriph title: "Lesson 09 — How Can an Agent Stay Oriented in a Long Task?" info: "English video course for AI Agents in Depth" author: Bojie Li transition: slide-left mdc: true lineNumbers: false monaco: false aspectRatio: 16/9 canvasWidth: 980 layout: cover class: cover ---
Build · Chapter 2 · Context Engineering
# How Can an Agent Stay Oriented in a Long Task?

Status bars, physical time, context rot, and compression

Lesson 09 of 42 · 19 minutes · Agent Status Bar; Context Compression; Isolation Over Compression
--- layout: center class: text-center ---
The central question
Why does an Agent lose track of progress even before its context window is full?
--- # Why this problem matters

Context rot

Relevant facts remain present but become hard to retrieve.

Implicit state

Progress and time are scattered across the trajectory.

Compression

Raw history must become high-density working state.

--- # Three ideas to keep in view

Status bar

Explicit task, time, budget, and progress state

Hierarchical compression

Preserve recent detail and summarize older phases

Isolation

Move independent work into separate contexts

--- # The book's visual model Comparison of context compression strategies
Comparison of context compression strategies
--- # Long raw trajectory vs. Engineered working set

Long raw trajectory

Engineered working set

The goal is usable information—not maximum token retention.
--- # Make hidden state explicit ~~~python status = { "goal": task.goal, "done": completed_steps, "budget": remaining_steps, "elapsed": clock.elapsed() } ~~~ --- # Test the claim
2-81 min

Preview the injected status information

Observe: Task progress, time, tool count, and remaining budget

2-93 min

Compare compression strategies

Observe: What each strategy preserves, discards, and recomputes

Demo budget: 4 minutes · one contiguous terminal block
--- class: course-terminal ---
Live demo
# Switching to the terminal ~~~bash $ uv run python chapter2/system-hint/main.py --mode preview $ uv run python chapter2/context-compression/experiment.py --list-strategies ~~~
Run the command(s), narrate decisions, and point to the observation—not just the output.
--- # What the evidence supports

Finding 1

A status bar turns repeated inference into direct retrieval.

Finding 2

Compression is needed for information density before token overflow.

Finding 3

Independent sub-tasks are often better isolated than summarized.

--- layout: center ---
Where the claim stops
# Boundary condition
An incorrect status bar can be more harmful than missing meta-information because the Agent trusts it.
--- layout: center ---
Engineering takeaway
# Design rule
Compress completed history into verifiable state; keep recent evidence available; isolate independent work.
--- # Continue the experiment
Experiment 2-7: status-bar attention chapter2/attention_visualization/run_status_bar_experiment.py Run all six compression strategies chapter2/context-compression/run_all_strategies.py Status insertion position book-en/images/fig2-15.svg Compression processing flow book-en/images/fig2-17.svg
--- layout: center class: text-center ---
Pause and apply
# Your turn
Which fields in a status bar can be computed deterministically instead of inferred by the model?
--- layout: center class: text-center ---
Chapter 2 complete · Next · Lesson 10
Extend working context across sessions without turning memory into noise.