Skip to content

Conversation

@TNAJanssen
Copy link

Problem

When using Gemini 2.5 models (e.g., gemini-2.5-flash), the API can return multi-part responses that include
"thinking" content alongside the actual response. This is similar to Claude's extended thinking feature.

Example response structure:

  • Part 0: Analysis/thinking text with thoughtSignature field
  • Part 1: Actual response content

The current ResultConverter::convertChoice() method doesn't handle this case. It only processes:

  1. Function calls
  2. Single text parts
  3. Code execution results

When multiple text parts exist without code execution, the method throws RuntimeException('Code execution failed.') which is incorrect and confusing.

Solution

Added fallback logic to concatenate all text parts when no code execution results are present. This allows
multi-part thinking responses to be processed correctly as TextResult.

Changes

  • Modified convertChoice() to concatenate text from all parts when code execution is not detected
  • Updated error message to be more accurate ("no text content" instead of "code execution failed")
  • Added test coverage for multi-part thinking responses

Testing

Tested with gemini-2.5-flash model returning thinking + JSON response structure.

When Gemini 2.5 models return multi-part responses containing thinking
content (with thoughtSignature) alongside the actual response, the
converter now correctly concatenates all text parts instead of throwing
an incorrect "Code execution failed" error.
@carsonbot carsonbot added Platform Issues & PRs about the AI Platform component Status: Needs Review labels Dec 4, 2025
@OskarStark
Copy link
Contributor

Can you please add an example in the examples folder? Thanks

@OskarStark OskarStark changed the title [Platform] Fix ResultConverter to handle Gemini 2.5 multi-part thinking responses [Platform][Gemini] Fix ResultConverter to handle Gemini 2.5 multi-part thinking responses Dec 4, 2025
@OskarStark OskarStark changed the title [Platform][Gemini] Fix ResultConverter to handle Gemini 2.5 multi-part thinking responses [Platform][Gemini] Fix ResultConverter to handle gemini-2.5-flash multi-part thinking responses Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants