Search⌘ K
AI Features

Context Isolation via Orchestrator-Worker Architectures

Explore how to split a multi-stage incident review across isolated workers instead of one growing conversation. Compare flat prompts, labeled sections, and true context isolation; measure token growth; and coordinate workers through concise results and focused handoffs.

We'll cover the following...

So far, the on-call assistant has been one agent in one conversation. In Chapter 5, we gave it tools to keep that conversation small: pruning, compaction, notes, and memory. But some tasks need several kinds of work, one after another. After the incident, someone has to write the incident review. That means planning it, gathering evidence, computing the impact from the metrics, checking the numbers, writing the review, and checking its citations.

If one agent does all of that in one conversation, everything it reads and produces stays in its context until the end. In this lesson, we’ll measure that growth, see why labeling sections inside one prompt doesn’t help, and then split the work across isolated workers: separate calls that each see only what they need and return a short result to a coordinator.

One agent, five stages

Let’s start with the data the review needs. We have per-minute checkout metrics from 14:00 to 14:19, and a service-level objective (SLO): checkout p99 latency must stay under one second.

incident_metrics.py · Python 3.14.0
P99_MS = [182, 176, 190, 185, 179, 2400, 2550, 2600, 2480, 2390, 2310, 2350, 640, 210, 205, 198, 201, 195, 190, 188]
REQUESTS_PER_MIN = [1210, 1195, 1230, 1220, 1205, 1150, 1120, 1100, 1135, 1160, 1170, 1180, 1190, 1200, 1215,
1225, 1210, 1200, 1195, 1205]
SLO_P99_MS = 1000 # checkout p99 must stay under one second
def minute_label(i):
return f"14:{i:02d}"
def metrics_table():
return "\n".join(f"{minute_label(i)} p99={p} ms requests={r}" for i, (p, r) in enumerate(zip(P99_MS, REQUESTS_PER_MIN)))
if __name__ == "__main__":
print(metrics_table())

In the code above:

  • Lines 1–3: We store p99 latency and requests for each minute from 14:00 to 14:19.

  • Line 4: We set the SLO at 1,000 ms.

  • Lines 7–12: We define minute_label() and metrics_table(), which turn the lists into one line per minute.

The spike starts at 14:05 and ends after 14:11:

14:00 p99=182 ms requests=1210
14:01 p99=176 ms requests=1195
14:02 p99=190 ms requests=1230
14:03 p99=185 ms requests=1220
14:04 p99=179 ms requests=1205
14:05 p99=2400 ms requests=1150
14:06 p99=2550 ms requests=1120
14:07 p99=2600 ms requests=1100
14:08 p99=2480 ms requests=1135
14:09 p99=2390 ms requests=1160
14:10 p99=2310 ms requests=1170
14:11 p99=2350 ms requests=1180
14:12 p99=640 ms requests=1190
14:13 p99=210 ms requests=1200
14:14 p99=205 ms requests=1215
14:15 p99=198 ms requests=1225
14:16 p99=201 ms requests=1210
14:17 p99=195 ms requests=1200
14:18 p99=190 ms requests=1195
14:19 p99=188 ms requests=1205
Twenty minutes of checkout metrics around the incident

Now let’s write the first three stages of the review. Each stage returns two things: its full output, everything it read or produced, and a short result, the one line the next stage actually needs.

stages.py · Python 3.14.0
import json
from note_store import search_documents
from freshness_filter import freshness_filter
from change_log import get_recent_changes
from incident_metrics import P99_MS, REQUESTS_PER_MIN, SLO_P99_MS, metrics_table, minute_label
TASK = "Write the incident review for the 14:05 checkout latency spike, with cited, checked impact numbers."
def plan_stage():
steps = ["Collect the runbooks, the change log, and the checkout metrics.", "Compute minutes over the SLO and "
"affected checkouts.", "Recheck every number.", "Write the cited review.", "Check the citations."]
return "\n".join(f"{n}. {step}" for n, step in enumerate(steps, 1)), f"plan: {len(steps)} steps"
def evidence_stage():
found = search_documents("checkout latency spiked after a deploy roll back", top_k=5)
current, _ = freshness_filter([note["doc_id"] for note in found]) # Chapter 4: drop stale runbooks
notes = [note for note in found if note["doc_id"] in current]
changes = get_recent_changes("checkout", "deploy", "13:30") + get_recent_changes("checkout", "feature_flag", "13:30")
full = json.dumps(notes, indent=1) + "\n" + json.dumps(changes, indent=1) + "\n" + metrics_table()
ids = ", ".join(note["doc_id"] for note in notes)
return full, f"evidence: {ids}; v2.31 at 14:02; flag at 14:03; metrics 14:00-14:19"
def analysis_stage():
log, slow_minutes, affected = [], [], 0
for i, (p99, requests) in enumerate(zip(P99_MS, REQUESTS_PER_MIN)):
over = p99 > SLO_P99_MS
slow_minutes += [minute_label(i)] if over else []
affected += requests if over else 0
log.append(f"{minute_label(i)} p99={p99} over_slo={over} requests={requests} running_affected={affected}")
result = f"impact: {slow_minutes[0]}-{slow_minutes[-1]}, {len(slow_minutes)} min over SLO, {affected} checkouts slow"
return "\n".join(log), result

Here’s what each stage does:

    ...