Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Fix Anthropic tool calling to batch all tool_use/tool_result blocks into single messages and preserve original IDs
  • Fix Gemini to handle multiple parallel function calls in a single response
  • Fix DeepSeek to use dynamic model and correct max_tokens parameter
  • Fix Bedrock toolUseId to stay within 64-char AWS limit
  • Add name field to tool result messages for Mistral and Groq
  • Strengthen MCP types with proper McpToolSchemaProperty interface

Type of Change

  • Bug fix

Testing

Tested TypeScript compilation passes

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 9:28am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

This PR corrects tool calling message formats across multiple LLM providers to align with their respective API specifications. The key changes ensure proper batching of parallel tool calls and preservation of tool IDs.

Major Changes:

  • Anthropic: Now batches all tool_use blocks into a single assistant message and all tool_result blocks into a single user message, preserving original IDs from Claude's response instead of generating new ones
  • Gemini: Refactored to handle multiple parallel function calls per API specification, executing all calls together with proper batched message formatting
  • DeepSeek: Fixed to use dynamic request.model instead of hardcoded model name
  • Bedrock: Enhanced generateToolUseId to enforce AWS's 64-character limit with proper name truncation and sanitization
  • Mistral/Groq: Added missing name field to tool result messages
  • MCP Types: Strengthened type safety with proper McpToolSchemaProperty interface

Architecture Impact:
The batching changes fundamentally alter how tool execution results are communicated back to the LLM, moving from individual message pairs per tool call to consolidated messages containing all tool interactions. This aligns with provider specifications and should improve context efficiency.

Confidence Score: 4/5

  • This PR is generally safe to merge with minor verification needed for the refactored tool batching logic
  • The changes align with provider API specifications and improve correctness. However, the significant refactoring in Anthropic and Gemini providers for tool batching should be tested thoroughly to ensure parallel tool execution and message formatting work correctly in production scenarios
  • Pay close attention to apps/sim/providers/anthropic/index.ts and apps/sim/providers/gemini/core.ts - the tool batching refactor changes core execution flow

Important Files Changed

Filename Overview
apps/sim/providers/bedrock/utils.ts Improved generateToolUseId to enforce AWS 64-char limit with proper truncation and sanitization
apps/sim/providers/gemini/core.ts Refactored to batch multiple parallel function calls per Gemini docs, executing all calls together with proper message formatting
apps/sim/providers/anthropic/index.ts Fixed to batch all tool_use/tool_result blocks into single messages and preserve original tool_use IDs from Claude's response

Sequence Diagram

sequenceDiagram
    participant User
    participant Provider as Provider (Anthropic/Gemini/etc)
    participant LLM as LLM API
    participant Tools as Tool Executor
    
    User->>Provider: Send request with tools
    Provider->>LLM: API call with tool definitions
    
    alt Multiple Tool Calls (Parallel)
        LLM->>Provider: Response with multiple tool_use blocks
        Note over Provider: Collect all tool_use blocks
        
        par Execute tools in parallel
            Provider->>Tools: Execute tool 1
            Provider->>Tools: Execute tool 2
            Provider->>Tools: Execute tool N
        end
        
        Tools-->>Provider: Results for all tools
        
        Note over Provider: Batch into single messages:<br/>ONE assistant msg with ALL tool_use<br/>ONE user msg with ALL tool_result
        
        Provider->>LLM: Continue with batched messages
        LLM->>Provider: Final response
    end
    
    Provider->>User: Return final 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

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.

endTime: new Date(toolCallEndTime).toISOString(),
duration,
result: resultContent,
const batchStartTime = Date.now()
Copy link

Choose a reason for hiding this comment

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

Unused variable batchStartTime in executeToolCallsBatch

Low Severity

batchStartTime is assigned at line 98 but never used. This is dead code that should be removed.

Fix in Cursor Fix in Web

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.

2 participants