7
7
8
8
### Adding LangGraph dependency
9
9
10
- Currently are available only the developer SNAPSHOTs
10
+ > 👉 Currently are available only the developer SNAPSHOTs
11
11
12
12
** Maven**
13
13
14
- ** JDK8 compliant **
14
+ ** JDK8 compliant**
15
15
``` xml
16
16
<dependency >
17
17
<groupId >org.bsc.langgraph4j</groupId >
@@ -21,7 +21,7 @@ Currently are available only the developer SNAPSHOTs
21
21
<dependency >
22
22
```
23
23
24
- ** JDK17 compliant **
24
+ ** JDK17 compliant**
25
25
``` xml
26
26
<dependency >
27
27
<groupId >org.bsc.langgraph4j</groupId >
@@ -71,63 +71,63 @@ Below you can find a piece of code of the `AgentExecutor` to give you an idea of
71
71
72
72
``` java
73
73
74
- public static class State implements AgentState {
74
+ public static class State implements AgentState {
75
75
76
- private final Map<String ,Object > data;
76
+ private final Map<String ,Object > data;
77
77
78
- public State ( Map<String ,Object > initData ) {
79
- this . data = new HashMap<> (initData);
80
- this . data. putIfAbsent(" intermediate_steps" ,
81
- new AppendableValue<IntermediateStep > ());
82
- }
78
+ public State ( Map<String ,Object > initData ) {
79
+ this . data = new HashMap<> (initData);
80
+ this . data. putIfAbsent(" intermediate_steps" ,
81
+ new AppendableValue<IntermediateStep > ());
82
+ }
83
83
84
- public Map<String ,Object > data () { return Map . copyOf(data); }
84
+ public Map<String ,Object > data () { return Map . copyOf(data); }
85
85
86
- Optional<String > input () { return value(" input" ); }
87
- Optional<AgentOutcome > agentOutcome () { return value(" agent_outcome" ); }
88
- Optional<List<IntermediateStep > > intermediateSteps () { return appendableValue(" intermediate_steps" ); }
89
- }
86
+ Optional<String > input () { return value(" input" ); }
87
+ Optional<AgentOutcome > agentOutcome () { return value(" agent_outcome" ); }
88
+ Optional<List<IntermediateStep > > intermediateSteps () { return appendableValue(" intermediate_steps" ); }
89
+ }
90
90
91
91
92
- var toolInfoList = ToolInfo . fromList( objectsWithTools );
92
+ var toolInfoList = ToolInfo . fromList( objectsWithTools );
93
93
94
- final List<ToolSpecification > toolSpecifications = toolInfoList. stream()
95
- .map(ToolInfo :: specification)
96
- .toList();
94
+ final List<ToolSpecification > toolSpecifications = toolInfoList. stream()
95
+ .map(ToolInfo :: specification)
96
+ .toList();
97
97
98
- var agentRunnable = Agent . builder()
99
- .chatLanguageModel(chatLanguageModel)
100
- .tools( toolSpecifications )
101
- .build();
98
+ var agentRunnable = Agent . builder()
99
+ .chatLanguageModel(chatLanguageModel)
100
+ .tools( toolSpecifications )
101
+ .build();
102
102
103
- var workflow = new GraphState<> (State :: new );
103
+ var workflow = new GraphState<> (State :: new );
104
104
105
- workflow. setEntryPoint(" agent" );
105
+ workflow. setEntryPoint(" agent" );
106
106
107
- workflow. addNode( " agent" , node_async( state - >
108
- runAgent(agentRunnable, state)) // see implementation in the repo code
109
- );
107
+ workflow. addNode( " agent" , node_async( state - >
108
+ runAgent(agentRunnable, state)) // see implementation in the repo code
109
+ );
110
110
111
- workflow. addNode( " action" , node_async( state - >
112
- executeTools(toolInfoList, state)) // see implementation in the repo code
113
- );
111
+ workflow. addNode( " action" , node_async( state - >
112
+ executeTools(toolInfoList, state)) // see implementation in the repo code
113
+ );
114
114
115
- workflow. addConditionalEdge(
116
- " agent" ,
117
- edge_async( state - > {
118
- if (state. agentOutcome(). map(AgentOutcome :: finish). isPresent()) {
119
- return " end" ;
120
- }
121
- return " continue" ;
122
- }),
123
- Map . of(" continue" , " action" , " end" , END )
124
- );
115
+ workflow. addConditionalEdge(
116
+ " agent" ,
117
+ edge_async( state - > {
118
+ if (state. agentOutcome(). map(AgentOutcome :: finish). isPresent()) {
119
+ return " end" ;
120
+ }
121
+ return " continue" ;
122
+ }),
123
+ Map . of(" continue" , " action" , " end" , END )
124
+ );
125
125
126
- workflow. addEdge(" action" , " agent" );
126
+ workflow. addEdge(" action" , " agent" );
127
127
128
- var app = workflow. compile();
128
+ var app = workflow. compile();
129
129
130
- return app. stream( inputs );
130
+ return app. stream( inputs );
131
131
132
132
```
133
133
0 commit comments