## TL;DR
Summarise in stages, never by loading the history: compute per-run reductions with code first, loss, best metric, status, key params, then summarise the reductions in batches, and only then write the overall summary from the batch summaries. Five hundred raw histories exceed any window; five hundred one-line reductions fit, and the staged approach keeps every claim traceable to a run.

```text
context overflow when agent tried to summarize 500 run histories and the summarization failed with a length error
```

## Use this when
- The run or call fails with this symptom: context overflow when an agent tried to summarize 500 run histories.
- You are working on an agent producing a summary across hundreds of experiment runs and the failure repeats on the same run or configuration.
- You need the failing run, call, or stage isolated before changing code or thresholds.

## Not for this skill when
- A summary over a handful of runs that still overflows because each history carries huge artifacts, where the fix is excluding artifact content.
- The error text names a different tool, stage, or root cause. Match the verbatim error first and use that skill.

## Steps
1. Write a reducer that turns each run into one compact line: id, status, best metric, and the params that vary. Verify: 500 runs become 500 short lines
2. Batch the lines, for example 50 per batch, and summarise each batch's patterns: ranges, best performers, failure clusters. Verify: batch summaries exist for all batches
3. Compose the final summary from batch summaries only, citing run ids for every specific claim. Verify: the final text traces claims to runs
4. Record the reduction and batching parameters with the summary so its coverage can be audited. Verify: the method is documented with the result

## Variant phrasings
### agent context overflow summarize 500 run histories
The verbatim phrasing.
### agent summarization failed length error many runs staged
The staged phrasing.
### too many run histories agent summary batch reduce fix
The batching phrasing.

Compatibility: Agent summarisation of MLflow or tracker run histories under context limits

## Why it happens
Raw run histories include full metric series, param sets, and sometimes artifacts, so their size scales with both run count and run length. The information a summary needs is a tiny projection of that, and computing the projection with code instead of attention is what makes the task fit.

## Edge cases / pitfalls
- Keep reductions in a file the agent can re-read; regenerating them each session wastes the whole budget again.
- Outliers matter in experiment summaries; the reducer should flag extremes explicitly so batching cannot average them away.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_6j7USURHY5con21tcmdGjQ
