# RTK vs Caveman vs Stacked Compression Modes in OmniRoute: A Technical Comparison

> Explore RTK, Caveman, and Stacked compression modes in OmniRoute. Understand their differences for optimal token reduction and advanced data processing.

- Repository: [Diego Rodrigues de Sa e Souza/OmniRoute](https://github.com/diegosouzapw/OmniRoute)
- Tags: technical-comparison
- Published: 2026-08-01

---

**RTK provides fast line-level filtering, Caveman performs deeper semantic condensation, and Stacked combines both in a prioritized pipeline for maximum token reduction.**

OmniRoute's prompt-compression subsystem implements multiple "engine" modes that process request prompts and tool output data sequentially. Understanding the differences between **RTK**, **Caveman**, and **Stacked** compression modes is essential for optimizing latency and token usage in production deployments. This guide examines each mode's implementation in the `diegosouzapw/OmniRoute` source code.

## What Is RTK Compression Mode?

**RTK** (Real-Time Kleaner) is a fast, rule-based engine designed for lightweight, low-latency compression of tool results before upstream transmission.

### How RTK Works

The RTK engine operates line-by-line to remove obvious noise:

- Strips ANSI escape codes from terminal output
- Filters duplicate lines
- Truncates long-running command output
- Applies user-defined filter rules from [`.rtk/filters.toml`](https://github.com/diegosouzapw/OmniRoute/blob/main/.rtk/filters.toml)

In [`open-sse/services/compression/engines/rtk/index.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/rtk/index.ts), the RTK engine implements this filtering logic with minimal overhead. The engine prioritizes speed over semantic understanding, making it ideal for streaming scenarios.

### RTK Configuration

RTK settings are defined in [`open-sse/services/compression/engines/rtk/rtkConfigSchema.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/rtk/rtkConfigSchema.ts). Enable RTK alone when latency is critical:

```typescript
await fetch("/api/settings/compression", {
  method: "PUT",
  body: JSON.stringify({ engines: { rtk: { enabled: true } } }),
});

```

## What Is Caveman Compression Mode?

**Caveman** is a more aggressive, semantic-condensation engine that applies handcrafted rules to collapse redundant content while preserving meaning.

### How Caveman Works

The Caveman engine runs deeper analysis than RTK:

- Collapses redundant system prompts
- Deduplicates semantically similar content
- Aggressively shrinks prompts using rule-based transformations

The core logic resides in [`open-sse/services/compression/caveman.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/caveman.ts), with an adapter layer in [`open-sse/services/compression/engines/cavemanAdapter.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/cavemanAdapter.ts). Custom rules are defined in [`cavemanRules.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/cavemanRules.ts).

### Caveman Configuration

Enable Caveman for batch-style requests where aggressive size reduction is acceptable:

```typescript
await fetch("/api/settings/compression", {
  method: "PUT",
  body: JSON.stringify({ 
    engines: { caveman: { enabled: true, level: "full" } } 
  }),
});

```

## What Is Stacked Compression Mode?

**Stacked** is not a third engine but a **composite pipeline** that runs RTK first, then Caveman. This mode delivers the highest token savings while maintaining RTK's safety guarantees.

### How Stacked Mode Is Constructed

The pipeline order is determined by each engine's `stackPriority`:

| Engine | Priority | Position |
|--------|----------|----------|
| RTK | 10 | First |
| Caveman | 20 | Second |

This priority system is defined in [`open-sse/services/compression/engineCatalog.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engineCatalog.ts). When both engines are enabled, [`open-sse/services/compression/strategySelector.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/strategySelector.ts) automatically returns `"stacked"` and constructs the derived pipeline:

 ```json
[{engine: "rtk"}, {engine: "caveman"}]
 ```

### Stacked Configuration Example

```typescript
await fetch("/api/settings/compression", {
  method: "PUT",
  body: JSON.stringify({
    engines: {
      rtk: { enabled: true },
      caveman: { enabled: true, level: "full" },
    },
  }),
});
// Resulting pipeline: [{engine: "rtk"}, {engine: "caveman"}]

```

The selection logic is validated in [`tests/unit/compression/strategySelector.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/tests/unit/compression/strategySelector.test.ts) (lines 138-150), confirming that enabling both engines yields `"stacked"` with correct priority ordering.

## Key Differences Between RTK, Caveman, and Stacked

### Compression Depth

- **RTK** — Lightweight line-filters; minimal semantic analysis
- **Caveman** — Deep semantic reductions; rule-driven condensation
- **Stacked** — Maximum token savings through layered processing

### Execution Order in Stacked Mode

RTK always runs **first** to strip obvious noise at low cost. Caveman then refines the pre-filtered result. This ordering is immutable based on `stackPriority` values.

### Latency Characteristics

- **RTK** — Fastest; suitable for streaming
- **Caveman** — Slower; acceptable for batch processing
- **Stacked** — RTK latency + Caveman latency; optimized by RTK pre-filtering

### Configuration Independence

Each engine maintains separate config sections. Stacked mode derives automatically when both are enabled, though `stackedPipeline` property allows manual override.

## RTK vs Caveman vs Stacked: When to Use Each

**Use RTK alone** when:
- Streaming real-time tool output
- Latency budget is tight
- Content is already relatively clean

**Use Caveman alone** when:
- Processing large, redundant prompts
- Batch processing tolerates higher latency
- Maximum compression is required

**Use Stacked** when:
- General-purpose compression is needed
- Balancing speed and quality
- Default configuration for most deployments

## Implementation Files Reference

| Component | File Path |
|-----------|-----------|
| RTK engine | [`open-sse/services/compression/engines/rtk/index.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/rtk/index.ts) |
| RTK config schema | [`open-sse/services/compression/engines/rtk/rtkConfigSchema.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/rtk/rtkConfigSchema.ts) |
| Caveman core | [`open-sse/services/compression/caveman.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/caveman.ts) |
| Caveman adapter | [`open-sse/services/compression/engines/cavemanAdapter.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/cavemanAdapter.ts) |
| Engine priorities | [`open-sse/services/compression/engineCatalog.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engineCatalog.ts) |
| Mode selection | [`open-sse/services/compression/strategySelector.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/strategySelector.ts) |
| Stacked tests | [`tests/unit/compression/strategySelector.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/tests/unit/compression/strategySelector.test.ts) |

## Summary

- **RTK** provides fast, line-level filtering for low-latency scenarios
- **Caveman** executes deep, rule-based semantic condensation for aggressive size reduction
- **Stacked** automatically composes both engines in priority order (RTK → Caveman) when both are enabled
- Engine selection is controlled through the compression settings API, with mode determination handled by [`strategySelector.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/strategySelector.ts)
- Pipeline construction respects `stackPriority` values defined in [`engineCatalog.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/engineCatalog.ts)

## Frequently Asked Questions

### Can I change the order of RTK and Caveman in Stacked mode?

No. The execution order is fixed by `stackPriority` values in [`open-sse/services/compression/engineCatalog.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engineCatalog.ts)—RTK has priority 10 and Caveman has priority 20. RTK always runs first to remove surface-level noise before Caveman's deeper analysis.

### Does enabling both engines always create Stacked mode?

Yes. According to [`open-sse/services/compression/strategySelector.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/strategySelector.ts), when both `rtk.enabled` and `caveman.enabled` are true, the function returns `"stacked"` and builds the derived pipeline automatically. This behavior is verified in the test suite.

### What happens if I disable RTK but keep Caveman enabled?

The system runs Caveman alone. The [`strategySelector.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/strategySelector.ts) logic evaluates enabled engines individually and returns `"caveman"` as the mode when only that engine is active. The same applies for RTK-only configurations.

### Where are custom RTK filter rules stored?

User-defined RTK filter rules are stored in a [`.rtk/filters.toml`](https://github.com/diegosouzapw/OmniRoute/blob/main/.rtk/filters.toml) file. The RTK engine in [`open-sse/services/compression/engines/rtk/index.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/services/compression/engines/rtk/index.ts) loads and applies these rules during line-by-line processing.