Function: groupHistoryIntoTurns()
ts
function groupHistoryIntoTurns<M, TC>(
messages: readonly M[],
toolCalls: readonly TC[],
): HistoryTurn<M, TC>[];Defined in: src/batteries/context/thrift/relevance.ts:213
Group a flat message history (plus its tool calls) into HistoryTurns: a new turn starts at each message that begins a fresh exchange and closes at the next 'assistant'-role message (inclusive); every message up to the first turn boundary that has no preceding messages also starts a turn. Tool calls are attributed to the LATEST turn whose first message precedes the call's timestamp.
Type Parameters
| Type Parameter | Default type |
|---|---|
M extends RelevanceMessage | RelevanceMessage |
TC extends RelevanceToolCall | RelevanceToolCall |
Parameters
| Parameter | Type | Description |
|---|---|---|
messages | readonly M[] | The full flat message history, in chronological order. |
toolCalls | readonly TC[] | The full flat tool-call history, in any order (this function sorts by attribution, not the input order). |
Returns
HistoryTurn<M, TC>[]
The grouped turns, in chronological order.