|
47 | 47 | import io.reactivex.rxjava3.core.Single; |
48 | 48 | import io.reactivex.rxjava3.disposables.Disposable; |
49 | 49 | import io.reactivex.rxjava3.functions.Function; |
| 50 | +import io.reactivex.rxjava3.schedulers.Schedulers; |
50 | 51 | import java.util.ArrayList; |
51 | 52 | import java.util.HashMap; |
52 | 53 | import java.util.HashSet; |
@@ -154,13 +155,16 @@ public static Maybe<Event> handleFunctionCalls( |
154 | 155 | getFunctionCallMapper(invocationContext, tools, toolConfirmations, false, parentContext); |
155 | 156 |
|
156 | 157 | Observable<Event> functionResponseEventsObservable; |
157 | | - if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) { |
| 158 | + if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL |
| 159 | + || validFunctionCalls.size() <= 1) { |
158 | 160 | functionResponseEventsObservable = |
159 | 161 | Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper); |
160 | 162 | } else { |
161 | 163 | functionResponseEventsObservable = |
162 | 164 | Observable.fromIterable(validFunctionCalls) |
163 | | - .concatMapEager(call -> functionCallMapper.apply(call).toObservable()); |
| 165 | + .concatMapEager( |
| 166 | + call -> |
| 167 | + functionCallMapper.apply(call).toObservable().subscribeOn(Schedulers.io())); |
164 | 168 | } |
165 | 169 | return functionResponseEventsObservable |
166 | 170 | .toList() |
@@ -225,13 +229,16 @@ public static Maybe<Event> handleFunctionCallsLive( |
225 | 229 | getFunctionCallMapper(invocationContext, tools, toolConfirmations, true, parentContext); |
226 | 230 |
|
227 | 231 | Observable<Event> responseEventsObservable; |
228 | | - if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL) { |
| 232 | + if (invocationContext.runConfig().toolExecutionMode() == ToolExecutionMode.SEQUENTIAL |
| 233 | + || validFunctionCalls.size() <= 1) { |
229 | 234 | responseEventsObservable = |
230 | 235 | Observable.fromIterable(validFunctionCalls).concatMapMaybe(functionCallMapper); |
231 | 236 | } else { |
232 | 237 | responseEventsObservable = |
233 | 238 | Observable.fromIterable(validFunctionCalls) |
234 | | - .concatMapEager(call -> functionCallMapper.apply(call).toObservable()); |
| 239 | + .concatMapEager( |
| 240 | + call -> |
| 241 | + functionCallMapper.apply(call).toObservable().subscribeOn(Schedulers.io())); |
235 | 242 | } |
236 | 243 |
|
237 | 244 | return responseEventsObservable |
|
0 commit comments