Skip to content

Function: createTurn()

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / createTurn

createTurn<TData>(messages, toolExecutions, usage, cycles, data?): Turn<TData>

Defined in: src/types/turn.ts:152

Creates a Turn from accumulated inference data.

TData = unknown

Type of the structured output data

Message[]

All messages produced during the inference

ToolExecution[]

Record of all tool executions

TokenUsage

Aggregate token usage

number

Number of inference cycles

TData

Optional structured output data

Turn<TData>

A complete Turn object

Error if no assistant message is found in the messages

const turn = createTurn(
[userMsg, assistantMsg],
[],
{ inputTokens: 100, outputTokens: 50, totalTokens: 150 },
1
);