Skip to main content

Variable: historyEnabled

const historyEnabled: <TInput, TOutput>(processable, history, options?) => Processable<TInput, TOutput> & TInput extends string ? object : Record<string, never> = withHistory

Defined in: chat/src/middleware/history.ts:311

Create a history-enabled version of a Processable Alias for withHistory with a more declarative name

Wrap a Processable with conversation history tracking

This middleware pattern allows history to be added to any Processable, not just ChatBot. It injects conversation history into process options and saves messages after each interaction.

Tool calls and tool results emitted during the turn are captured from the stream and persisted alongside the assistant text, so reloads preserve the tool_use → tool_result pairing that providers require for multi-turn fidelity.

Type Parameters

TInput

TInput

TOutput

TOutput

Parameters

processable

Processable<TInput, TOutput>

history

HistoryManager

options?

maxHistoryMessages?

number

Maximum history messages to inject (default: 50)

saveAssistantMessages?

boolean

Save assistant messages to history (default: true)

saveUserMessages?

boolean

Save user messages to history (default: true)

skipSave?

(result) => boolean

Skip saving if result matches this predicate

Returns

Processable<TInput, TOutput> & TInput extends string ? object : Record<string, never>