# ModelCompactor

**Kind:** Class

**Source:** [`atloria-monorepo/libs/agent-core/src/context/model-compactor.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/libs/agent-core/src/context/model-compactor.ts#L176)

## Methods

| Method | Signature | Returns |
|---|---|---|
| `compact` | `compact(items: unknown[])` | `Promise<string>` |
| `getSummary` | `getSummary()` | `CompactionSummary | null` |
| `setSummary` | `setSummary(summary: CompactionSummary)` | `void` |
| `getEvents` | `getEvents()` | `readonly CompactionEvent[]` |
| `formatSummaryForContext` | `formatSummaryForContext()` | `string` |
| `hasPendingCompaction` | `hasPendingCompaction()` | `boolean` |
| `flush` | `flush()` | `Promise<void>` |
| `reset` | `reset()` | `void` |

## Where it refuses work

- `ModelCompactor` stops the work with `Error` when `!content` — “Compaction model returned empty content”.
- `ModelCompactor` stops the work with `Error` when `!parsed.sessionGoal && typeof parsed.sessionGoal !== 'string'` — “Invalid compaction summary: missing sessionGoal”.
- `ModelCompactor` stops the work with `Error` when `!parsed.progress || typeof parsed.progress !== 'object'` — “Invalid compaction summary: missing progress”.
- `ModelCompactor` stops the work with an early return when `historyText.length < 100`.
- `ModelCompactor` stops the work with an early return when `!this.currentSummary`.
- `ModelCompactor` stops the work with an early return when `this.config.useV1Endpoint`.

## When something fails

- `ModelCompactor` handles failure in 1 place: it logs it and continues in all 1.
