PostgreSQL checkpoints
If your application already uses PostgreSQL, use it to save conversations, approvals, and long-running workflows so they can resume from a pause. If you already store checkpoints, follow the PostgreSQL migration guide first.
Configure the saver
After initializing the schema, start the application with CREATE_NONE. Use the same DataSource for the saver, the blob store, and any parent and child graphs you need to fork together. Connect all application instances to the same schema and keep the serializer and blob namespace consistent.
import com.alibaba.cloud.ai.graph.checkpoint.savers.postgresql.CreateOption;
import com.alibaba.cloud.ai.graph.checkpoint.savers.postgresql.PostgresCheckpointBlobStore;
import com.alibaba.cloud.ai.graph.checkpoint.savers.postgresql.PostgresSaver;
var saver = PostgresSaver.builder()
.datasource(dataSource)
.createOption(CreateOption.CREATE_NONE)
.build();
var blobs = new PostgresCheckpointBlobStore(dataSource, "support-workflow");
Register saver with the graph to save and resume progress. To reduce the cost of saving large state, follow the large state guide to attach blobs and select keys. To collect recovery and collection metrics, pass the application's MeterRegistry when constructing the blob store.
Resume approvals and branch from history
- Use
graph.getPendingInterruption(thread)to find items awaiting approval. If several parallel steps are waiting, pick the item frompendingInterruptions()and submit its feedback withRunnableConfig.Builder.addHumanFeedback(...). - To start a branch from history, select a snapshot with
getStateHistory(thread), callforkState(snapshot.config(), edits, null), and continue with the returned configuration. Page through longer histories withgetStateHistoryPage(config, null, pageSize). - Resupply temporary request context as input when resuming, for example
graph.invoke(Map.of("requestContext", recreated), thread.withResume()). Completed tasks stay complete when the application supplies new temporary values.