# HistoryConfig
Source: https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/historyconfig/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/engine/src/lib/history/history-manager.ts:29](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L29)

Persistence, retention, and prompt-projection policy for Engine history.

## Type Parameters

### TMeta

`TMeta` = `unknown`

## Properties

### deriveLLMContext?

> `readonly` `optional` **deriveLLMContext?**: (`entry`, `defaults`) => readonly [`LLMContextMessage`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/llmcontextmessage/)\[\]

Defined in: [packages/engine/src/lib/history/history-manager.ts:69](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L69)

Optional projection from a stored entry to the LLM-context messages it contributes. Called once per retained entry during `getLLMContext` and once per entry during truncation cost estimation, so keep the projection cheap and side-effect-free. When omitted, the engine uses its default projection: turns produce a user message (from user\_intent reasons) + an assistant message (from the response’s userMessage); injections produce a single assistant message.

The `defaults` callback returns the engine’s default projection for the same entry, enabling compose-with-default overrides without reimplementing the full projection. Call it from any branch that should fall through to default behavior; ignore it entirely for a full replacement.

Override to expose richer stored `metadata` to the LLM, rewrite roles, or merge multiple entries into a single context message.

#### Parameters

##### entry

[`HistoryEntry`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/historyentry/)<`TMeta`\>

##### defaults

() => readonly [`LLMContextMessage`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/llmcontextmessage/)\[\]

#### Returns

readonly [`LLMContextMessage`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/llmcontextmessage/)\[\]

* * *

### maxChars?

> `readonly` `optional` **maxChars?**: `number`

Defined in: [packages/engine/src/lib/history/history-manager.ts:44](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L44)

Budget for total characters in retained LLM-context projections. Omit to disable it. With [createEngine](https://docs.maelstrom-ai.co/dev/reference/engine/functions/createengine/), this must be a positive integer and an `assistant_message` whose `content.length` exceeds it is rejected. Truncation retains the newest entry even if its projection alone exceeds the budget. Direct [createHistoryManager](https://docs.maelstrom-ai.co/dev/reference/engine/functions/createhistorymanager/) calls skip those Engine boundary checks; a non-positive value retains no entries.

* * *

### maxEntries?

> `readonly` `optional` **maxEntries?**: `number`

Defined in: [packages/engine/src/lib/history/history-manager.ts:35](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L35)

Hard cap on per-session entry count. Omit to disable the entry-count cap entirely — truncation then relies solely on `maxChars` (or becomes a no-op if that is also omitted).

* * *

### store

> `readonly` **store**: [`HistoryStore`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/historystore/)<`TMeta`\>

Defined in: [packages/engine/src/lib/history/history-manager.ts:81](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L81)

Backing store. Required — the engine never silently defaults to an in-process store. Local dev and tests should pass `createInMemoryStore()` explicitly; production deployments supply a persistent, atomic store. Making this explicit prevents the footgun of shipping a configured `history` block to production and silently losing every session on process restart.

* * *

### transformEntry?

> `readonly` `optional` **transformEntry?**: (`entry`) => [`HistoryEntry`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/historyentry/)<`TMeta`\>

Defined in: [packages/engine/src/lib/history/history-manager.ts:51](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/history/history-manager.ts#L51)

Optional per-entry transform applied before persistence. Runs for both `turn` and `injection` entries. Use to strip fields a production store doesn’t need (rationale, vessel snapshots, etc.) — or to enrich entries with typed `metadata` before they’re stored.

#### Parameters

##### entry

[`HistoryEntry`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/historyentry/)<`TMeta`\>

#### Returns

[`HistoryEntry`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/historyentry/)<`TMeta`\>
