Skip to content

Commit 517257b

Browse files
committed
add agent test
Signed-off-by: Dmitrii Tikhomirov <[email protected]>
1 parent 0b9dd4a commit 517257b

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/WorkflowTests.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,64 @@
3636

3737
class WorkflowTests {
3838

39+
@Test
40+
public void testAgent() throws ExecutionException, InterruptedException {
41+
final StorySeedAgent storySeedAgent = mock(StorySeedAgent.class);
42+
43+
when(storySeedAgent.invoke(eq("A Great Story"))).thenReturn("storySeedAgent");
44+
when(storySeedAgent.outputName()).thenReturn("premise");
45+
46+
Workflow workflow =
47+
AgentWorkflowBuilder.workflow("storyFlow")
48+
.tasks(d -> d.agent("story", storySeedAgent))
49+
.build();
50+
51+
Map<String, String> topic = new HashMap<>();
52+
topic.put("title", "A Great Story");
53+
54+
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
55+
String result =
56+
app.workflowDefinition(workflow).instance(topic).start().get().asText().orElseThrow();
57+
58+
assertEquals("storySeedAgent", result);
59+
}
60+
}
61+
62+
@Test
63+
public void testAgents() throws ExecutionException, InterruptedException {
64+
final StorySeedAgent storySeedAgent = mock(StorySeedAgent.class);
65+
final PlotAgent plotAgent = mock(PlotAgent.class);
66+
final SceneAgent sceneAgent = mock(SceneAgent.class);
67+
68+
when(storySeedAgent.invoke(eq("A Great Story"))).thenReturn("storySeedAgent");
69+
when(storySeedAgent.outputName()).thenReturn("premise");
70+
71+
when(plotAgent.invoke(eq("storySeedAgent"))).thenReturn("plotAgent");
72+
when(plotAgent.outputName()).thenReturn("plot");
73+
74+
when(sceneAgent.invoke(eq("plotAgent"))).thenReturn("sceneAgent");
75+
when(sceneAgent.outputName()).thenReturn("story");
76+
77+
Workflow workflow =
78+
AgentWorkflowBuilder.workflow("storyFlow")
79+
.tasks(
80+
d ->
81+
d.agent("story", storySeedAgent)
82+
.agent("plot", plotAgent)
83+
.agent("scene", sceneAgent))
84+
.build();
85+
86+
Map<String, String> topic = new HashMap<>();
87+
topic.put("title", "A Great Story");
88+
89+
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
90+
String result =
91+
app.workflowDefinition(workflow).instance(topic).start().get().asText().orElseThrow();
92+
93+
assertEquals("sceneAgent", result);
94+
}
95+
}
96+
3997
@Test
4098
public void testSequence() throws ExecutionException, InterruptedException {
4199
final StorySeedAgent storySeedAgent = mock(StorySeedAgent.class);
@@ -48,7 +106,7 @@ public void testSequence() throws ExecutionException, InterruptedException {
48106
when(plotAgent.invoke(eq("storySeedAgent"))).thenReturn("plotAgent");
49107
when(plotAgent.outputName()).thenReturn("plot");
50108

51-
when(sceneAgent.invoke(eq("plotAgent"))).thenReturn("plotAgent");
109+
when(sceneAgent.invoke(eq("plotAgent"))).thenReturn("sceneAgent");
52110
when(sceneAgent.outputName()).thenReturn("story");
53111

54112
Workflow workflow =
@@ -63,7 +121,7 @@ public void testSequence() throws ExecutionException, InterruptedException {
63121
String result =
64122
app.workflowDefinition(workflow).instance(topic).start().get().asText().orElseThrow();
65123

66-
assertEquals("plotAgent", result);
124+
assertEquals("sceneAgent", result);
67125
}
68126
}
69127

0 commit comments

Comments
 (0)