Function: withHistory()
withHistory<
TInput,TOutput>(processable,history,options?):Processable<TInput,TOutput> &TInputextendsstring?object:Record<string,never>
Defined in: chat/src/middleware/history.ts:193
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
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>