# `ADK.Context.Compressor`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/context/compressor.ex#L1)

Behaviour for context compression strategies.

Context compression reduces the number of messages/tokens sent to the LLM
when conversation history grows too large. Strategies implement this behaviour
to provide different compression approaches.

## Configuration

Compression can be configured on the agent or via `RunConfig`:

    agent = LlmAgent.new(
      name: "bot",
      model: "gemini-flash-latest",
      instruction: "Help",
      context_compressor: {ADK.Context.Compressor.Truncate, max_messages: 20}
    )

Or triggered automatically when message count exceeds a threshold.

# `message`

```elixir
@type message() :: %{role: atom(), parts: [map()]}
```

# `compress`

```elixir
@callback compress(messages :: [message()], opts :: keyword(), context :: map()) ::
  {:ok, [message()]} | {:error, term()}
```

Compress a list of messages, returning a shorter list.

The `opts` keyword list contains strategy-specific configuration.
The `context` map may include `:model` and `:instruction` for strategies
that need to call the LLM (e.g., summarization).

# `compaction_event`

```elixir
@spec compaction_event(non_neg_integer(), non_neg_integer()) :: ADK.Event.t()
```

Create a compaction event summarizing what was compressed.

The event has author `"system:compaction"` so it can be identified
during session reload and content assembly.

# `maybe_compress`

```elixir
@spec maybe_compress([message()], keyword() | nil) :: [message()]
```

Apply compression to messages if they exceed the configured threshold.

Returns the original messages if no compressor is configured or if
the message count is below the threshold.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
