Repository navigation
fix(litellm): preserve reasoning replay and optionally share agent thoughts - #5572
Closed
lorenzbaraldi wants to merge 2 commits into
Closed
lorenzbaraldi wants to merge 2 commits into
lorenzbaraldi wants to merge 2 commits into
Conversation
|
This could be very useful! Looking forward to it |
Collaborator
|
Hi @lorenzbaraldi , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Please fix failing mypy-diff tests. |
Contributor
Author
|
Hi @rohityan thanks for pointing that out. It should be fixed now |
Collaborator
|
Hi @lorenzbaraldi , could you please resolve the branch conflicts |
lorenzbaraldi
force-pushed
the
feature/pass_reasoning_content
branch
from
June 2, 2026 09:56
c5ae71f to
7d6d3e6
Compare
Contributor
Author
|
Hi @rohityan I resolved the branch conflicts, and I was wondering if there are any remaining concerns or if it’s waiting for a maintainer review. In any case, thanks for taking the time to have a look |
Collaborator
|
Thank you @lorenzbaraldi for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 6290aec. Closing this PR as the changes are now in the main branch. |
copybara-service Bot
pushed a commit
that referenced
this pull request
Jul 8, 2026
…oughts 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: 944562507
FrigaZzz
pushed a commit
to FrigaZzz/adk-python
that referenced
this pull request
Aug 11, 2026
…oughts Merge google#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=google#5572 from lorenzbaraldi:feature/pass_reasoning_content 7d6d3e6 PiperOrigin-RevId: 944562507
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
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_agentsflag. The default remainsFalse, 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-sidethought=Trueparts.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:
Passed locally:
uv run --extra test pytest tests/unittests/models/test_litellm.py257 passeduv run --extra test pytest tests/unittests/flows/llm_flows/test_contents_other_agent.py12 passedManual 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
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.