-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add BaseCheckpointSaver - add Checkpoint - add CheckpointConfig - add CompileConfig - add InvokeConfig work on #11
- Loading branch information
1 parent
9ed434a
commit f9800ec
Showing
8 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
core-jdk8/src/main/java/org/bsc/langgraph4j/CompileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.bsc.langgraph4j; | ||
|
||
import org.bsc.langgraph4j.state.BaseCheckpointSaver; | ||
|
||
import java.util.Optional; | ||
|
||
|
||
public class CompileConfig { | ||
|
||
private BaseCheckpointSaver checkpointSaver; | ||
private String[] interruptBefore = {}; | ||
private String[] interruptAfter = {}; | ||
|
||
public Optional<BaseCheckpointSaver> getCheckpointSaver() { return Optional.ofNullable(checkpointSaver); } | ||
public String[] getInterruptBefore() { return interruptBefore; } | ||
public String[] getInterruptAfter() { return interruptAfter; } | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private final CompileConfig config = new CompileConfig(); | ||
|
||
public Builder checkpointSaver(BaseCheckpointSaver checkpointSaver) { | ||
this.config.checkpointSaver = checkpointSaver; | ||
return this; | ||
} | ||
public Builder interruptBefore(String... interruptBefore) { | ||
this.config.interruptBefore = interruptBefore; | ||
return this; | ||
} | ||
public Builder interruptAfter(String... interruptAfter) { | ||
this.config.interruptAfter = interruptAfter; | ||
return this; | ||
} | ||
public CompileConfig build() { | ||
return config; | ||
} | ||
} | ||
|
||
|
||
private CompileConfig() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core-jdk8/src/main/java/org/bsc/langgraph4j/InvokeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.bsc.langgraph4j; | ||
|
||
import org.bsc.langgraph4j.state.CheckpointConfig; | ||
|
||
import java.util.Optional; | ||
|
||
public class InvokeConfig { | ||
|
||
private CheckpointConfig checkpointConfig; | ||
|
||
public Optional<CheckpointConfig> getCheckpointConfig() { | ||
return Optional.ofNullable(checkpointConfig); | ||
} | ||
|
||
static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String checkpointThreadId; | ||
|
||
public Builder checkpointThreadId(String threadId) { | ||
this.checkpointThreadId = threadId; | ||
return this; | ||
} | ||
public InvokeConfig build() { | ||
InvokeConfig result = new InvokeConfig(); | ||
|
||
if( checkpointThreadId != null ) { | ||
result.checkpointConfig = CheckpointConfig.of(checkpointThreadId); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
private InvokeConfig() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
core-jdk8/src/main/java/org/bsc/langgraph4j/state/BaseCheckpointSaver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.bsc.langgraph4j.state; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface BaseCheckpointSaver { | ||
|
||
Collection<Checkpoint> list(); | ||
Optional<Checkpoint> get( String id ); | ||
void put( Checkpoint checkpoint ); | ||
} |
35 changes: 35 additions & 0 deletions
35
core-jdk8/src/main/java/org/bsc/langgraph4j/state/Checkpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.bsc.langgraph4j.state; | ||
|
||
import lombok.Value; | ||
|
||
import java.util.*; | ||
|
||
public class Checkpoint { | ||
|
||
@lombok.Value(staticConstructor="of") | ||
public static class Value { | ||
AgentState state; | ||
String next; | ||
} | ||
|
||
private final String id; | ||
private final Value value; | ||
|
||
public final String getId() { | ||
return id; | ||
} | ||
public final Value getValue() { | ||
return value; | ||
} | ||
|
||
public Checkpoint( Value value ) { | ||
this(UUID.randomUUID().toString(), value ); | ||
} | ||
public Checkpoint(String id, Value value) { | ||
Objects.requireNonNull(id, "id cannot be null"); | ||
Objects.requireNonNull(value, "value cannot be null"); | ||
this.id = id; | ||
this.value = value; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
core-jdk8/src/main/java/org/bsc/langgraph4j/state/CheckpointConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.bsc.langgraph4j.state; | ||
|
||
import lombok.Value; | ||
|
||
@Value(staticConstructor = "of") | ||
public class CheckpointConfig { | ||
String threadId; | ||
} |