refactor: Extract duplicate Gemini tool call ID cleanup logic #2438
+25
−13
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.
Summary
This PR extracts duplicate code for cleaning up Gemini tool call IDs into a shared utility function in
ChatCmplHelpers.Problem
Two files had identical logic to remove the
"__thought__"suffix from Gemini tool call IDs:src/agents/models/chatcmpl_stream_handler.py(lines 394-402)src/agents/extensions/models/litellm_model.py(lines 820-827)This duplication made maintenance harder and could lead to inconsistencies if one instance was updated but not the other.
Solution
Added a new classmethod
ChatCmplHelpers.clean_gemini_tool_call_id()that:tool_call_idand optionalmodelparameterChanges
src/agents/models/chatcmpl_helpers.pyclean_gemini_tool_call_id()method (new lines 104-121)src/agents/models/chatcmpl_stream_handler.pysrc/agents/extensions/models/litellm_model.pyChatCmplHelpersimportContext
LiteLLM adds a
"__thought__"suffix to Gemini tool call IDs to track thought signatures. This suffix is removed because:provider_specific_fields)Testing
🤖 Generated with Claude Code