API Reference
prepareRequestMessages
function prepareRequestMessages(messages, options?): Message[];Defined in: primitives/loop.ts:491
Prepare working history for sending: drop both reasoning representations
(reasoning and reasoning_details) from assistant turns that did NOT call
tools — unless the model preserves its full reasoning history.
Parameters
| Parameter | Type | Description |
|---|---|---|
messages | Message[] | The working history to prepare. Never mutated. |
options | { keepReasoningOnPlainTurns?: boolean; } | Retention options. |
options.keepReasoningOnPlainTurns? | boolean | Keep reasoning on plain (non-tool-call) turns too (Preserved-Thinking models). Defaults to false. |
Returns
Message[]
A fresh array with reasoning stripped per the active regime.
Remarks
Two retention regimes, selected by ModelClient.retainsReasoning:
- Interleaved (default) — reasoning is resent only on tool-call turns. Thinking-mode models (e.g. DeepSeek V4) require it there for tool-call continuity and reject the request otherwise, while on plain turns the model ignores it, so it is stripped.
- Preserved (
keepReasoningOnPlainTurns: true) — reasoning is kept on EVERY assistant turn. Preserved-Thinking models (GLMclear_thinking:false, Kimi/Qwenpreserve_thinking:true) retain their whole reasoning history and want the complete, in-order sequence back, so stripping plain turns would contradict the kwarg the request already sends.
The flat string and the verbatim structured blocks follow the same rule (see Message.reasoning).
See
- Message.reasoning
- Message.reasoning_details
- ModelClient.retainsReasoning