OpenAILlm drops reasoning text returned by vLLM, SGLang and DeepSeek (`reasoning` / `reasoning_content`)
Maintainer thường phản hồi trong vòng 3 ngày
@sanketpatil06 đang làm issue này rồi.
Từ ngày 17/11/2026.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 22.3k
- Fork
- 4.4k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/adk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/adk-python#8360 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
google/adk-python#8359 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Can pin to litellm version be changed?Có thể đã có người làm @llalitkumarrr đã nhận 10 ngày trước. Đang mởmodels
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
google/adk-python#8129 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
OpenAPI tools ignore operation- and path-level server overridesCó thể đã có người làm @sanketpatil06 đã nhận 14 ngày trước. Đang mởtools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
google/adk-python#8064 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Two docstrings in openapi_tool document parameters the signatures do not acceptCó thể đã có người làm @surajksharma07 đã nhận 17 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
google/adk-python#8024 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của google/adk-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vllm-project/vllm#70030 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TigreGotico/tugaphone#408 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
gke-labs/kube-agents#7308 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
chore
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
lugassawan/swe-workbench#841 ·