@@ -110,4 +110,52 @@ public void runAsync_noSubAgents_returnsEmptyFlowable() {
110110
111111 assertThat (events ).isEmpty ();
112112 }
113+
114+ static class BlockingAgent extends BaseAgent {
115+ private final long sleepMillis ;
116+
117+ private BlockingAgent (String name , long sleepMillis ) {
118+ super (name , "Blocking Agent" , ImmutableList .of (), null , null );
119+ this .sleepMillis = sleepMillis ;
120+ }
121+
122+ @ Override
123+ protected Flowable <Event > runAsyncImpl (InvocationContext invocationContext ) {
124+ return Flowable .fromCallable (
125+ () -> {
126+ Thread .sleep (sleepMillis );
127+ return Event .builder ()
128+ .author (name ())
129+ .branch (invocationContext .branch ().orElse (null ))
130+ .invocationId (invocationContext .invocationId ())
131+ .content (Content .fromParts (Part .fromText ("Done" )))
132+ .build ();
133+ });
134+ }
135+
136+ @ Override
137+ protected Flowable <Event > runLiveImpl (InvocationContext invocationContext ) {
138+ throw new UnsupportedOperationException ("Not implemented" );
139+ }
140+ }
141+
142+ @ Test
143+ public void runAsync_blockingSubAgents_shouldExecuteInParallel () {
144+ long sleepTime = 1000 ;
145+ BlockingAgent agent1 = new BlockingAgent ("agent1" , sleepTime );
146+ BlockingAgent agent2 = new BlockingAgent ("agent2" , sleepTime );
147+
148+ ParallelAgent parallelAgent =
149+ ParallelAgent .builder ().name ("parallel_agent" ).subAgents (agent1 , agent2 ).build ();
150+
151+ InvocationContext invocationContext = createInvocationContext (parallelAgent );
152+
153+ long startTime = System .currentTimeMillis ();
154+ List <Event > events = parallelAgent .runAsync (invocationContext ).toList ().blockingGet ();
155+ long duration = System .currentTimeMillis () - startTime ;
156+
157+ assertThat (events ).hasSize (2 );
158+ // If parallel, duration should be less than 2 * sleepTime (2000ms).
159+ assertThat (duration ).isLessThan ((long ) (2.0 * sleepTime ));
160+ }
113161}
0 commit comments