Skip to main content

Module pairing

Module pairing 

Source
Expand description

The rules pairing a conversation’s tool calls with their results: validation and repair of a message list, the same repair over entries that keeps their ids (normalize), the calls a cut-short conversation still owes, and where a window of it may start.

use rig_core::{conversation::pairing, message::Message};

pairing::validate(&[Message::user("Hello"), Message::assistant("Hi")])?;

Structs§

Normalized
entries repaired as repair repairs messages, keeping ids: what the conversation holds after Conversation::normalize.
Paired
A history with its calls and results paired.
Pairing
How pair reads a history.

Enums§

AnswerError
Why a batch of results does not answer a turn’s calls (answers).
PairingError
Why a history is not a canonical conversation, or what pair repaired. See validate.

Constants§

NO_RESULT_PROVIDED
The text of the result rig sends for a tool call nothing answered.

Functions§

answers
Whether results answer pending exactly, one result per occurrence of an id in any order, matched as pair matches them.
close_pending
The user message closing calls nothing answered: a NO_RESULT_PROVIDED error result per occurrence, in call order, exactly as pair closes them.
close_pending_with
close_pending, each error result saying why, such as why the calls never ran.
normalize
entries repaired as repair repairs their messages, but that user entries side by side stay apart: an assistant entry directly after another is merged into it (the later stop standing) and keeps the first’s id, author and made-time; a result no call waits for is dropped, and an entry left empty with it; a made-up result for a call nothing answered goes into the next user entry, else a new entry by Author::rig; a system entry arriving while calls wait moves after the entries that answer them. A list repair leaves as it is comes back unchanged.
pair
The one rule for when a tool call is answered. None is a turn the caller emptied; it ends waiting calls like a turn.
pending_calls
The tool calls of the last assistant message in messages that no later tool result answers, in call order: what a conversation cut short still owes the model.
repair
messages read as a canonical conversation and repaired into one validate accepts, losing no turn: the lenient load of a history from outside the protocol, such as a stored transcript, and the close of a run’s history at cancellation. Beyond pair, an assistant turn left directly after another is merged into it; repairs reports the input as pair read it.
safe_start
The first index at or after at a request may start messages from: past every tool result before the first assistant turn from at, since its call is cut off, with any text or system message among them. Paired results later on are left alone. at past the end is the end.
validate
Rejects what pair would repair: consecutive assistant messages, a call nothing answered, and a result no waiting call asked for.