Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
7.7 KiB
7.7 KiB
theme, title, info, author, transition, mdc, lineNumbers, monaco, aspectRatio, canvasWidth, layout, class
| theme | title | info | author | transition | mdc | lineNumbers | monaco | aspectRatio | canvasWidth | layout | class |
|---|---|---|---|---|---|---|---|---|---|---|---|
| seriph | Lesson 09 — How Can an Agent Stay Oriented in a Long Task? | English video course for AI Agents in Depth | Bojie Li | slide-left | true | false | false | 16/9 | 980 | cover | 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
Long raw trajectory vs. Engineered working set
Long raw trajectory
- Repeated observations
- Low information density
- Reasoning cost grows
Engineered working set
- Explicit current state
- Compressed completed phases
- Isolated sub-tasks
The goal is usable information—not maximum token retention.
Make hidden state explicit
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
$ 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.
→