UNPKG

@mastra/core

Version:
38 lines • 2.22 kB
/** * Every buffered step of a run carries the response messages of the run *so * far*, three times over: `response.messages` (the model-format messages), * `response.dbMessages` and `response.uiMessages` are all cumulative snapshots * of the same growing conversation, not per-step deltas. Persisting them on * every step makes a suspended snapshot grow quadratically in step count: a * fifteen-iteration agent run has been observed writing 22 MB of buffered steps * over 2 MB of distinct messages. * * The full conversation is already persisted once, in the serialized * `messageList` that sits alongside the buffered steps. So the snapshot stores * only the stable IDs of the messages each step referenced, and rebuilds the * three mirrors lazily from that list on the way back in. IDs are used instead * of a prefix length because processors can promote messages between sources or * remove messages after an earlier step was buffered. * * One behavioural note. A step's `dbMessages` share message objects with the * list, and an agentic turn keeps appending parts to the same message, so the * mirror a step persisted was never its step-time snapshot to begin with — it * was whatever the message had grown into by the time the snapshot was * written. `uiMessages` and `messages` were copies and did hold the step-time * shape, so after rehydration an earlier step's mirrors now reflect the same * content its `dbMessages` always did. The steps stay internally consistent, * and the last step — the one a resume continues from — is unchanged. * * This is purely a storage representation: callers still see populated message * mirrors on every step after rehydration. Each mirror is rebuilt and cached * only if a caller reads it, so restoring a long run does not eagerly convert * every historical prefix. */ import type { MessageList } from '../../agent/message-list/index.js'; type StepLike = { response?: unknown; }; export declare function packStepMessageMirrors<T extends StepLike>(steps: T[]): T[]; export declare function unpackStepMessageMirrors<T extends StepLike>(steps: T[], messageList: MessageList): T[]; export {}; //# sourceMappingURL=step-message-mirrors.d.ts.map