24
24
import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newStyleEditor ;
25
25
import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newStyleScorer ;
26
26
import static io .serverlessworkflow .fluent .agentic .AgentsUtils .newSummaryStory ;
27
- import static io .serverlessworkflow .fluent .agentic .dsl .AgenticDSL .fn ;
28
27
import static io .serverlessworkflow .fluent .agentic .langchain4j .Agents .*;
29
28
import static io .serverlessworkflow .fluent .agentic .langchain4j .Agents .AudienceEditor ;
30
29
import static io .serverlessworkflow .fluent .agentic .langchain4j .Agents .CreativeWriter ;
31
30
import static io .serverlessworkflow .fluent .agentic .langchain4j .Agents .StyleEditor ;
32
31
import static io .serverlessworkflow .fluent .agentic .langchain4j .Models .BASE_MODEL ;
33
32
import static org .junit .jupiter .api .Assertions .assertEquals ;
34
33
import static org .junit .jupiter .api .Assertions .assertNotNull ;
35
- import static org .junit .jupiter .api .Assertions .assertTrue ;
36
34
import static org .mockito .ArgumentMatchers .any ;
37
35
import static org .mockito .ArgumentMatchers .eq ;
38
36
import static org .mockito .Mockito .spy ;
48
46
import java .util .function .Function ;
49
47
import java .util .function .Predicate ;
50
48
import java .util .stream .IntStream ;
51
-
52
49
import org .junit .jupiter .api .Test ;
53
50
54
51
public class WorkflowAgentsIT {
@@ -106,9 +103,9 @@ public void sequenceHelperTest() {
106
103
var styleEditor = newStyleEditor ();
107
104
108
105
AgentsUtils .NovelCreator novelCreator =
109
- io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
110
- .flow (workflow ("seqFlow" ).sequence (creativeWriter , audienceEditor , styleEditor ))
111
- .build ();
106
+ io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
107
+ .flow (workflow ("seqFlow" ).sequence (creativeWriter , audienceEditor , styleEditor ))
108
+ .build ();
112
109
113
110
String story = novelCreator .createNovel ("dragons and wizards" , "young adults" , "fantasy" );
114
111
assertNotNull (story );
@@ -121,9 +118,9 @@ public void agentAndSequenceHelperTest() {
121
118
var styleEditor = newStyleEditor ();
122
119
123
120
AgentsUtils .NovelCreator novelCreator =
124
- io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
125
- .flow (workflow ("seqFlow" ).agent (creativeWriter ).sequence (audienceEditor , styleEditor ))
126
- .build ();
121
+ io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
122
+ .flow (workflow ("seqFlow" ).agent (creativeWriter ).sequence (audienceEditor , styleEditor ))
123
+ .build ();
127
124
128
125
String story = novelCreator .createNovel ("dragons and wizards" , "young adults" , "fantasy" );
129
126
assertNotNull (story );
@@ -137,13 +134,13 @@ public void agentAndSequenceAndAgentHelperTest() {
137
134
var summaryStory = newSummaryStory ();
138
135
139
136
AgentsUtils .NovelCreator novelCreator =
140
- io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
141
- .flow (
142
- workflow ("seqFlow" )
143
- .agent (creativeWriter )
144
- .sequence (audienceEditor , styleEditor )
145
- .agent (summaryStory ))
146
- .build ();
137
+ io .serverlessworkflow .fluent .agentic .AgenticServices .of (AgentsUtils .NovelCreator .class )
138
+ .flow (
139
+ workflow ("seqFlow" )
140
+ .agent (creativeWriter )
141
+ .sequence (audienceEditor , styleEditor )
142
+ .agent (summaryStory ))
143
+ .build ();
147
144
148
145
String story = novelCreator .createNovel ("dragons and wizards" , "young adults" , "fantasy" );
149
146
assertNotNull (story );
@@ -155,20 +152,20 @@ public void parallelWorkflow() {
155
152
var movieExpert = newMovieExpert ();
156
153
157
154
Function <Map <String , List <String >>, List <EveningPlan >> planEvening =
158
- input -> {
159
- List <String > movies = input .get ("findMovie" );
160
- List <String > meals = input .get ("findMeal" );
155
+ input -> {
156
+ List <String > movies = input .get ("findMovie" );
157
+ List <String > meals = input .get ("findMeal" );
161
158
162
- int max = Math .min (movies .size (), meals .size ());
163
- return IntStream .range (0 , max )
164
- .mapToObj (i -> new EveningPlan (movies .get (i ), meals .get (i )))
165
- .toList ();
166
- };
159
+ int max = Math .min (movies .size (), meals .size ());
160
+ return IntStream .range (0 , max )
161
+ .mapToObj (i -> new EveningPlan (movies .get (i ), meals .get (i )))
162
+ .toList ();
163
+ };
167
164
168
165
EveningPlannerAgent eveningPlannerAgent =
169
- AgenticServices .of (EveningPlannerAgent .class )
170
- .flow (workflow ("parallelFlow" ).parallel (foodExpert , movieExpert ).outputAs (planEvening ))
171
- .build ();
166
+ AgenticServices .of (EveningPlannerAgent .class )
167
+ .flow (workflow ("parallelFlow" ).parallel (foodExpert , movieExpert ).outputAs (planEvening ))
168
+ .build ();
172
169
List <EveningPlan > result = eveningPlannerAgent .plan ("romantic" );
173
170
assertEquals (3 , result .size ());
174
171
}
@@ -182,9 +179,9 @@ public void loopTest() {
182
179
Predicate <AgenticScope > until = s -> s .readState ("score" , 0.0 ) >= 0.8 ;
183
180
184
181
StyledWriter styledWriter =
185
- AgenticServices .of (StyledWriter .class )
186
- .flow (workflow ("loopFlow" ).agent (creativeWriter ).loop (until , scorer , editor ))
187
- .build ();
182
+ AgenticServices .of (StyledWriter .class )
183
+ .flow (workflow ("loopFlow" ).agent (creativeWriter ).loop (until , scorer , editor ))
184
+ .build ();
188
185
189
186
String story = styledWriter .writeStoryWithStyle ("dragons and wizards" , "fantasy" );
190
187
assertNotNull (story );
@@ -195,25 +192,25 @@ public void humanInTheLoop() {
195
192
var astrologyAgent = newAstrologyAgent ();
196
193
197
194
var askSign =
198
- new Function <Map <String , Object >, Map <String , Object >>() {
199
- @ Override
200
- public Map <String , Object > apply (Map <String , Object > holder ) {
201
- System .out .println ("What's your star sign?" );
202
- // var sign = System.console().readLine();
203
- holder .put ("sign" , "piscis" );
204
- return holder ;
205
- }
206
- };
195
+ new Function <Map <String , Object >, Map <String , Object >>() {
196
+ @ Override
197
+ public Map <String , Object > apply (Map <String , Object > holder ) {
198
+ System .out .println ("What's your star sign?" );
199
+ // var sign = System.console().readLine();
200
+ holder .put ("sign" , "piscis" );
201
+ return holder ;
202
+ }
203
+ };
207
204
208
205
String result =
209
- AgenticServices .of (Agents .HoroscopeAgent .class )
210
- .flow (
211
- workflow ("humanInTheLoop" )
212
- .inputFrom (askSign )
213
- // .tasks(tasks -> tasks.callFn(fn(askSign))) // TODO should work too
214
- .agent (astrologyAgent ))
215
- .build ()
216
- .invoke ("My name is Mario. What is my horoscope?" );
206
+ AgenticServices .of (Agents .HoroscopeAgent .class )
207
+ .flow (
208
+ workflow ("humanInTheLoop" )
209
+ .inputFrom (askSign )
210
+ // .tasks(tasks -> tasks.callFn(fn(askSign))) // TODO should work too
211
+ .agent (astrologyAgent ))
212
+ .build ()
213
+ .invoke ("My name is Mario. What is my horoscope?" );
217
214
218
215
assertNotNull (result );
219
216
}
0 commit comments