Skip to content

Conversation

@hobostay
Copy link
Contributor

@hobostay hobostay commented Feb 8, 2026

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:

  • Takes a tool_call_id and optional model parameter
  • Returns the cleaned tool call ID
  • Includes comprehensive documentation

Changes

src/agents/models/chatcmpl_helpers.py

  • Added clean_gemini_tool_call_id() method (new lines 104-121)
  • Well-documented with docstring explaining the logic
  • Follows existing code patterns in the class

src/agents/models/chatcmpl_stream_handler.py

  • Replaced 7 lines of inline logic with single helper call
  • Maintains identical behavior

src/agents/extensions/models/litellm_model.py

  • Added ChatCmplHelpers import
  • Replaced 7 lines of inline logic with single helper call
  • Maintains identical behavior

Context

LiteLLM adds a "__thought__" suffix to Gemini tool call IDs to track thought signatures. This suffix is removed because:

  1. It's redundant (thought_signature is available in provider_specific_fields)
  2. It causes validation errors when cross-model passing
  3. Reference: litellm#16895

Testing

  • ✅ Same behavior as before (logic extracted, not changed)
  • ✅ Code is now DRY (Don't Repeat Yourself)
  • ✅ Easier to maintain and modify in one place
  • ✅ Well-documented with comprehensive docstring

🤖 Generated with Claude Code

This commit 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
- src/agents/extensions/models/litellm_model.py

This duplication made maintenance harder and could lead to inconsistencies.

## Solution

Added a new classmethod `ChatCmplHelpers.clean_gemini_tool_call_id()` that:
- Takes a tool_call_id and optional model parameter
- Returns the cleaned tool call ID
- Includes comprehensive documentation

## Changes

1. **chatcmpl_helpers.py**: Added `clean_gemini_tool_call_id()` method
   - Well-documented with docstring
   - Follows existing code patterns
   - Returns cleaned tool call ID

2. **chatcmpl_stream_handler.py**: Replaced inline logic with helper call
   - Reduced from 7 lines to 2 lines
   - Maintains same behavior

3. **litellm_model.py**: Replaced inline logic with helper call
   - Added ChatCmplHelpers import
   - Reduced from 7 lines to 2 lines
   - Maintains same behavior

## Context

LiteLLM adds a "__thought__" suffix to Gemini tool call IDs to track
thought signatures. This suffix is removed because:
- It's redundant (thought_signature is in provider_specific_fields)
- It causes validation errors when cross-model passing
- Reference: BerriAI/litellm#16895

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
hobostay and others added 2 commits February 8, 2026 17:26
- Shortened first line of docstring to stay under 100 characters
- Split long explanation into multiple lines
Ruff's isort check (I001) requires imports to be sorted alphabetically.
The import statement was updated to:
  HEADERS, HEADERS_OVERRIDE, ChatCmplHelpers

This ensures the import block is properly sorted and passes lint checks.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@seratch seratch added this to the 0.8.x milestone Feb 9, 2026
@seratch seratch merged commit 195b53d into openai:main Feb 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants