2
2
3
3
4
4
import lombok .Getter ;
5
+ import lombok .NonNull ;
5
6
import org .bsc .langgraph4j .action .AsyncEdgeAction ;
6
7
import org .bsc .langgraph4j .action .AsyncNodeAction ;
7
8
import org .bsc .langgraph4j .serializer .Serializer ;
9
+ import org .bsc .langgraph4j .serializer .StateSerializer ;
8
10
import org .bsc .langgraph4j .serializer .std .ObjectStreamStateSerializer ;
9
11
import org .bsc .langgraph4j .state .AgentState ;
10
12
import org .bsc .langgraph4j .state .AgentStateFactory ;
@@ -93,32 +95,26 @@ GraphRunnerException exception(String... args) {
93
95
private final Map <String , Channel <?>> channels ;
94
96
95
97
@ Getter
96
- private final AgentStateFactory <State > stateFactory ;
97
-
98
- @ Getter
99
- private final Serializer <Map <String ,Object >> stateSerializer ;
98
+ private final StateSerializer <State > stateSerializer ;
100
99
101
100
/**
102
101
*
103
102
* @param channels the state's schema of the graph
104
- * @param stateFactory the factory to create agent states
105
103
* @param stateSerializer the serializer to serialize the state
106
104
*/
107
105
public StateGraph (Map <String , Channel <?>> channels ,
108
- AgentStateFactory <State > stateFactory ,
109
- Serializer <Map <String ,Object >> stateSerializer ) {
106
+ StateSerializer <State > stateSerializer ) {
110
107
this .channels = channels ;
111
- this .stateFactory = stateFactory ;
112
- this .stateSerializer = ( stateSerializer == null ) ? new ObjectStreamStateSerializer () : stateSerializer ;
108
+ this .stateSerializer = stateSerializer ;
113
109
}
114
110
115
111
/**
116
- * Constructs a new StateGraph with the specified state factory .
112
+ * Constructs a new StateGraph with the specified serializer .
117
113
*
118
- * @param stateFactory the factory to create agent states
114
+ * @param stateSerializer the serializer to serialize the state
119
115
*/
120
- public StateGraph (AgentStateFactory < State > stateFactory , Serializer < Map < String , Object > > stateSerializer ) {
121
- this ( mapOf (), stateFactory , stateSerializer );
116
+ public StateGraph (@ NonNull StateSerializer < State > stateSerializer ) {
117
+ this ( mapOf (), stateSerializer );
122
118
123
119
}
124
120
@@ -128,7 +124,7 @@ public StateGraph(AgentStateFactory<State> stateFactory, Serializer<Map<String,O
128
124
* @param stateFactory the factory to create agent states
129
125
*/
130
126
public StateGraph (AgentStateFactory <State > stateFactory ) {
131
- this ( mapOf (), stateFactory , null );
127
+ this ( mapOf (), stateFactory );
132
128
133
129
}
134
130
@@ -138,9 +134,12 @@ public StateGraph(AgentStateFactory<State> stateFactory) {
138
134
* @param stateFactory the factory to create agent states
139
135
*/
140
136
public StateGraph (Map <String , Channel <?>> channels , AgentStateFactory <State > stateFactory ) {
141
- this ( channels , stateFactory , null );
137
+ this ( channels , new ObjectStreamStateSerializer <>( stateFactory ) );
142
138
}
143
139
140
+ public final AgentStateFactory <State > getStateFactory () {
141
+ return stateSerializer .stateFactory ();
142
+ }
144
143
145
144
public Map <String , Channel <?>> getChannels () {
146
145
return unmodifiableMap (channels );
0 commit comments