Skip to content

feat(models): send the ADK session id to a LiteLLM proxy - #8187

Open
thomaslprr wants to merge 1 commit into
google:mainfrom
thomaslprr:feat/litellm-propagate-session-id
Open

thomaslprr wants to merge 1 commit into
google:mainfrom
thomaslprr:feat/litellm-propagate-session-id

Conversation

@thomaslprr

@thomaslprr thomaslprr commented Nov 16, 2026 •

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:

LiteLlm does not tell a LiteLLM Proxy which conversation a call belongs to, so the proxy logs every call of an ADK session under a different session_id and the calls cannot be grouped per conversation.

Solution:

  • LlmRequest.session_id: a new optional field, exclude=True so that model_dump() output (recorded or traced requests) does not change.
  • The LLM flow sets it from invocation_context.session.id, next to the adk_agent_name label, unless it is already set.
  • LiteLlm sends it as the x-litellm-session-id header when the model is served through a LiteLLM Proxy (the existing _is_proxied_model check).

Behavior that does not change:

  • Providers other than the proxy receive nothing new.
  • No header when the request has no session id (calls made outside a Runner).
  • A session id header set by the caller, in extra_headers or in http_options.headers, is kept.

Out of scope: the native Gemini model (the Gemini API has no session to map to) and live mode.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
$ pytest tests/unittests/models tests/unittests/flows tests/unittests/agents tests/unittests/runners tests/unittests/plugins -q -n auto
6452 passed, 4 skipped, 4 xfailed
  • tests/unittests/models/test_litellm.py: header sent for a proxied model (prefix and custom_llm_provider), not sent to a direct provider, not sent without a session id, caller's header kept (constructor and http_options), other extra headers preserved, session_id absent from model_dump().
  • tests/unittests/flows/llm_flows/test_other_configs.py: the request carries the session id, and a sub-agent reached by transfer gets the same one.
  • tests/unittests/models/test_fallback_model.py: the new field is added to the list of fields FallbackModel leaves as is (models only read it).

Manual End-to-End (E2E) Tests:

Re-run with this branch against a real LiteLLM Proxy (v1.105.1, Postgres spend logs), no plugin or callback:
an agent with a tool, a sub-agent reached by transfer with its own tool, and an AgentTool child; three user turns.

Scenario Calls Distinct session_id
litellm_proxy/<model> 9 2: 8 calls on the ADK session id, 1 on the AgentTool child's own session
openai/<model> with api_base = the proxy 9 9 (not treated as proxied: nothing sent, as designed)
caller sets x-litellm-session-id in extra_headers 8 1 (the caller's value)

Without this branch the same litellm_proxy/ conversation gives one session_id per call (#8186).

Also checked: the new tests fail on main's sources (7 failures) and pass on this branch;
pytest tests/unittests/{models,flows,agents,runners,plugins,tools} -n auto: 10064 passed, 2 skipped, 4 xfailed.

Known limits, for reviewers:

  • An AgentTool child runs in its own in-memory session, so its calls carry that session's id, not the parent's.
  • A proxy reached as openai/<model> + api_base is not detected; use the litellm_proxy/ prefix.
  • Model calls made outside the LLM flow (event compaction summarizer, model_consult, classifiers, eval judges) carry no session id.

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

Two questions for reviewers are in #8186: whether a field on LlmRequest is the channel you want, and whether this should be on by default.

@google-cla

google-cla Bot commented Nov 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

LiteLlm did not tell a LiteLLM proxy which conversation a call belongs
to, so the proxy logged every call of an ADK session under a different
session_id and calls could not be grouped per conversation.

The LLM flow now sets the session id on LlmRequest.session_id, a field
excluded from serialization, and LiteLlm sends it as the
x-litellm-session-id header when the model is served through a LiteLLM
proxy. A session id header set by the caller is kept, and no header is
sent to other providers or when the request has no session id.
@thomaslprr
thomaslprr force-pushed the feat/litellm-propagate-session-id branch from f59536a to 1e4ec4d Compare November 16, 2026 16:45
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.

LiteLlm does not pass the ADK session to a LiteLLM proxy: every call gets its own session_id

2 participants