> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Compaction

> Automatic context window management

The `compaction` command manages context window compaction settings.

## Quick Start

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Show compaction status
praisonai compaction status
```

## Usage

### Show Status

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai compaction status
```

**Expected Output:**

```
╭─ Context Compaction ─────────────────────────────────────────────────────────╮
│  Strategy: sliding                                                           │
│  Max Tokens: 8,000                                                           │
│  Preserve Recent: 3 messages                                                 │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Set Strategy

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai compaction set sliding
```

Available strategies: `truncate`, `sliding`, `summarize`, `smart`

### Show Stats

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai compaction stats
```

## Python API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.compaction import (
    ContextCompactor, CompactionStrategy
)

compactor = ContextCompactor(
    max_tokens=4000,
    strategy=CompactionStrategy.SLIDING,
    preserve_recent=3
)

messages = [...]  # Your conversation history
compacted, result = compactor.compact(messages)

print(f"Compression: {result.compression_ratio:.1%}")
```

## See Also

* [Context Compaction Feature](/docs/features/context-compaction)
