Commit 6290aec
fix(litellm): preserve reasoning replay and optionally share agent thoughts
Merge #5572
**Please ensure you have read the [contribution guide](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) before creating a pull request.**
### Link to Issue or Description of Change
**1. Link to an existing issue (if applicable):**
- Closes: N/A
- Related: N/A
**2. Or, if no issue exists, describe the change:**
**Problem:**
LiteLLM-backed reasoning content can be streamed as small text fragments, notably with vLLM. ADK stores those fragments as separate `Part(thought=True)` entries. When replaying prior assistant/model thoughts back into LiteLLM, ADK previously joined those fragments with newlines, which changed the original reasoning text.
In multi-agent flows, ADK also always excluded thoughts from other agents when presenting their messages as context. That default is privacy-preserving, but it removes a useful coordination signal for advanced multi-agent systems. For example, an orchestrator, reviewer, planner, or supervisor agent may benefit from seeing another agent’s reasoning trail when deciding whether to continue, retry, delegate, or synthesize results.
**Solution:**
This PR updates LiteLLM reasoning replay so plain thought text fragments are concatenated without inserting separators. This preserves vLLM-style streamed reasoning chunks when ADK sends previous model output back to LiteLLM.
The PR also adds an opt-in `RunConfig.include_thoughts_from_other_agents` flag. The default remains `False`, so existing behavior and privacy expectations are preserved. When enabled for full-history context, other-agent thoughts are converted into explicit user-context text, e.g. `[agent] thought: ...`, so downstream model adapters do not drop them as user-side `thought=True` parts.
The option is intentionally developer-controlled because whether reasoning should cross agent boundaries is application-specific. It can be valuable in orchestrated systems where agents are trusted collaborators and reasoning improves handoff quality, but it should not be enabled silently for all apps.
### Testing Plan
**Unit Tests:**
- [x] I have added or updated unit tests for my change.
- [x] All unit tests pass locally.
Passed locally:
- `uv run --extra test pytest tests/unittests/models/test_litellm.py`
- `257 passed`
- `uv run --extra test pytest tests/unittests/flows/llm_flows/test_contents_other_agent.py`
- `12 passed`
**Manual End-to-End (E2E) Tests:**
Not run. The change is covered by focused unit tests for LiteLLM reasoning replay and other-agent context construction.
### Checklist
- [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] New and existing unit tests pass locally with my changes.
- [ ] I have manually tested my changes end-to-end.
- [ ] Any dependent changes have been merged and published in downstream modules.
### Additional context
The other-agent thought sharing behavior is deliberately opt-in. In many apps, thoughts should remain private and excluded from cross-agent context. In more controlled multi-agent systems, however, exposing reasoning to orchestrator-like agents can improve routing, recovery, auditing, and synthesis decisions.
This may not be the final API shape for the capability, but having an explicit option to include other agents’ reasoning is useful and worth discussing.
Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=#5572 from lorenzbaraldi:feature/pass_reasoning_content 7d6d3e6
PiperOrigin-RevId: 9445625071 parent 7cb5ebe commit 6290aec
5 files changed
Lines changed: 211 additions & 25 deletions
File tree
- src/google/adk
- agents
- flows/llm_flows
- models
- tests/unittests
- flows/llm_flows
- models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
382 | 390 | | |
383 | 391 | | |
384 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
| |||
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
| 102 | + | |
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| 114 | + | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
| |||
274 | 282 | | |
275 | 283 | | |
276 | 284 | | |
277 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
278 | 288 | | |
279 | 289 | | |
280 | 290 | | |
| |||
294 | 304 | | |
295 | 305 | | |
296 | 306 | | |
297 | | - | |
| 307 | + | |
298 | 308 | | |
299 | 309 | | |
300 | 310 | | |
| |||
303 | 313 | | |
304 | 314 | | |
305 | 315 | | |
306 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
307 | 319 | | |
308 | 320 | | |
309 | 321 | | |
| |||
325 | 337 | | |
326 | 338 | | |
327 | 339 | | |
328 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
329 | 344 | | |
330 | 345 | | |
331 | 346 | | |
| |||
393 | 408 | | |
394 | 409 | | |
395 | 410 | | |
| 411 | + | |
| 412 | + | |
396 | 413 | | |
397 | 414 | | |
398 | 415 | | |
| |||
418 | 435 | | |
419 | 436 | | |
420 | 437 | | |
421 | | - | |
| 438 | + | |
422 | 439 | | |
423 | 440 | | |
424 | 441 | | |
| |||
577 | 594 | | |
578 | 595 | | |
579 | 596 | | |
| 597 | + | |
580 | 598 | | |
581 | 599 | | |
582 | 600 | | |
| |||
592 | 610 | | |
593 | 611 | | |
594 | 612 | | |
| 613 | + | |
| 614 | + | |
595 | 615 | | |
596 | 616 | | |
597 | 617 | | |
| |||
624 | 644 | | |
625 | 645 | | |
626 | 646 | | |
627 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
628 | 654 | | |
629 | 655 | | |
630 | 656 | | |
| |||
699 | 725 | | |
700 | 726 | | |
701 | 727 | | |
702 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
703 | 731 | | |
704 | 732 | | |
705 | 733 | | |
| |||
752 | 780 | | |
753 | 781 | | |
754 | 782 | | |
| 783 | + | |
755 | 784 | | |
756 | 785 | | |
757 | 786 | | |
| |||
768 | 797 | | |
769 | 798 | | |
770 | 799 | | |
| 800 | + | |
| 801 | + | |
771 | 802 | | |
772 | 803 | | |
773 | 804 | | |
| |||
778 | 809 | | |
779 | 810 | | |
780 | 811 | | |
781 | | - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
782 | 819 | | |
783 | 820 | | |
784 | 821 | | |
| |||
791 | 828 | | |
792 | 829 | | |
793 | 830 | | |
| 831 | + | |
794 | 832 | | |
795 | 833 | | |
796 | 834 | | |
| |||
851 | 889 | | |
852 | 890 | | |
853 | 891 | | |
854 | | - | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
855 | 895 | | |
856 | 896 | | |
857 | 897 | | |
858 | 898 | | |
859 | 899 | | |
860 | 900 | | |
861 | 901 | | |
| 902 | + | |
| 903 | + | |
862 | 904 | | |
863 | 905 | | |
864 | 906 | | |
| |||
872 | 914 | | |
873 | 915 | | |
874 | 916 | | |
875 | | - | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
876 | 921 | | |
877 | 922 | | |
878 | 923 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
885 | 907 | | |
886 | 908 | | |
887 | 909 | | |
| |||
1088 | 1110 | | |
1089 | 1111 | | |
1090 | 1112 | | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | 1113 | | |
1104 | 1114 | | |
1105 | 1115 | | |
| |||
1128 | 1138 | | |
1129 | 1139 | | |
1130 | 1140 | | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
| 1141 | + | |
1134 | 1142 | | |
1135 | 1143 | | |
1136 | 1144 | | |
| |||
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
88 | 194 | | |
89 | 195 | | |
90 | 196 | | |
| |||
0 commit comments