Repository navigation
Conversation
…enAILlm OpenAI-compatible servers return reasoning in an extra field on the message and on each stream delta (`reasoning` on vLLM main, `reasoning_content` on SGLang, DeepSeek and older vLLM). OpenAILlm only read `content` and `tool_calls`, so the reasoning was dropped. Map it to `Part(thought=True)` in both the streaming and non-streaming paths, using the same field order as LiteLlm. A response that runs out of tokens mid-reasoning is still surfaced as a MAX_TOKENS error, as documented on `max_tokens`. Fixes google#8191
|
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. |
Now that reasoning is kept as thought parts, the next request turned them into "Thought: ..." text inside the assistant message, so the model saw its earlier private reasoning as part of its visible answer. Drop thought parts from outgoing assistant messages, as OpenAIResponsesLlm already does. Refs google#8191
|
Reviewed this against my local fix and tests for #8191 — the parsing side looks solid across both non-streaming and streaming paths ( One substantive item to fold in before merge, per @sanketpatil06's comment on #8191 (#8191 (comment)):
Two minor test-coverage suggestions for the parsing side:
(Also a heads-up that the |
…deltas Add the cases raised in review: a message or delta that sets both reasoning_content and reasoning yields a single thought, a message with reasoning and tool_calls keeps both in order, and a stream chunk carrying reasoning and answer text yields a thought partial then a text partial. Refs google#8191
|
Thanks @yibol9768-alt for the review, and @sanketpatil06 for the direction on #8191. Both are addressed: Replay of thought parts (220f022)
Extra parsing coverage (75a40c5)
E2E, two turns in one session (same fake server and Before: After: It's the same with On the CLA: |
Link to Issue or Description of Change
1. Link to an existing issue: #8191
reasoning/reasoning_content) #8191Problem:
OpenAI-compatible servers return a reasoning model's thinking in an extra field on the
assistant message and on each stream delta:
reasoningon vLLM main, andreasoning_contenton SGLang, the DeepSeek API and older vLLM. The OpenAI SDK keepsthese as extra attributes, but
OpenAILlmonly readcontentandtool_calls. So thereasoning never reached
adk web, callbacks, session events or telemetry, even thoughthoughts_token_countwas already filled in.Solution:
_extract_reasoning_text, which readsreasoning_contentand thenreasoning(the same order
LiteLlm._extract_reasoning_valueuses). It accepts only non-emptystrings.
Part(thought=True)before the answer text.aggregated response with the full reasoning as one thought part.
that runs out of tokens mid-reasoning is still a
MAX_TOKENSerror, as themax_tokensdocstring says, and isn't returned as a success with only a thought in it.Testing Plan
Unit Tests:
New tests in
tests/unittests/integrations/openai/test_openai_llm.pyuse realChatCompletion/ChatCompletionChunkobjects instead of mocks, so they also check thatthe SDK exposes the extra field through attribute access:
finish_reason="length"→ still aMAX_TOKENSerror, streaming and non-streamingWithout the source change, the 5 tests that check the new behaviour fail. The other new
tests pass on
maintoo, because they guard behaviour that already exists.Manual End-to-End (E2E) Tests:
Setup: a local fake Chat Completions server answers the way DeepSeek/SGLang
(
reasoning_content) and vLLM (reasoning) do. A realLlmAgentwithOpenAILlm(model="deepseek-reasoner", base_url="http://127.0.0.1:<port>/v1")runsthrough
InMemoryRunner.run_async, withStreamingMode.NONEandStreamingMode.SSE.The script prints every event part and then the parts stored in the session. No API key
is needed. I can attach the script if that helps.
Before (
main): the reasoning is dropped.After (this PR): the reasoning arrives as thought parts and is saved in the session.
Checklist
Additional context
This PR also stops sending earlier reasoning back to the model:
_content_to_openai_messagesdrops thought parts from outgoing assistant messages, matchingOpenAIResponsesLlm, so both changes land together as requested on #8191.No docs change is needed: this restores output users would expect, and no public API changes.