Spaces:
Paused
docs: π update documentation for enhanced claude thinking sanitization and remove obsolete todo file
Browse filesThis commit comprehensively updates documentation to reflect the improved Claude extended thinking sanitization system and removes the completed todo.md file.
- Enhanced DOCUMENTATION.md with detailed explanations of the robust thinking sanitization system, including:
- Clarification that Claude Opus 4.5 always uses the thinking variant (non-thinking version doesn't exist)
- Complete sanitization scenario table with new edge cases (function call ID mismatch, missing tool responses, cached conversations)
- Detailed implementation notes on Gemini-format message processing and turn state analysis
- Three-tier function call response pairing strategy (ID match β name match β fallback)
- Recovery mechanisms for cache post-transformation
- Increased default max output tokens to 64000 for thinking output
- Updated README.md to mention improved function call response pairing with three-tier matching strategy
- Removed todo.md as tasks have been completed (thinking sanitization refinements and function call pairing improvements are now implemented)
- DOCUMENTATION.md +30 -25
- README.md +2 -1
- src/rotator_library/pyproject.toml +1 -1
- todo.md +0 -7
|
@@ -420,10 +420,11 @@ The most sophisticated provider implementation, supporting Google's internal Ant
|
|
| 420 |
|
| 421 |
**Claude Opus 4.5 (NEW!):**
|
| 422 |
- Anthropic's most powerful model, now available via Antigravity proxy
|
| 423 |
-
-
|
| 424 |
-
- Uses `thinkingBudget` parameter for extended thinking control
|
| 425 |
- Full support for tool use with schema cleaning
|
| 426 |
- Same thinking preservation and sanitization features as Sonnet
|
|
|
|
| 427 |
|
| 428 |
**Claude Sonnet 4.5:**
|
| 429 |
- Proxied through Antigravity API (uses internal model name `claude-sonnet-4-5-thinking`)
|
|
@@ -475,7 +476,7 @@ ANTIGRAVITY_GEMINI3_SYSTEM_INSTRUCTION="..." # Full system prompt
|
|
| 475 |
|
| 476 |
#### Claude Extended Thinking Sanitization
|
| 477 |
|
| 478 |
-
The provider includes automatic sanitization for Claude's extended thinking mode, handling common error scenarios
|
| 479 |
|
| 480 |
**Problem**: Claude's extended thinking API requires strict consistency in thinking blocks:
|
| 481 |
- If thinking is enabled, the final assistant turn must start with a thinking block
|
|
@@ -491,38 +492,42 @@ The provider includes automatic sanitization for Claude's extended thinking mode
|
|
| 491 |
| Tool loop WITHOUT thinking + thinking enabled | **Inject synthetic closure** to start fresh turn with thinking |
|
| 492 |
| Thinking disabled | Strip all thinking blocks |
|
| 493 |
| Normal conversation (no tool loop) | Strip old thinking, new response adds thinking naturally |
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
-
**
|
| 496 |
-
- Analyzes conversation state to detect incomplete tool use loops
|
| 497 |
-
- When enabling thinking in a tool loop that started without thinking:
|
| 498 |
-
- Injects a minimal synthetic assistant message: `"[Tool execution completed. Processing results.]"`
|
| 499 |
-
- This **closes** the previous turn, allowing Claude to start a **fresh turn with thinking**
|
| 500 |
-
- Strips thinking from old turns (Claude API ignores them anyway)
|
| 501 |
-
- Preserves thinking when the turn was started with thinking enabled
|
| 502 |
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
|
| 505 |
-
**
|
|
|
|
|
|
|
| 506 |
```
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
User: [tool_result: "20C sunny"]
|
| 516 |
-
Assistant: "[Tool execution completed. Processing results.]" β INJECTED
|
| 517 |
-
|
| 518 |
-
β Claude now starts a NEW turn and CAN think!
|
| 519 |
```
|
| 520 |
|
| 521 |
**Configuration**:
|
| 522 |
```env
|
| 523 |
-
ANTIGRAVITY_CLAUDE_THINKING_SANITIZATION=true # Enable/disable auto-correction
|
| 524 |
```
|
| 525 |
|
|
|
|
|
|
|
| 526 |
#### File Logging
|
| 527 |
|
| 528 |
Optional transaction logging for debugging:
|
|
|
|
| 420 |
|
| 421 |
**Claude Opus 4.5 (NEW!):**
|
| 422 |
- Anthropic's most powerful model, now available via Antigravity proxy
|
| 423 |
+
- **Always uses thinking variant** - `claude-opus-4-5-thinking` is the only available variant (non-thinking version doesn't exist)
|
| 424 |
+
- Uses `thinkingBudget` parameter for extended thinking control (-1 for auto, 0 to disable, or specific token count)
|
| 425 |
- Full support for tool use with schema cleaning
|
| 426 |
- Same thinking preservation and sanitization features as Sonnet
|
| 427 |
+
- Increased default max output tokens to 64000 to accommodate thinking output
|
| 428 |
|
| 429 |
**Claude Sonnet 4.5:**
|
| 430 |
- Proxied through Antigravity API (uses internal model name `claude-sonnet-4-5-thinking`)
|
|
|
|
| 476 |
|
| 477 |
#### Claude Extended Thinking Sanitization
|
| 478 |
|
| 479 |
+
The provider now includes robust automatic sanitization for Claude's extended thinking mode, handling all common error scenarios with conversation history.
|
| 480 |
|
| 481 |
**Problem**: Claude's extended thinking API requires strict consistency in thinking blocks:
|
| 482 |
- If thinking is enabled, the final assistant turn must start with a thinking block
|
|
|
|
| 492 |
| Tool loop WITHOUT thinking + thinking enabled | **Inject synthetic closure** to start fresh turn with thinking |
|
| 493 |
| Thinking disabled | Strip all thinking blocks |
|
| 494 |
| Normal conversation (no tool loop) | Strip old thinking, new response adds thinking naturally |
|
| 495 |
+
| Function call ID mismatch | Three-tier recovery: ID match β name match β fallback |
|
| 496 |
+
| Missing tool responses | Automatic placeholder injection |
|
| 497 |
+
| Compacted/cached conversations | Recover thinking from cache post-transformation |
|
| 498 |
|
| 499 |
+
**Key Implementation Details**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
+
The `_sanitize_thinking_for_claude()` method now:
|
| 502 |
+
- Operates on Gemini-format messages (`parts[]` with `"thought": true` markers)
|
| 503 |
+
- Detects tool results as user messages with `functionResponse` parts
|
| 504 |
+
- Uses `_analyze_turn_state()` to classify conversation state on Gemini format
|
| 505 |
+
- Recovers thinking from cache when client strips reasoning_content
|
| 506 |
+
- When enabling thinking in a tool loop started without thinking:
|
| 507 |
+
- Injects synthetic assistant message to close the previous turn
|
| 508 |
+
- Allows Claude to start fresh turn with thinking capability
|
| 509 |
|
| 510 |
+
**Function Call Response Grouping**:
|
| 511 |
+
|
| 512 |
+
The enhanced pairing system ensures conversation history integrity:
|
| 513 |
```
|
| 514 |
+
Problem: Client/proxy may mutate response IDs or lose responses during context processing
|
| 515 |
+
|
| 516 |
+
Solution:
|
| 517 |
+
1. Try direct ID match (tool_call_id == response.id)
|
| 518 |
+
2. If no match, try function name match (tool.name == response.name)
|
| 519 |
+
3. If still no match, use order-based fallback (nth tool β nth response)
|
| 520 |
+
4. Repair "unknown_function" responses with correct names
|
| 521 |
+
5. Create placeholders for completely missing responses
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
```
|
| 523 |
|
| 524 |
**Configuration**:
|
| 525 |
```env
|
| 526 |
+
ANTIGRAVITY_CLAUDE_THINKING_SANITIZATION=true # Enable/disable auto-correction (default: true)
|
| 527 |
```
|
| 528 |
|
| 529 |
+
**Note**: These fixes ensure Claude thinking mode works seamlessly with tool use, model switching, context compression, and cached conversations. No manual intervention required.
|
| 530 |
+
|
| 531 |
#### File Logging
|
| 532 |
|
| 533 |
Optional transaction logging for debugging:
|
|
@@ -33,7 +33,8 @@ This project provides a powerful solution for developers building complex applic
|
|
| 33 |
- Claude Sonnet 4.5 with extended thinking support
|
| 34 |
- Thought signature caching for multi-turn conversations
|
| 35 |
- Tool hallucination prevention via parameter signature injection
|
| 36 |
-
- Automatic thinking block sanitization for Claude models
|
|
|
|
| 37 |
- Note: Claude thinking mode requires careful conversation state management (see [Antigravity documentation](DOCUMENTATION.md#antigravity-claude-extended-thinking-sanitization) for details)
|
| 38 |
- **π Credential Prioritization**: Automatic tier detection and priority-based credential selection ensures paid-tier credentials are used for premium models that require them.
|
| 39 |
- **π Weighted Random Rotation**: Configurable credential rotation strategy - choose between deterministic (perfect balance) or weighted random (unpredictable, harder to fingerprint) selection.
|
|
|
|
| 33 |
- Claude Sonnet 4.5 with extended thinking support
|
| 34 |
- Thought signature caching for multi-turn conversations
|
| 35 |
- Tool hallucination prevention via parameter signature injection
|
| 36 |
+
- Automatic thinking block sanitization for Claude models (with recovery strategies)
|
| 37 |
+
- Improved function call response pairing with three-tier matching strategy
|
| 38 |
- Note: Claude thinking mode requires careful conversation state management (see [Antigravity documentation](DOCUMENTATION.md#antigravity-claude-extended-thinking-sanitization) for details)
|
| 39 |
- **π Credential Prioritization**: Automatic tier detection and priority-based credential selection ensures paid-tier credentials are used for premium models that require them.
|
| 40 |
- **π Weighted Random Rotation**: Configurable credential rotation strategy - choose between deterministic (perfect balance) or weighted random (unpredictable, harder to fingerprint) selection.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
| 4 |
|
| 5 |
[project]
|
| 6 |
name = "rotator_library"
|
| 7 |
-
version = "0
|
| 8 |
authors = [
|
| 9 |
{ name="Mirrowel", email="nuh@uh.com" },
|
| 10 |
]
|
|
|
|
| 4 |
|
| 5 |
[project]
|
| 6 |
name = "rotator_library"
|
| 7 |
+
version = "1.0"
|
| 8 |
authors = [
|
| 9 |
{ name="Mirrowel", email="nuh@uh.com" },
|
| 10 |
]
|
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
~~Refine claude injection to inject even if we have correct thinking - to force it to think if we made ultrathink prompt. If last msg is tool use and you prompt - it never thinks again.~~ Maybe done
|
| 2 |
-
|
| 3 |
-
Anthropic translation and anthropic compatible endpoint.
|
| 4 |
-
|
| 5 |
-
Refine for deployment.
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|