Skip to content

Commit

Permalink
refactor: make StateSnapshot inherit from NodeOutput
Browse files Browse the repository at this point in the history
work on #24
  • Loading branch information
bsorrentino committed Sep 13, 2024
1 parent 3e291db commit b210f38
Showing 1 changed file with 28 additions and 11 deletions.
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);
}

}

0 comments on commit b210f38

Please sign in to comment.