-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make StateSnapshot inherit from NodeOutput
work on #24
- Loading branch information
1 parent
3e291db
commit b210f38
Showing
1 changed file
with
28 additions
and
11 deletions.
There are no files selected for viewing
39 changes: 28 additions & 11 deletions
39
core-jdk8/src/main/java/org/bsc/langgraph4j/state/StateSnapshot.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 |
---|---|---|
@@ -1,32 +1,49 @@ | ||
package org.bsc.langgraph4j.state; | ||
|
||
import lombok.NonNull; | ||
import lombok.Value; | ||
import lombok.var; | ||
import org.bsc.langgraph4j.NodeOutput; | ||
import org.bsc.langgraph4j.RunnableConfig; | ||
import org.bsc.langgraph4j.checkpoint.Checkpoint; | ||
|
||
@Value | ||
public class StateSnapshot<State extends AgentState> { | ||
State state; | ||
RunnableConfig config; | ||
public final class StateSnapshot<State extends AgentState> extends NodeOutput<State> { | ||
private final RunnableConfig config; | ||
|
||
public String getNext( ) { | ||
public String next( ) { | ||
return config.nextNode().orElse(null); | ||
} | ||
|
||
private StateSnapshot(@NonNull State state, @NonNull RunnableConfig config) { | ||
this.state = state; | ||
public RunnableConfig config() { | ||
return config; | ||
} | ||
|
||
/** | ||
* @deprecated Use {@link #config()} instead. | ||
*/ | ||
@Deprecated | ||
public RunnableConfig getConfig( ) { | ||
return config(); | ||
} | ||
|
||
/** | ||
* @deprecated Use {@link #next()} instead. | ||
*/ | ||
@Deprecated | ||
public String getNext( ) { | ||
return next(); | ||
} | ||
|
||
private StateSnapshot(@NonNull String node, @NonNull State state, @NonNull RunnableConfig config) { | ||
super( node, state ); | ||
this.config = config; | ||
} | ||
|
||
public static <State extends AgentState> StateSnapshot<State> of(Checkpoint checkpoint, RunnableConfig config, AgentStateFactory<State> factory) { | ||
|
||
var newConfig = RunnableConfig.builder(config) | ||
RunnableConfig newConfig = RunnableConfig.builder(config) | ||
.checkPointId( checkpoint.getId() ) | ||
.nextNode( checkpoint.getNextNodeId() ) | ||
.build() ; | ||
return new StateSnapshot<>( factory.apply(checkpoint.getState()), newConfig); | ||
return new StateSnapshot<>( checkpoint.getNodeId(), factory.apply(checkpoint.getState()), newConfig); | ||
} | ||
|
||
} |