36
36
37
37
class WorkflowTests {
38
38
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
+
39
97
@ Test
40
98
public void testSequence () throws ExecutionException , InterruptedException {
41
99
final StorySeedAgent storySeedAgent = mock (StorySeedAgent .class );
@@ -48,7 +106,7 @@ public void testSequence() throws ExecutionException, InterruptedException {
48
106
when (plotAgent .invoke (eq ("storySeedAgent" ))).thenReturn ("plotAgent" );
49
107
when (plotAgent .outputName ()).thenReturn ("plot" );
50
108
51
- when (sceneAgent .invoke (eq ("plotAgent" ))).thenReturn ("plotAgent " );
109
+ when (sceneAgent .invoke (eq ("plotAgent" ))).thenReturn ("sceneAgent " );
52
110
when (sceneAgent .outputName ()).thenReturn ("story" );
53
111
54
112
Workflow workflow =
@@ -63,7 +121,7 @@ public void testSequence() throws ExecutionException, InterruptedException {
63
121
String result =
64
122
app .workflowDefinition (workflow ).instance (topic ).start ().get ().asText ().orElseThrow ();
65
123
66
- assertEquals ("plotAgent " , result );
124
+ assertEquals ("sceneAgent " , result );
67
125
}
68
126
}
69
127
0 commit comments