-
Notifications
You must be signed in to change notification settings - Fork 600
fix multi turn tool calling for anthropic when arguments to the tool call is an empty object #1104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix multi turn tool calling for anthropic when arguments to the tool call is an empty object #1104
Conversation
…call is an empty object
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
DescriptionSummary By MatterAI
🔄 What ChangedThis pull request addresses a bug in handling multi-turn tool calls for Anthropic models, specifically when the arguments to a tool call are an empty object. The 🔍 Impact of the ChangeThis change fixes a critical bug that prevented successful multi-turn tool calling with Anthropic when tool arguments were empty, improving the robustness and reliability of the integration. It ensures that tool calls with empty argument objects are correctly processed, preventing parsing errors and allowing the conversation flow to continue as expected. The 📁 Total Files Changed1 file changed. 🧪 Test AddedNo explicit unit or integration tests were mentioned in the PR description. However, it is assumed that manual testing was performed to verify the fix for the specific scenario of empty tool call arguments. 🔒Security VulnerabilitiesNo new security vulnerabilities were detected in the changes. The fix improves robustness by handling a specific input case more gracefully. MotivationThis change is needed to fix a bug where multi-turn tool calling for Anthropic fails when arguments to the tool call is an empty object, as reported in #1103. Type of Change
How Has This Been Tested?
Screenshots (if applicable)N/A Checklist
Related IssuestotalScore: 8 Tip Quality Recommendations
Sequence DiagramsequenceDiagram
participant User as User/Client
participant Gateway as Portkey Gateway
participant AnthropicAPI as Anthropic API
User->>Gateway: Send Chat Completion Request (with tool definitions)
Gateway->>AnthropicAPI: Forward Request (with updated tool definitions including $defs)
AnthropicAPI-->>Gateway: Respond with Assistant Message (potentially with tool_use)
Gateway->>Gateway: Call transformAssistantMessage(msg: Message)
activate Gateway
Gateway->>Gateway: Iterate msg.tool_calls
loop For each toolCall
Gateway->>Gateway: Access toolCall.function.arguments
alt arguments is empty string or null/undefined
Gateway->>Gateway: Set input = {}
else arguments is non-empty string
Gateway->>Gateway: Call JSON.parse(toolCall.function.arguments)
Note right of Gateway: Handles potential malformed JSON if not empty
end
Gateway->>Gateway: Construct AnthropicMessage with tool_use and parsed input
end
deactivate Gateway
Gateway-->>User: Return Transformed Chat Completion Response
|
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
This PR fixes
$defs
alongwith your schema#1103
Testing done
Did multi turn tool calling with empty string arguments in assistant tool call message
payload for testing