fix(litellm): preserve reasoning replay and optionally share agent thoughts#5572
Open
lorenzbaraldi wants to merge 1 commit intogoogle:mainfrom
Open
fix(litellm): preserve reasoning replay and optionally share agent thoughts#5572lorenzbaraldi wants to merge 1 commit intogoogle:mainfrom
lorenzbaraldi wants to merge 1 commit intogoogle:mainfrom
Conversation
… and merge reasoning chunks
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.