Package org.bsc.langgraph4j.checkpoint
Class FileSystemSaver
java.lang.Object
org.bsc.langgraph4j.checkpoint.AbstractCheckpointSaver
org.bsc.langgraph4j.checkpoint.FileSystemSaver
- All Implemented Interfaces:
BaseCheckpointSaver,LG4JLoggable
A CheckpointSaver that stores Checkpoints in the filesystem.
Each RunnableConfig is associated with a file in the provided targetFolder. The file is named "thread-threadId.saver" if the RunnableConfig has a threadId, or "thread-$default.saver" if it doesn't.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.bsc.langgraph4j.checkpoint.BaseCheckpointSaver
BaseCheckpointSaver.Tag -
Field Summary
Fields inherited from interface org.bsc.langgraph4j.checkpoint.BaseCheckpointSaver
THREAD_ID_DEFAULTFields inherited from interface org.bsc.langgraph4j.LG4JLoggable
log -
Constructor Summary
ConstructorsConstructorDescriptionFileSystemSaver(Path targetFolder, Serializer<LinkedList<Checkpoint>> checkpointsSerializer) FileSystemSaver(Path targetFolder, StateSerializer<? extends AgentState> stateSerializer) -
Method Summary
Modifier and TypeMethodDescriptionbooleandeleteFile(RunnableConfig config) delete the checkpoint file associated with the given RunnableConfig.protected voidinsertedCheckpoint(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Checkpoint checkpoint) protected LinkedList<Checkpoint>loadCheckpoints(RunnableConfig config) protected BaseCheckpointSaver.TagreleaseCheckpoints(RunnableConfig config, LinkedList<Checkpoint> checkpoints) Releases the checkpoints associated with the given configuration.protected voidupdatedCheckpoint(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Checkpoint checkpoint) Methods inherited from class org.bsc.langgraph4j.checkpoint.AbstractCheckpointSaver
get, list, put, releaseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bsc.langgraph4j.checkpoint.BaseCheckpointSaver
threadId
-
Constructor Details
-
FileSystemSaver
-
FileSystemSaver
-
-
Method Details
-
insertedCheckpoint
protected void insertedCheckpoint(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Checkpoint checkpoint) throws Exception - Specified by:
insertedCheckpointin classAbstractCheckpointSaver- Throws:
Exception
-
updatedCheckpoint
protected void updatedCheckpoint(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Checkpoint checkpoint) throws Exception - Specified by:
updatedCheckpointin classAbstractCheckpointSaver- Throws:
Exception
-
loadCheckpoints
- Specified by:
loadCheckpointsin classAbstractCheckpointSaver- Throws:
Exception
-
releaseCheckpoints
protected BaseCheckpointSaver.Tag releaseCheckpoints(RunnableConfig config, LinkedList<Checkpoint> checkpoints) throws Exception Releases the checkpoints associated with the given configuration. This involves copying the current checkpoint file (e.g., "thread-123.saver") to a versioned backup file (e.g., "thread-123-v1.saver", "thread-123-v2.saver", etc.) based on existing versioned files, deleting the original unversioned file, and then clearing the in-memory checkpoints.- Specified by:
releaseCheckpointsin classAbstractCheckpointSaver- Parameters:
config- The configuration for which to release checkpoints.checkpoints- released checkpoints- Throws:
Exception- If an error occurs during file operations or releasing from memory.
-
deleteFile
delete the checkpoint file associated with the given RunnableConfig.- Parameters:
config- the RunnableConfig for which the checkpoint file should be cleared- Returns:
- true if the file existed and was successfully deleted, false otherwise
-