Mirrowel commited on
Commit
09eea32
·
1 Parent(s): 818ba14

feat(antigravity): ✨ add parallel tool usage instruction injection for claude and gemini 3

Browse files

Adds configurable instruction injection to encourage parallel tool usage for models that support it. Parallel tool calls reduce round-trips and improve efficiency when multiple independent operations are needed.

- Separate environment variable toggles for Claude (default: enabled) and Gemini 3 (default: disabled)
- Allows model-specific optimization based on capability and behavior

src/rotator_library/providers/antigravity_provider.py CHANGED
@@ -230,6 +230,9 @@ You MUST follow these rules strictly:
230
  If you are unsure about a tool's parameters, YOU MUST read the schema definition carefully.
231
  """
232
 
 
 
 
233
 
234
  # =============================================================================
235
  # HELPER FUNCTIONS
@@ -900,6 +903,19 @@ class AntigravityProvider(
900
  "ANTIGRAVITY_CLAUDE_SYSTEM_INSTRUCTION", DEFAULT_CLAUDE_SYSTEM_INSTRUCTION
901
  )
902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
  # Log configuration
904
  self._log_config()
905
 
@@ -909,7 +925,9 @@ class AntigravityProvider(
909
  f"Antigravity config: signatures_in_client={self._preserve_signatures_in_client}, "
910
  f"cache={self._enable_signature_cache}, dynamic_models={self._enable_dynamic_models}, "
911
  f"gemini3_fix={self._enable_gemini3_tool_fix}, gemini3_strict_schema={self._gemini3_enforce_strict_schema}, "
912
- f"claude_fix={self._enable_claude_tool_fix}, thinking_sanitization={self._enable_thinking_sanitization}"
 
 
913
  )
914
 
915
  def _load_tier_from_file(self, credential_path: str) -> Optional[str]:
@@ -3289,6 +3307,19 @@ class AntigravityProvider(
3289
  gemini_payload, self._claude_system_instruction
3290
  )
3291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3292
  # Add generation config
3293
  gen_config = {}
3294
  if top_p is not None:
 
230
  If you are unsure about a tool's parameters, YOU MUST read the schema definition carefully.
231
  """
232
 
233
+ # Parallel tool usage encouragement instruction
234
+ DEFAULT_PARALLEL_TOOL_INSTRUCTION = """When multiple independent operations are needed, prefer making parallel tool calls in a single response rather than sequential calls across multiple responses. This reduces round-trips and improves efficiency. Only use sequential calls when one tool's output is required as input for another."""
235
+
236
 
237
  # =============================================================================
238
  # HELPER FUNCTIONS
 
903
  "ANTIGRAVITY_CLAUDE_SYSTEM_INSTRUCTION", DEFAULT_CLAUDE_SYSTEM_INSTRUCTION
904
  )
905
 
906
+ # Parallel tool usage instruction configuration
907
+ self._enable_parallel_tool_instruction_claude = _env_bool(
908
+ "ANTIGRAVITY_PARALLEL_TOOL_INSTRUCTION_CLAUDE",
909
+ True, # ON for Claude
910
+ )
911
+ self._enable_parallel_tool_instruction_gemini3 = _env_bool(
912
+ "ANTIGRAVITY_PARALLEL_TOOL_INSTRUCTION_GEMINI3",
913
+ False, # OFF for Gemini 3
914
+ )
915
+ self._parallel_tool_instruction = os.getenv(
916
+ "ANTIGRAVITY_PARALLEL_TOOL_INSTRUCTION", DEFAULT_PARALLEL_TOOL_INSTRUCTION
917
+ )
918
+
919
  # Log configuration
920
  self._log_config()
921
 
 
925
  f"Antigravity config: signatures_in_client={self._preserve_signatures_in_client}, "
926
  f"cache={self._enable_signature_cache}, dynamic_models={self._enable_dynamic_models}, "
927
  f"gemini3_fix={self._enable_gemini3_tool_fix}, gemini3_strict_schema={self._gemini3_enforce_strict_schema}, "
928
+ f"claude_fix={self._enable_claude_tool_fix}, thinking_sanitization={self._enable_thinking_sanitization}, "
929
+ f"parallel_tool_claude={self._enable_parallel_tool_instruction_claude}, "
930
+ f"parallel_tool_gemini3={self._enable_parallel_tool_instruction_gemini3}"
931
  )
932
 
933
  def _load_tier_from_file(self, credential_path: str) -> Optional[str]:
 
3307
  gemini_payload, self._claude_system_instruction
3308
  )
3309
 
3310
+ # Inject parallel tool usage encouragement (independent of tool hardening)
3311
+ if self._is_claude(model) and self._enable_parallel_tool_instruction_claude:
3312
+ self._inject_tool_hardening_instruction(
3313
+ gemini_payload, self._parallel_tool_instruction
3314
+ )
3315
+ elif (
3316
+ self._is_gemini_3(model)
3317
+ and self._enable_parallel_tool_instruction_gemini3
3318
+ ):
3319
+ self._inject_tool_hardening_instruction(
3320
+ gemini_payload, self._parallel_tool_instruction
3321
+ )
3322
+
3323
  # Add generation config
3324
  gen_config = {}
3325
  if top_p is not None: