Function: deriveAPIMessages()
deriveAPIMessages(
segments):ChatMessage[]
Defined in: packages/core/src/segments/derivation.ts:24
The conversation as ChatMessage[] for an API call: tool calls on the
assistant message, their results as separate tool messages; error and
done segments are left out.
UserSegments are turn boundaries. A UserSegment that
records the instructions its request sent ahead of it (instructions)
becomes those instructions' user message, then the person's.
Segments stamped with the model step that produced them are rebuilt one
step at a time, in order: each step's text and tool calls as one assistant
message, then its tool results — the conversation exactly as the turn's
own later steps sent it, so the next turn's cached prefix still matches.
A stamped step's text is kept as streamed (no trim, no placeholder).
Unstamped segments (stored without a step) collapse into one assistant
message per turn, trimmed, with ... for a tool-only message.