Skip to content

fix(providers): correct tool calling message format across all providers#3132

Merged
waleedlatif1 merged 4 commits intostagingfrom
fix/provider-tool-calling-compliance
Feb 4, 2026
Merged

fix(providers): correct tool calling message format across all providers#3132
waleedlatif1 merged 4 commits intostagingfrom
fix/provider-tool-calling-compliance

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Feb 4, 2026

Summary

  • Replaced the single isolated-vm execution path with a configurable worker pool (lazy spawn, least-loaded dispatch, idle cleanup).
  • Added per-owner queue + active caps and weighted scheduling so one user can’t hog all worker capacity.
  • Added Redis-backed distributed per-owner in-flight limits for multi-instance fairness, with local-only mode when REDIS_URL is not set and fail-closed behavior when Redis is configured but unavailable.
  • Hardened sandbox fetch by reusing the existing DNS-validated/IP-pinned secure fetch helper, plus caps for URL length, options payload size, response size, and stdout growth.
  • Added env vars + tests for fairness, distributed limits, queue behavior, and fetch guardrails; defaults are high-throughput and tunable (including 8MB response bytes and 4,000,000 response chars).

Type of Change

  • Bug fix

Testing

Tested TypeScript compilation passes + added more tests

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 4, 2026 6:24pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

Corrected tool calling message formats across multiple AI providers to align with their respective API specifications, particularly for handling parallel/multiple tool calls.

Key Changes

  • Anthropic: Refactored to batch all tool_use blocks into a single assistant message and all tool_result blocks into a single user message, preserving original tool IDs from Claude's response instead of generating new ones
  • Gemini: Implemented parallel execution of multiple function calls with proper batching per Gemini documentation (one model message with all function calls, one user message with all responses)
  • Bedrock: Enhanced generateToolUseId to enforce AWS's 64-character limit with base36 timestamp encoding, tool name truncation, and character sanitization
  • DeepSeek: Changed from hardcoded model name to dynamic request.model parameter
  • Mistral & Groq: Added required name field to tool result messages
  • MCP Types: Strengthened type safety with McpToolSchemaProperty interface for proper JSON Schema typing

The changes follow each provider's API requirements for tool calling and improve correctness when handling multiple parallel tool invocations.

Confidence Score: 5/5

  • This PR is safe to merge with no critical issues found
  • All changes are focused bug fixes that align code with official provider API specifications, improve type safety, and correctly handle parallel tool calls - no logic errors or breaking changes detected
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/providers/anthropic/index.ts Batched tool_use/tool_result blocks into single messages and preserved original IDs from Claude
apps/sim/providers/gemini/core.ts Implemented parallel execution of multiple function calls with batched message format
apps/sim/providers/google/utils.ts Added extractAllFunctionCallParts for multi-tool handling, deprecated single-call function
apps/sim/providers/bedrock/utils.ts Enhanced generateToolUseId to enforce AWS 64-character limit with truncation and sanitization

Sequence Diagram

sequenceDiagram
    participant Client
    participant Provider
    participant AI_API as AI API (Anthropic/Gemini/etc)
    participant ToolExecutor

    Client->>Provider: Send request with tools
    Provider->>AI_API: Generate content
    AI_API-->>Provider: Response with tool_use blocks
    
    alt Multiple parallel tool calls
        Note over Provider,ToolExecutor: NEW: Batch processing
        loop For each tool_use
            Provider->>ToolExecutor: Execute tool (parallel)
        end
        ToolExecutor-->>Provider: All results
        
        Note over Provider: NEW: Single assistant message
        Provider->>Provider: Batch all tool_use blocks
        Note over Provider: NEW: Single user message
        Provider->>Provider: Batch all tool_result blocks
        
        Provider->>AI_API: Continue with batched messages
    else Single tool call (legacy)
        Provider->>ToolExecutor: Execute tool
        ToolExecutor-->>Provider: Result
        Provider->>AI_API: Continue with result
    end
    
    AI_API-->>Provider: Final response
    Provider-->>Client: Complete response
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Additional Comments (1)

apps/sim/providers/gemini/core.ts
Dead code - executeToolCall function is no longer called after introducing executeToolCallsBatch. Consider removing this function to reduce maintenance burden.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/providers/gemini/core.ts
Line: 84:177

Comment:
Dead code - `executeToolCall` function is no longer called after introducing `executeToolCallsBatch`. Consider removing this function to reduce maintenance burden.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

waleedlatif1 commented Feb 4, 2026

@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@waleedlatif1 waleedlatif1 merged commit c77e351 into staging Feb 4, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/provider-tool-calling-compliance branch February 4, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant