OpenAILlm drops reasoning text returned by vLLM, SGLang and DeepSeek (`reasoning` / `reasoning_content`)
维护者通常 3 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start with src/google/adk/integrations/openai/_openai_llm.py, especially _response_to_llm_response and _generate_content_streaming, then compare reasoning conversion in src/google/adk/models/lite_llm.py and src/google/adk/integrations/openai/_openai_responses_llm.py. The issue describes expected thought parts and mentions local unit tests using vLLM, SGLang, and DeepSeek response shapes. Done means reasoning appears before the answer in non-streaming and streaming responses without duplicating it when both fields are present.
由索引模型根据 Issue 内容生成。
描述
Required Information
Describe the Bug:
OpenAILlm (the Chat Completions adapter in
src/google/adk/integrations/openai/_openai_llm.py) drops the reasoning text
that OpenAI-compatible servers return. Reasoning models served by these servers
put it in an extra field on the assistant message and on each stream delta:
- vLLM:
reasoning(ChatMessage.reasoningandDeltaMessage.reasoningon
vLLM main; older vLLM releases usedreasoning_content). - SGLang:
reasoning_content(ChatMessageandDeltaMessagein
python/sglang/srt/entrypoints/openai/protocol.py). - DeepSeek API (
deepseek-reasonerand thinking mode):reasoning_content.
The OpenAI SDK keeps these fields on the parsed object as extra attributes, but
OpenAILlm never reads them:
- Non-streaming:
_response_to_llm_responsebuilds parts only from
message.contentandmessage.tool_calls
(_openai_llm.py:323-326). - Streaming:
_generate_content_streamingreads onlydelta.contentand
delta.tool_calls(_openai_llm.py:548-558), and the final response holds
only the accumulated text and tool calls (_openai_llm.py:603-605).
So the reasoning does not reach adk web, callbacks, session events, or
telemetry, even though thoughts_token_count is already filled from
completion_tokens_details.reasoning_tokens (_openai_llm.py:256-281).
LiteLlm already handles both field names: _extract_reasoning_value
(src/google/adk/models/lite_llm.py:1003-1022) checks reasoning_content
first and falls back to reasoning, and _convert_reasoning_value_to_parts
(lite_llm.py:925-965) turns the text into Part(thought=True). The
Responses adapter (_openai_responses_llm.py:590-623) also maps reasoning
items to thought parts. Only the Chat Completions adapter is missing it.
Steps to Reproduce:
-
Install ADK from main and
openai. -
Run the script under "Minimal Reproduction Code" below. It mocks
chat.completions.createwith the response shape vLLM returns, so no server
is needed. -
Or start a real server and point
OpenAILlmat it:vllm serve Qwen/Qwen3-8B --reasoning-parser qwen3 # or python -m sglang.launch_server --model-path Qwen/Qwen3-8B --reasoning-parser qwen3with
OpenAILlm(model="Qwen/Qwen3-8B", base_url="http://localhost:8000/v1", api_key="x").
The raw HTTP response contains the reasoning field; theLlmResponsedoes
not.
Expected Behavior:
The reasoning text is kept as a types.Part(text=..., thought=True) before the
answer, the same way LiteLlm and OpenAIResponsesLlm do it. If a server
sends both fields with the same text, it appears once.
Observed Behavior:
The LlmResponse contains only the answer text. The reasoning is dropped
without a warning.
thought=None text='The answer is 4.'
Against a real server (vLLM 0.34.0rc1, vllm serve Qwen/Qwen3-0.6B --reasoning-parser qwen3, one RTX 5090), prompt "What is 17*23?": the raw message has content and reasoning, while OpenAILlm on main returns a single answer part, and in streaming mode yields 0 thought chunks. With the PR1 change below it returns a thought part followed by the answer part, and the stream yields 820 partial thought chunks.
Environment Details:
- ADK Library Version: main at c6586f19 (
__version__2.14.1) - Desktop OS: Linux
- Python Version: 3.12
Model Information:
- Are you using LiteLLM: No (
OpenAILlm) - Which model is being used: Qwen/Qwen3-8B on vLLM or SGLang with
--reasoning-parser qwen3;deepseek-reasoneron the DeepSeek API
Optional Information
Regression: No. OpenAILlm has never read these fields.
Minimal Reproduction Code:
import asyncio
from unittest import mock
from google.adk.integrations.openai import OpenAILlm
from google.adk.models.llm_request import LlmRequest
from google.genai import types
from openai import AsyncOpenAI
from openai.types.chat import ChatCompletion
VLLM_RESPONSE = {
"id": "chatcmpl-1",
"object": "chat.completion",
"created": 0,
"model": "Qwen/Qwen3-8B",
"choices": [{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "The answer is 4.",
"reasoning": "2 + 2 is 4.",
},
}],
"usage": {"prompt_tokens": 12, "completion_tokens": 30, "total_tokens": 42},
}
async def main():
client = AsyncOpenAI(api_key="unused", base_url="http://localhost:8000/v1")
client.chat.completions.create = mock.AsyncMock(
return_value=ChatCompletion.model_validate(VLLM_RESPONSE)
)
llm = OpenAILlm(model="Qwen/Qwen3-8B", client=client)
request = LlmRequest(
model="Qwen/Qwen3-8B",
contents=[
types.Content(role="user", parts=[types.Part.from_text(text="2+2?")])
],
)
async for response in llm.generate_content_async(request):
for part in response.content.parts:
print(f"thought={part.thought!r} text={part.text!r}")
asyncio.run(main())
How often has this issue occurred?: Always (100%), for every response that
carries reasoning or reasoning_content.
Additional Context:
Proposed fix, split into small PRs with one concern each. PR1 and PR2 depend on
each other, so I would like a maintainer view on PR2 before opening PR1.
-
PR1: parse reasoning. Map
reasoning_content/reasoningto a thought
part in the non-streaming path, and to partial thought deltas plus one
merged thought part in the streaming path. Keep the current behaviour that a
response with no answer and an abnormal finish reason (for example the token
budget runs out during reasoning) is reported as aMAX_TOKENSerror. I have
this ready locally with unit tests built from vLLM, SGLang and DeepSeek
response shapes. -
PR2: how thoughts are sent back (design question). Today
_part_to_openai_contentturns a thought part into assistant text
"Thought: <text>"(_openai_llm.py:89-90). This path is rarely hit now,
because this adapter never produces thought parts. With PR1 alone, every
later turn with a reasoning model would send the earlier reasoning back as
visible assistant text, for example
{"role": "assistant", "content": "Thought: 2 + 2 is 4.\nThe answer is 4."}.
_is_part_invisible(src/google/adk/flows/llm_flows/context/_contents.py:205)
hides thought parts, but an event that also has an answer or a function
call is kept, and its thought part is converted along with the rest. Two
problems follow: chat templates such as Qwen3's strip earlier reasoning from
history, so the model did not see it during training; and the prompt grows
by the full reasoning on each turn. Options:- drop thought parts on replay (what
OpenAIResponsesLlmdoes today, see
_skip_replayed_reasoning_part,_openai_responses_llm.py:296-314); - send them back as
reasoning_contenton the assistant message (what
LiteLlmdoes). Some servers need this inside a tool-call loop, while
others reject or ignore the field; - keep the
"Thought:"text.
Which one do maintainers prefer? I plan to open PR1 and PR2 together, or
PR2 first, so that no release has PR1 without it. - drop thought parts on replay (what
-
PR3:
extra_body.OpenAILlmbuilds the request kwargs at
_openai_llm.py:465-472and has no way to passextra_body. Compatible
servers use it for options such as vLLM/SGLang
chat_template_kwargs={"enable_thinking": False}.LiteLlmforwards
http_options.extra_body(lite_llm.py:4822-4823), and
OpenAIResponsesLlmmergesextra_bodyfromextra_request_args
(_openai_responses_llm.py:1206-1226). -
PR4: malformed or truncated tool-call arguments. When the arguments
string is not valid JSON, both paths log a warning and run the tool with
args={}(_openai_llm.py:291-296and_openai_llm.py:609-616). A
truncated stream (finish_reason="length"in the middle of the arguments)
hits the same path. Other adapters now report this instead of calling the
tool: #7803 (LiteLlm,MALFORMED_FUNCTION_CALL), #7686 (Apigee, truncated
calls asMAX_TOKENS), #7558 (Claude, calls cut off bymax_tokens). I
propose the same forOpenAILlm. This one is independent of the others, and
I have it ready locally with unit tests (truncated and non-object arguments,
streaming and non-streaming).
Workaround: use LiteLlm instead. OpenAILlm is the native adapter documented
for OpenAI-compatible endpoints in
src/google/adk/integrations/openai/README.md, so it should not lose data that
the server returns.
I checked open PRs that touch the same file (#8006, #8086, #8112); none of
them change response parsing.
I am willing to contribute all four PRs.
- 主要语言
- Python
- 星标
- 22.3k
- 派生
- 4.4k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/adk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
google/adk-python#8360 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
google/adk-python#8359 ·
维护者通常 3 天内回复
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 于 10 天前认领。 未关闭models
难度 1/5 1 小时以内 新手友好度 65/100
google/adk-python#8129 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 于 14 天前认领。 未关闭tools
难度 2/5 1-3 小时 新手友好度 75/100
google/adk-python#8064 · 4 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 于 17 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
google/adk-python#8024 · 1 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
查看 google/adk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
vllm-project/vllm#70030 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
TigreGotico/tugaphone#408 ·
维护者通常 1 天内回复
-
t: bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
needs-triage
难度 1/5 1 小时以内 新手友好度 85/100
Azure/azure-sdk-for-python#50155 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复