Skip to Content
Motoko

Compacting a session

pi-durable compacts a session on its own when its context nears the model's window (its compaction settings, in settings). session.compact({ instructions? }) asks for one now: it admits pi-durable's manual compaction and resolves once it is admitted. The compaction summarizes the session's older messages, keeping the newest ones verbatim, into what the model reads from then on; the thread keeps them. It runs while the session keeps working, and its summary lands at once when the session is idle, else at the run's next boundary. instructions is added to the summarization prompt, to say what the summary should keep.

await session.compact({ instructions: "Keep every decision the user made." });

The stream shows it as it goes, from pi.live: compaction:start (reason: "manual", or threshold and overflow for pi-durable's own), then session:compacted with the summary and compaction:end. A compaction whose summary fails (the model's error, after pi-durable's retries) ends with compaction:end and its error, and the model reads the messages as they were; the view keeps the failure until a later compaction succeeds. A compaction runs on the scope's models, resolved again before compact as before submit. A child session refuses it with SessionOwnedError: what its sub-agent reads is its delegate's call's.