Patch tool call / tool response parity in a messages array.
Ensures strict 1:1 correspondence between AIMessage tool_calls and ToolMessage responses:
Dangling tool_calls — an AIMessage contains a tool_call with no matching ToolMessage anywhere after it. A synthetic cancellation ToolMessage is inserted immediately after the AIMessage.
Orphaned ToolMessages — a ToolMessage whose tool_call_id does not
match any tool_call in a preceding AIMessage. The ToolMessage is removed.
Both directions are required for providers that enforce strict parity (e.g. Google Gemini returns 400 INVALID_ARGUMENT otherwise).
patchDanglingToolCalls(
messages: BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]
): __type| Name | Type | Description |
|---|---|---|
messages* | BaseMessage<MessageStructure<MessageToolSet>, MessageType>[] | The messages array to patch |