ReadonlylengthHow many messages the transcript holds. Zero before any call, and for realtime audio turns, which keep no message list.
A shorter transcript with the same shape: the first turn, the last keepLastTurns
turns, and a model's summary of everything between them.
This makes a metered model call. Compacting means asking a model to summarize the middle, so it costs tokens and goes through the usage gate like any other call. A summary that cannot be produced — the budget is gone, the provider is down — leaves the transcript untouched rather than returning something no shorter.
Cuts only at turn boundaries, so an assistant's tool calls and the results answering them always travel together — a transcript with one half of that pair is rejected by the provider outright.
const shorter = agent.getTranscript().compact({keepLastTurns: 3});
agent.setTranscript(shorter);
The original is unchanged. A transcript with nothing between its kept turns is returned as-is, without spending a call, so calling this unconditionally is safe.
Optionaloptions: AiCompactOptions
How much to keep, and which model to summarize with. Omit for the defaults.
A read-only view of the messages, oldest first. Each entry carries role and text; an assistant entry that requested tools also carries toolCalls, and a tool entry carries toolResult. Mutating the returned array does not affect the transcript.
The transcript as a string that AiClientOptions.transcript, AiAgent.setTranscript and B.ai.transcript accept back. Store this to continue the conversation in a later execution; the format is versioned, and a string that does not decode is refused with a message naming the entry at fault.
The exact message list a
B.aicall sent to the model, tool calls and results included. Returned asAiCallResult.transcript, accepted back asAiClientOptions.transcript(orAiAgent.setTranscript) to continue that conversation losslessly, and carried between executions as the stringtoJson()returns. Opaque: read it throughentries(); build one only from a previous call or fromB.ai.transcript(json).Example: ```javascript
const result = B.ai.call({ message: B.net.request.parameter("q"), tools: [lookup] });
B.out = result.transcript.entries() .map(entry => entry.role + ": " + entry.text).join("\n");
// Carry it to a later execution, then continue exactly where it stopped. const json = result.transcript.toJson(); B.ai.call({ transcript: B.ai.transcript(json), message: "And the dose?" });