KestrelDocs

Agents

Long runs fill an agent's context. Kestrel compacts old turns into a summary instead of cutting them off, so the agent keeps working with room to spare.

Fig. 1Context window
Context window float endAt(float t) { return t < 0.3 ? 494.0 : t < 0.9 ? mix(494.0, 284.0, ease((t - 0.3) / 0.6)) : t < 1.3 ? 284.0 : t < 3.4 ? mix(284.0, 494.0, (t - 1.3) / 2.1) : 494.0; } float field(vec2 p, float t) { float X0 = 67.0, LIMIT = 641.0, END = 494.0, COMPACT = 284.0; float e = endAt(t); float most = (END - X0) / (COMPACT - X0); float sq; float zone; if (t < 0.9) { sq = (END - X0) / (e - X0); zone = e; } else { sq = mix(1.0, most, 1.0 - sm(3.5, 4.1, t)); zone = COMPACT; } float squeezed = (sq - 1.0) / (most - 1.0); float tau = p.x <= zone ? X0 + (p.x - X0) * sq : p.x; // new tokens beyond the compacted zone: the pattern they had at t = 0 float k3[3]; k3[0] = 0.95; k3[1] = 0.85; k3[2] = 0.7; float y3[3]; y3[0] = 168.0; y3[1] = 232.0; y3[2] = 296.0; float r3[3]; r3[0] = 13.0; r3[1] = 17.0; r3[2] = 11.0; float v = 0.0; float wob = 5.0 * sin(p.y * 0.18 + TAU * 8.0 * t / T); // whole turns a cycle, so the loop closes for (int i = 0; i < 3; i++) { float band = exp(-pow(p.y - y3[i], 2.0) / (r3[i] * r3[i])); float on = step(0.28, hash(vec2(floor(tau / 7.0), float(i)))); float front = 1.0 - sm(e - 8.0, e + 6.0 + wob, p.x); if (p.x >= X0 && p.x <= LIMIT) { v += band * on * k3[i] * (p.x <= zone ? 1.0 + 0.45 * squeezed : 1.0) * front; v += band * 0.14 * (1.0 - front) * step(p.x, LIMIT); // the write head: a glow at the front while new tokens stream in if (t > 1.3 && t < 3.5) v += blob(p, vec2(e + 3.0, y3[i]), 9.0, 0.8 * sm(1.3, 1.5, t) * (1.0 - sm(3.3, 3.5, t))); } } return v; }
As the run goes on, turns fill the window. Near the top, the oldest turns are squeezed into a short summary, and the agent carries on with the space they freed.

What fills it

The task, the files the agent has read, every tool result and every reply. A run that reads a large repo can fill a million tokens in an hour.

Compaction

When the window reaches 80%, Kestrel compacts it. The oldest turns are rewritten as a summary a quarter of their size. Your task and the repo's memory are pinned: they are never compacted or dropped.

Value
Working context1M tokens
Compaction starts at80% full
Compaction ratioAbout 4 to 1
Always keptThe task, pinned memory, the last 20 turns

Tune it

kestrel.yaml
context:
  compact_at: 0.7     # start earlier on repos with huge files
  keep_turns: 30      # keep more recent turns word for word
Tip

The trace marks each compaction, with the size before and after. If an agent repeats work after one, raise keep_turns.

Was this page helpful?

Open the dashboard