Agent Harness Tutorial · Tech stack
L1 · Context assembly
What the model sees each turn, built in one place, within a budget. Family: Think · one turn, in order.
Why our choiceNo product does cache-friendly ordering, fencing, trimming from the middle and a transcript check, so we code it once.
| Option | Where from | Verdict | Why |
|---|---|---|---|
| Our assembler | ours | ✓ chosen | agent_harness/context |
| Prompts in Git | ours | ✓ chosen | |
| jinja2 | ours | ✓ chosen | fixed replies only |
| Foundry prompt management | Azure | ✗ dropped | too thin |
| Jinja templates | open source | ✓ used | fixed replies only |
How it works inside the harness: Context assembly.
How it is done: the real code
Cut from the live repositories each time the site is built, so it always matches what runs.
def assembled(
*,
system: str,
history: Sequence[Message],
max_chars: int = 24_000,
) -> Assembly:
"""Order for cache friendliness, then trim whole exchanges from the middle.
The system prompt is a stable prefix and goes first and unchanged: any byte
that moves invalidates every cached token after it. Trimming takes from the
middle rather than the tail, because the most recent turns are what the model
is answering and the earliest establish the task.
**Trimming drops whole exchanges.** An earlier version dropped individual
messages by index and orphaned a tool call in eight of fifty-five
turn-and-budget combinations — an assistant turn claiming a call whose answer
had been removed, which every provider rejects. Nothing caught it because no
test ran a conversation long enough to trim.
Compaction is still deliberately absent: a summary inherits the provenance of
everything it summarised, and getting that wrong is worse than a shorter
window.
"""
head = Message(role="system", content=system, provenance="operator")
units = exchanges(history)
before = len(units)
def size(groups: Iterable[list[Message]]) -> int:
return sum(len(m.content) for group in groups for m in group)
while len(units) > 2 and size(units) + len(system) > max_chars:
units.pop(len(units) // 2)
kept = [m for group in units for m in group]