fix: capture thought output from Gemini thinking models (#4647)#4648
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
fix: capture thought output from Gemini thinking models (#4647)#4648devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- Add thinking_config parameter to GeminiCompletion.__init__ (accepts dict or ThinkingConfig) - Include thinking_config in _prepare_generation_config when set - Rewrite _process_stream_chunk to iterate over parts directly instead of using chunk.text, avoiding warnings when non-text parts (thought, function_call) are present - Convert _extract_text_from_response from staticmethod to instance method; separate thought parts from text parts and store thoughts in self.previous_thoughts - Add 11 tests covering thinking config initialization, generation config integration, thought part extraction in streaming and non-streaming paths Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: capture thought output from Gemini thinking models (#4647)
Summary
Gemini thinking models (e.g.
gemini-2.5-pro,gemini-2.5-flash) produce "thought" parts alongside text parts in their responses. Previously, these thought parts were silently discarded, and usingchunk.texton streaming responses containing non-text parts triggered SDK warnings.This PR:
thinking_configparameter toGeminiCompletion(acceptsThinkingConfigor dict), passed through to the generation config_process_stream_chunkto iterate over candidate parts directly instead of callingchunk.text, which avoids SDK warnings when non-text parts are present_extract_text_from_responsefrom a@staticmethodto an instance method so it can store thought contentself.previous_thoughts(both streaming and non-streaming paths)Review & Testing Checklist for Human
_process_stream_chunkrewrite doesn't break non-thinking streaming. This is the highest-risk change — the old code usedchunk.textthen separately looped over parts for function calls. The new code uses a single loop over parts for everything. Test with regular (non-thinking) models with streaming enabled, especially with tool calling.not part.function_callin the streaming loop (line ~980). Is it possible for a real SDKPartto have both.textand.function_callset? If so, this guard is correct; if not, it's harmless but worth confirming.previous_thoughtsis actually accessible downstream. Thoughts are captured inself.previous_thoughtsbut there is no consumer shown in this diff that surfaces them via the LLM event system or return values. Verify this is sufficient for the issue reporter's use case, or whether an additional integration point is needed._extract_text_from_responseuse it as a static/class method. It was changed from@staticmethodto an instance method — anyGeminiCompletion._extract_text_from_response(response)calls would break.previous_thoughtsaccumulates indefinitely — it is never cleared betweencall()invocations. Confirm this is acceptable behavior for multi-turn conversations or whether it should be reset per-call.Notes
test_gemini_raises_error_when_model_not_supported) is unrelated to these changesPartobjects rather than real SDK responsesRequested by: João
Link to Devin run: https://app.devin.ai/sessions/5d1a2a24e1e84fb7b3056281f054fc5c