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.SubGraphSaver, 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) list(Path targetFolder, BiPredicate<String, Integer> filter) protected LinkedList<Checkpoint>loadCheckpoints(RunnableConfig config) <State extends AgentState>
CompletableFuture<InterruptionMetadata<State>>registerInterruption(RunnableConfig config, InterruptionMetadata<State> interruptionMetadata) Register Interrupt of the execution for the given config and provide interruption metadata.protected BaseCheckpointSaver.TagreleaseCheckpoints(RunnableConfig config, LinkedList<Checkpoint> checkpoints, @Nullable String message) Releases the checkpoints associated with the given configuration.protected BaseCheckpointSaver.TagreleaseCheckpointsOnError(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Exception exception) tag(RunnableConfig config, Integer version) protected voidupdatedCheckpoint(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Checkpoint checkpoint) Methods inherited from class org.bsc.langgraph4j.checkpoint.AbstractCheckpointSaver
get, list, listSubGraphSaver, put, putSubGraphSaver, release, release, releaseOnErrorMethods 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
lastTag, 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, @Nullable String message) 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.
-
releaseCheckpointsOnError
protected BaseCheckpointSaver.Tag releaseCheckpointsOnError(RunnableConfig config, LinkedList<Checkpoint> checkpoints, Exception exception) throws Exception - Specified by:
releaseCheckpointsOnErrorin classAbstractCheckpointSaver- Throws:
Exception
-
registerInterruption
public <State extends AgentState> CompletableFuture<InterruptionMetadata<State>> registerInterruption(RunnableConfig config, InterruptionMetadata<State> interruptionMetadata) Description copied from interface:BaseCheckpointSaverRegister Interrupt of the execution for the given config and provide interruption metadata. this is used internally and should not be called directly by the user.- Specified by:
registerInterruptionin interfaceBaseCheckpointSaver- Parameters:
config- the RunnableConfig for which to register the interruptioninterruptionMetadata- the metadata associated with the interruption
-
tag
public Optional<BaseCheckpointSaver.Tag> tag(RunnableConfig config, Integer version) throws Exception - Specified by:
tagin interfaceBaseCheckpointSaver- Throws:
Exception
-
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
-
list
public static Stream<Path> list(Path targetFolder, BiPredicate<String, Integer> filter) throws IOException- Throws:
IOException
-