Skip to main content

Module conversation

Module conversation 

Source
Expand description

One conversation model for all of rig: Conversation, its edits as Changes, TurnRecords kept as asides, and pairing of tool calls with their results.

use rig_core::conversation::{Author, Conversation, Entry, pairing};
use rig_core::message::Message;

let mut conversation = Conversation::new();
let hello = conversation.push(Message::user("Hello"));
conversation.push(Message::assistant("Hi"));
// A plugin rewrites the greeting; the entry keeps its id.
let mut greeting = conversation.entry(0).ok_or("no entry")?;
greeting.message = Message::user("Hello there").into();
conversation.splice(0..1, [greeting], Author::plugin("polite"));
assert_eq!(conversation.index_of(hello), Some(0));

// The outbox folds into the same value.
let mut folded = Conversation::new();
for change in conversation.take_unsaved() {
    folded.apply(&change)?;
}
assert_eq!(folded, conversation);
assert!(pairing::pending_calls(conversation.messages()).is_empty());

Modules§

pairing
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.

Structs§

Aside
Kept with the conversation, saved and forked with it, never sent to a model: a plugin’s note in the transcript, the kernel’s record of a call in flight, a plugin’s own data. Readers take the kinds they know.
AsideId
An aside’s identity in its conversation, kept while it is replaced and across a save. Rises in the order asides were put.
Author
Who wrote an entry or an aside, or made a change: the kind of writer, the id of the agent it came from, the request it answers or makes, and what it is about. An entry without one is the user’s own text, the model’s reply or a tool result.
ChangeRecord
A change as kept in the outbox and saved: who made it and when.
Conversation
A conversation: its entries (each a message with an id and, when it is not the user’s own or the model’s, an author), its asides, why its last user message is unanswered, and the changes made to it that nobody has saved yet. Every edit builds a Change, applies it with the same code a fold (apply) uses, and keeps it in the outbox (unsaved).
Entry
A message as it goes into a conversation: the message, who wrote it, and, for a message taken out with Conversation::entry, its id, which a splice keeps. A recorded change always carries every id.
EntryRef
Entry index of a conversation, borrowed.
Lineage
The saved log a Conversation continues: a token a store chose when it started that log, carried by every value loaded from it or saved to it. A store appends a value’s unsaved changes to a log only when the value holds what that log holds (Conversation::continues): its lineage, and as many of its changes. The count alone cannot tell two conversations apart.
MessageId
A message’s identity in its conversation: kept while entries around it are added, cut or replaced, while it is spliced back changed, across a save and a fork. Ids rise in the order messages were first made.
MessageKey
A message’s identity beyond its conversation: when it was made and its id. Equal for a message and its copy in a fork (a fork copies ids and made-times), different for one made since, unless both were made in the same millisecond with the same id.
Note
A note in a transcript: an Aside of kind Note::KIND that every front showing the conversation draws after the entry it follows, with what it shows collapsed, in a line, and what it shows expanded. It never reaches a model, and it is saved, restored and forked with the conversation; one made unsaved is not saved.
ParseIdError
A MessageId or AsideId that could not be read from its plain form.
RequestId
The id of a request to an agent, which the reply to it names, such as the tool call that asked. Unique per sender, so it doubles as an idempotency key.
Spliced
What a splice changed.
TurnRecord
One turn of a conversation, from the message that asked for it to how it ended. Kept as an aside of kind TURN by Author::rig, put after the last entry when the turn begins and replaced when it ends.

Enums§

ApplyError
Why a recorded change could not be applied: it does not fit the conversation, such as a splice of a range holding other ids.
AuthorKind
Who wrote it.
Change
One edit of a conversation. Its serde form is the conversation part of the saved format.
Halt
Why the user’s last message is left without an answer, so a restore does not answer it. How a turn ended is its TurnRecord.
TurnEnd
How a turn ended.

Constants§

STOPPED
The text of the entry that goes between a request the user stopped and the next entry, so the model does not carry the request out. rig pushes it as its own entry, by Author::rig.
TURN
The kind of an aside holding a TurnRecord.

Functions§

short_id
The first characters of the agent id id, enough to tell agents apart.