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

未關閉
#8,186 1 則留言 2 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 3 天內回覆

@sanketpatil06 已經在處理了。

開始於 2026年11月17日。

  • #8187 來自 @thomaslprr —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
backend

研究方向

The issue describes passing invocation_context.session.id through LlmRequest to LiteLlm and includes a linked pull request, #8187. Read that pull request and the LLM flow where adk_agent_name is added to understand the proposed change; the request’s open questions and existing PR mean this work is already underway. Done means the proxy receives the ADK session ID while caller-provided headers are preserved.

由索引模型根據 Issue 內容生成。

描述

models needs review

🔴 Required Information

Is your feature request related to a specific problem?

LiteLlm does not tell LiteLLM which conversation a call belongs to. Behind a LiteLLM Proxy, the proxy therefore gives every call its own session_id in LiteLLM_SpendLogs, and the calls of one ADK session cannot be grouped (cost per conversation, evaluation, traces).

Measured with a root agent that has one tool and a sub-agent reached through transfer_to_agent, run for 3 turns in a single ADK session with LiteLlm("litellm_proxy/<model>") (LiteLLM 1.105.1, ADK 2.5.0):

calls distinct session_id in LiteLLM_SpendLogs
today 6 6
with the header x-litellm-session-id: <session.id> 6 1, equal to the ADK session id, sub-agent included
Describe the Solution You'd Like

When the model is served through a LiteLLM Proxy, LiteLlm sends the ADK session id in the x-litellm-session-id header, which is the header the proxy reads to set the session of a call.

  • No header when the request has no session id (calls made outside a Runner), and no header to providers other than the proxy.
  • A session id header already set by the caller (extra_headers at construction, or http_options.headers) is kept.
Impact on your work

Without it, per-conversation cost and quality analysis on the proxy side needs a callback copied into every agent. Not blocking, there is a workaround (below).

Willingness to contribute

Yes. A PR with tests is ready and linked below.


🟡 Recommended Information

Describe Alternatives You've Considered
  • Workaround today: a before_model_callback (or a plugin) that sets llm_request.config.http_options.headers["x-litellm-session-id"] from the session. It works, but every app has to know the header and re-implement it.
  • A label in config.labels (like adk_agent_name): the Gemini model sends labels to Vertex, so this would add a very high-cardinality billing label.
Proposed API / Implementation

The model does not see the session today, so the id needs a way to reach it:

class LlmRequest(BaseModel):
  session_id: str | None = Field(default=None, exclude=True)
  • The LLM flow sets it from invocation_context.session.id, next to where it adds the adk_agent_name label, unless it is already set.
  • exclude=True keeps it out of model_dump(), so recorded or traced requests do not change.
  • LiteLlm reads it and adds the header for proxied models.

Open questions:

  1. Is a field on LlmRequest the channel you would want for this?
  2. Should it be on by default (as in the PR), or opt-in?
Additional Context

ADK already adds adk_agent_name to every request so that billing can be sliced per agent. This is the same idea, per session.

主要語言
Python
星號
22.3k
分支
4.4k
平均合併
1 天 2 小時
30 天內合併 PR
6

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

google/adk-python 的其他 Issue

查看 google/adk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。