Skip to content

Commit bfec4eb

Browse files
committed
parallelWorkflow() works
Signed-off-by: Dmitrii Tikhomirov <[email protected]>
1 parent 381d0e9 commit bfec4eb

File tree

1 file changed

+44
-47
lines changed
  • experimental/fluent/agentic-langchain4j/src/test/java/io/serverlessworkflow/fluent/agentic/langchain4j

1 file changed

+44
-47
lines changed

experimental/fluent/agentic-langchain4j/src/test/java/io/serverlessworkflow/fluent/agentic/langchain4j/WorkflowAgentsIT.java

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import static io.serverlessworkflow.fluent.agentic.AgentsUtils.newStyleEditor;
2525
import static io.serverlessworkflow.fluent.agentic.AgentsUtils.newStyleScorer;
2626
import static io.serverlessworkflow.fluent.agentic.AgentsUtils.newSummaryStory;
27-
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.fn;
2827
import static io.serverlessworkflow.fluent.agentic.langchain4j.Agents.*;
2928
import static io.serverlessworkflow.fluent.agentic.langchain4j.Agents.AudienceEditor;
3029
import static io.serverlessworkflow.fluent.agentic.langchain4j.Agents.CreativeWriter;
3130
import static io.serverlessworkflow.fluent.agentic.langchain4j.Agents.StyleEditor;
3231
import static io.serverlessworkflow.fluent.agentic.langchain4j.Models.BASE_MODEL;
3332
import static org.junit.jupiter.api.Assertions.assertEquals;
3433
import static org.junit.jupiter.api.Assertions.assertNotNull;
35-
import static org.junit.jupiter.api.Assertions.assertTrue;
3634
import static org.mockito.ArgumentMatchers.any;
3735
import static org.mockito.ArgumentMatchers.eq;
3836
import static org.mockito.Mockito.spy;
@@ -48,7 +46,6 @@
4846
import java.util.function.Function;
4947
import java.util.function.Predicate;
5048
import java.util.stream.IntStream;
51-
5249
import org.junit.jupiter.api.Test;
5350

5451
public class WorkflowAgentsIT {
@@ -106,9 +103,9 @@ public void sequenceHelperTest() {
106103
var styleEditor = newStyleEditor();
107104

108105
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();
112109

113110
String story = novelCreator.createNovel("dragons and wizards", "young adults", "fantasy");
114111
assertNotNull(story);
@@ -121,9 +118,9 @@ public void agentAndSequenceHelperTest() {
121118
var styleEditor = newStyleEditor();
122119

123120
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();
127124

128125
String story = novelCreator.createNovel("dragons and wizards", "young adults", "fantasy");
129126
assertNotNull(story);
@@ -137,13 +134,13 @@ public void agentAndSequenceAndAgentHelperTest() {
137134
var summaryStory = newSummaryStory();
138135

139136
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();
147144

148145
String story = novelCreator.createNovel("dragons and wizards", "young adults", "fantasy");
149146
assertNotNull(story);
@@ -155,20 +152,20 @@ public void parallelWorkflow() {
155152
var movieExpert = newMovieExpert();
156153

157154
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");
161158

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+
};
167164

168165
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();
172169
List<EveningPlan> result = eveningPlannerAgent.plan("romantic");
173170
assertEquals(3, result.size());
174171
}
@@ -182,9 +179,9 @@ public void loopTest() {
182179
Predicate<AgenticScope> until = s -> s.readState("score", 0.0) >= 0.8;
183180

184181
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();
188185

189186
String story = styledWriter.writeStoryWithStyle("dragons and wizards", "fantasy");
190187
assertNotNull(story);
@@ -195,25 +192,25 @@ public void humanInTheLoop() {
195192
var astrologyAgent = newAstrologyAgent();
196193

197194
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+
};
207204

208205
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?");
217214

218215
assertNotNull(result);
219216
}

0 commit comments

Comments
 (0)