Repository navigation
Commit 7470b43
committed
fix(flows): avoid StackOverflowError after many steps in BaseLlmFlow
BaseLlmFlow.run subscribed to the next step from inside the previous
step's completion, through concatWith, toList, flatMapPublisher and
PersistBarrier.awaitPersisted(...).andThen(run(...)). When a step
completed on the subscribing thread, as it does with the core models
and the session services, each step ran 23 stack frames deeper than
the one before. With a 1 MB thread stack, the default on x86-64, an
agent that kept calling tools failed with StackOverflowError after
roughly 250-300 LLM calls, before the default maxLlmCalls of 500
could end the run, and the error never reached onError.
Drive the steps with repeatUntil instead, as LoopAgent does on its
resumable path. repeatUntil resubscribes from a loop when the source
completes synchronously, so every step starts at the same stack
depth, like the while loop in adk-python's BaseLlmFlow.run_async.
The end-of-flow checks, the pause on a pending long-running call,
the PersistBarrier wait between steps and maxSteps are unchanged.1 parent 2d4a59e commit 7470b43
2 files changed
Lines changed: 55 additions & 5 deletions
File tree
- core/src
- main/java/com/google/adk/flows/llmflows
- test/java/com/google/adk/flows/llmflows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
523 | 524 | | |
524 | 525 | | |
525 | 526 | | |
526 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
527 | 542 | | |
528 | 543 | | |
529 | | - | |
530 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
531 | 553 | | |
532 | 554 | | |
533 | 555 | | |
| |||
554 | 576 | | |
555 | 577 | | |
556 | 578 | | |
| 579 | + | |
557 | 580 | | |
558 | 581 | | |
559 | | - | |
560 | | - | |
| 582 | + | |
561 | 583 | | |
562 | 584 | | |
563 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
194 | 222 | | |
195 | 223 | | |
196 | 224 | | |
| |||
0 commit comments