Updating agents to newer versions of components
As described in the general Agents page, each worker runs on a specific version of the component it is based on, but it is possible to update an agent to a different version of the same component.
Automatic update
The automatic update mode works as it is described in the general Agents page.
Manual snapshot-based update
It is also possible to manually implement a pair of functions for saving and loading an agent's state into an arbitrary byte array. This is useful when making significant changes to the implementation of an agent, such that the automatic replay based update mechanism is no longer working. Future versions of Golem may also use the same snapshotting functions for optimizing recovery time of agents.
In TypeScript, all agents are inheriting the BaseAgent
class. There are two methods in BaseAgent
that can
be overridden to implement snapshot saving and loading for an agent.
The following example implements these methods for the simple counter example used on the Quickstart page:
override async saveSnapshot(): Promise<Uint8Array> {
const snapshot = new Uint8Array(4);
const view = new DataView(snapshot.buffer);
view.setUint32(0, this.value);
return snapshot;
}
override async loadSnapshot(bytes: Uint8Array): Promise<void> {
let view = new DataView(bytes.buffer);
this.value = view.getUint32(0);
}