Skip to content

fix(litellm): preserve reasoning replay and optionally share agent thoughts#5572

Open
lorenzbaraldi wants to merge 1 commit intogoogle:mainfrom
lorenzbaraldi:feature/pass_reasoning_content
Open

fix(litellm): preserve reasoning replay and optionally share agent thoughts#5572
lorenzbaraldi wants to merge 1 commit intogoogle:mainfrom
lorenzbaraldi:feature/pass_reasoning_content

Conversation

@lorenzbaraldi
Copy link
Copy Markdown

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):

  • 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:

  • I have added or updated unit tests for my change.
  • 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

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • 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.

@lorenzbaraldi lorenzbaraldi changed the title Add option to include thoughts from other agents in LLM context fix(litellm): preserve reasoning replay and optionally share agent thoughts May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant