I replayed 40 turns of a small Python agent that triages GitHub issues, with real GitHub API output as its tool results, and at turn 20 those tool results were 99.1 percent of the tokens in the request. So the first thing to measure is what fills the window. If it is tool output, shape each result to what the agent reads before it enters the history. In the replay, cutting each issue to five fields took the call at turn 40 from 658,594 tokens to 36,934. A limit of six turns still sent about 99,000 tokens on every call from turn 6 on, and a summary of the dropped turns saved nothing more.
For the bloat, the next largest saving after shaping came from replacing old tool results with a one-line stub, and any cut should fall between whole turns so that no tool call loses its result. For losing track, the part you can fix in code is where the instructions live. They should go with every request instead of sitting in the history, where a trim or a summary can reach them. I would add a summary last, for either problem, and only to carry what the user decided.
The replay
The agent behind every number below is deliberately plain. Its instructions are 94 tokens: answer in English, suggest labels but never apply them, cite issue numbers, keep answers short. Each turn is a user question of about 10 tokens, one call to a list_open_issues tool, the tool result, and a fixed answer of 90 tokens.
On 17 November 2026 I fetched the five newest open items of two Python agent projects from GitHub's REST API, pydantic/pydantic-ai (40,094 bytes of JSON) and openai/openai-agents-python (67,052 bytes), and the replay alternates between the two responses. Counted with tiktoken's o200k_base encoding, they are 11,058 and 21,583 tokens. The tiktoken README gives a rule of thumb: "On average, in practice, each token corresponds to about 4 bytes." This JSON came out at 3.6 and 3.1 bytes per token, so it costs more tokens per byte than that average.
The second response is heavier because of what sits in the bodies. GitHub's issues endpoint returned pull requests as well, and all five items from openai-agents-python were Dependabot pull requests updating dependencies, each with release notes in its body. Nobody wrote code to send release notes to the model, and with the whole history kept they go out again on every later call.
No model was called. A script builds the messages that would be sent on each of the 40 calls, in five different ways, and counts them, adding 4 tokens of formatting per message.
| How the window is built | Call at turn 10 | Call at turn 20 | Call at turn 40 | Input tokens over 40 calls |
|---|---|---|---|---|
| Whole history | 164,651 | 329,301 | 658,594 | 13.4 million |
| Last 6 turns | 98,790 | 98,788 | 98,793 | 3.7 million |
| Last 6 turns and a 54-token summary | 98,848 | 98,846 | 98,851 | 3.7 million |
| Tool results older than the last two replaced by a 16-token stub | 34,215 | 35,820 | 39,023 | 1.4 million |
| Tool results shaped to five fields, whole history kept | 9,236 | 18,471 | 36,934 | 0.76 million |
With the whole history, the request passes 128,000 tokens at turn 8 and 200,000 at turn 13. A Claude tokenizer would give other counts. Every row is counted the same way, so I would expect their order to hold.
Bloat
In this agent a six-turn limit keeps six tool results of 11,000 to 22,000 tokens each, so the window climbs to about 99,000 tokens by turn 6 and stays there for the remaining 34 calls. The limit stopped the growth, but each of those calls still carried six raw tool results. Over 40 calls the six-turn version sent 3.7 million input tokens, almost five times as many as the shaped version that kept its entire history.
A 54-token summary on top of the limit cost 58 tokens on each call from turn 7 and removed nothing, because the limit had already dropped the turns it stands in for.
Each raw tool result is a list of five GitHub issue objects, with 33 or 34 top-level fields in each. Seven of those fields are URLs, the author object adds twelve more URLs, and then there are reaction counts, timestamps and the full body. The triage agent reads five things: the number, the title, the labels, the comment count and the start of the body.
import json
def shape_issues(raw: str) -> str:
"""Keep what the agent reads; drop what it never uses."""
issues = json.loads(raw)
return json.dumps([
{
"number": i["number"],
"title": i["title"],
"labels": [label["name"] for label in i.get("labels", [])],
"comments": i.get("comments"),
"body": (i.get("body") or "")[:300],
}
for i in issues
])
The two results drop to 751 and 807 tokens, 15 and 27 times smaller. Of the five ways in the table, this is the only one that also keeps the newest result small, because the raw text never enters the history. I would not leave this to a framework setting. A framework has no way to know that a triage agent reads five fields of a GitHub issue, and whoever writes the tool does.
Shaping means you decide now which fields the agent will want later. Three hundred characters of body will not hold a stack trace, so an agent that needs one has to call the tool again for that issue.
My replay cannot say whether shaping costs answers, because it called no model. AheadKit tested that after a comment of mine and published the result on 19 November. The test used the same five fields, a small local model and twelve triage jobs, each run twice. The trimmed results solved 17 of 24 jobs and the full results 9 of 24.
AheadKit also counted how often the agent asked for one issue in full: 0.92 times per job with trimmed results and 0.88 with full ones. If the five fields had left out something the jobs needed, I would expect that number to climb, and it barely moved.
AheadKit's own conclusion is that "the direction is the finding, not the percentages", and with one small model and twelve jobs I would not read more into it either. The issue bodies in that test also ran a little over a hundred words, much shorter than most bodies in my replay, and AheadKit has not measured what shaping does to longer ones.
Stubbing keeps every tool call and replaces each result older than the last two with one line of 16 tokens, "[tool result removed from the window: 5 issues listed at this turn]". At turn 40 the call comes to 39,023 tokens. Anthropic offers the same idea on the server side as context editing, which was marked beta when I read it: "When activated, the API automatically clears the oldest tool results in chronological order."
A DataHub blog post names the risk: "Trim a tool output too early and a later step loses the field it needed." The stub keeps that recoverable. It tells the model that a result existed and what it covered, so the model can call the tool again instead of guessing.
If you also drop old turns, cut between turns, never inside one. The OpenAI Cookbook's session memory example defines the unit as "A turn = one user message plus everything that follows it (assistant replies, reasoning, tool calls, tool results) until the next user message." A cut inside a turn can leave a tool call without its result, and providers reject such a request.
Losing track
At turn 20 the whole-history request is 329,301 tokens, and 94 of them are the rules the agent is supposed to follow.
Pydantic AI Harness has a page on system reminders that describes what long runs do to such rules: "Long multi-turn runs suffer instruction fade: after many tool-use turns the model progressively ignores the guidance it was given at the start." I did not test reminders, and the replay says nothing about fade.
The other way to lose the rules is in your own code: a trim drops them, or a summary rewrites them. Marcus_MSC described this on r/AI_Agents on 9 September 2026, writing about task statements and acceptance criteria: "They're usually the oldest content, so dropping old turns can remove them while preserving recent tool noise, and repeated summarization can gradually rewrite them."
The model cannot follow rules it is no longer sent, and inside one conversation the code that builds each request decides whether they are sent. The rule I would follow is on Pydantic AI's message history page: "Text the model must follow at every step belongs in the agent's instructions, which every request sends." In the replay the instructions are the first message of every window, in every row of the table, so no trim ever reached them.
Your own agent
Log one number for every model call, the share of the request that is tool output. If it is near the 99 percent this agent showed, shape and stub first. If the conversation itself is most of the window, a turn limit and a summary are where I would start, though this replay did not test that case.
When the count has to match the model, ask the provider. OpenAI's token counting endpoint takes the same payload you would send to responses.create and returns an accurate count, and Anthropic's counts with the tokenizer of the model you name. A local tokenizer, as in this replay, is good enough for comparing two ways of building the same window.
I ran the replay on 17 November 2026, with the GitHub responses fetched at 12:31 UTC that day, tiktoken 0.14.0 and the o200k_base encoding. The replay's answers are a fixed text, so it measures size and leaves answer quality to tests like AheadKit's. I read the documentation, the DataHub post and the Reddit comment cited here on the night of 5 to 6 November 2026 and AheadKit's write-up on 19 and 20 November 2026, and this article describes them as they were on those dates.
I work on Mnemoverse; none of its code or data is involved in this replay.


Top comments (2)
Measuring what fills the window before deciding how to trim it is the step people skip. 99.1 percent tool output at turn 20 is a truck showing up with the whole lumber yard when the framer asked for twelve studs. Cutting each issue to the five fields the agent reads is ordering to the cut list. The six-turn limit that still carries about 99,000 tokens on every call is the number I'd show a team, because it looks like a fix and isn't one. Keeping the instructions outside the history, where no trim can reach them, is why the spec doesn't live in the meeting notes.
Agreed that it is not a fix for size. It fixes the growth: from turn 6 the window stays flat, but it keeps six raw tool results of 11,000 to 22,000 tokens each. When the output cannot be shaped, for example from a third-party tool you do not control, I would try the stub next. Replacing tool results older than the last two with a 16-token line ended at 39,023 tokens on the call at turn 40, close to the 36,934 of the shaped version.