Skip to content

support anthropic computer use#1126

Merged
VisargD merged 2 commits into
Portkey-AI:mainfrom
narengogi:chore/anthropic-computer-use
Jun 11, 2025
Merged

support anthropic computer use#1126
VisargD merged 2 commits into
Portkey-AI:mainfrom
narengogi:chore/anthropic-computer-use

Conversation

@narengogi

Copy link
Copy Markdown
Member

Add support for anthropic computer use

example playload:

{
    "model": "claude-4-opus-20250514",
    "max_tokens": 2000,
    "anthropic_beta": "computer-use-2025-01-24",
    "tools": [
        {
            "type": "computer",
            "computer": {
                "name": "computer_20250124",
                "display_width_px": 1024,
                "display_height_px": 768,
                "display_number": 1
            }
        },
        {
            "type": "text_editor_20250429",
            "name": "str_replace_based_edit_tool"
        },
        {
            "type": "bash_20250124",
            "name": "bash"
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": "Save a picture of a cat to my desktop."
        }
    ]
    // "thinking": {
    //     "type": "enabled",
    //     "budget_tokens": 1024
    // }
}

@matterai-app

matterai-app Bot commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

Code Quality new feature

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request introduces support for Anthropic's computer tool use. It modifies the AnthropicTool interface to include optional description, input_schema, and new properties like type, display_width_px, display_height_px, and display_number. A new computer property is added to the Tool interface in requestBody.ts. The AnthropicChatCompleteConfig logic is updated to process and include tool.computer objects in the tools array sent to the Anthropic API, mapping tool.computer.name to type and setting the tool name to 'computer'.

🔍 Impact of the Change

This change enables applications to leverage Anthropic models that support the computer-use beta feature, allowing for more advanced interactions where the model can specify display parameters for a 'computer' tool. It expands the capabilities of the Anthropic provider to support a new type of tool interaction.

📁 Total Files Changed

2 files were changed in this pull request.

🧪 Test Added

No specific tests were mentioned or added in the provided patch or PR description. Manual testing might have been performed based on the example payload provided in the PR body.

🔒Security Vulnerabilities

No security vulnerabilities were detected in the provided code changes.

Motivation

Add support for anthropic computer use

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

totalScore: 4

Related Issues

.

Tip

Quality Recommendations

  1. Add unit and/or integration tests to validate the correct transformation and handling of the new computer tool type, including edge cases for its properties.

  2. Consider adding explicit input validation for the computer tool's display properties (display_width_px, display_height_px, display_number) to ensure they are valid numbers and prevent potential runtime errors.

  3. Update relevant documentation (e.g., API reference, examples) to clearly describe the structure and usage of the new computer tool for Anthropic requests.

Sequence Diagram

sequenceDiagram
    actor User
    participant ClientApp as Client Application
    participant RequestBody as Request Body (src/types/requestBody.ts)
    participant AnthropicChatComplete as AnthropicChatCompleteConfig (src/providers/anthropic/chatComplete.ts)
    participant AnthropicAPI as Anthropic API

    User->>ClientApp: Sends Chat Completion Request
    ClientApp->>RequestBody: Constructs RequestBody with 'tools'
    Note over RequestBody: 'Tool' interface now supports 'computer' property
    RequestBody->>AnthropicChatComplete: Passes RequestBody to AnthropicChatCompleteConfig
    AnthropicChatComplete->>AnthropicChatComplete: Processes 'tools' array
    alt If tool.function exists
        AnthropicChatComplete->>AnthropicChatComplete: Adds tool.function to 'tools' array
    else If tool.computer exists
        AnthropicChatComplete->>AnthropicChatComplete: Adds tool.computer to 'tools' array
        Note over AnthropicChatComplete: Maps tool.computer.name to 'type'
        Note over AnthropicChatComplete: Sets name to 'computer'
        Note over AnthropicChatComplete: Adds display_width_px, display_height_px, display_number
    end
    AnthropicChatComplete->>AnthropicAPI: Sends processed Chat Completion Request
    AnthropicAPI-->>AnthropicChatComplete: Responds with Chat Completion
    AnthropicChatComplete-->>ClientApp: Returns Chat Completion Response
    ClientApp-->>User: Displays Chat Completion
Loading

@matterai-app matterai-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR adds support for Anthropic's computer tool functionality, which is a valuable addition. I've identified a few improvements that could enhance the implementation.

@Portkey-AI Portkey-AI deleted a comment from matterai-app Bot Jun 6, 2025
@Portkey-AI Portkey-AI deleted a comment from matterai-app Bot Jun 6, 2025
@Portkey-AI Portkey-AI deleted a comment from matterai-app Bot Jun 6, 2025
@narengogi narengogi requested review from VisargD and sk-portkey June 6, 2025 09:28
@matterai-app

matterai-app Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@VisargD VisargD merged commit 219ac9d into Portkey-AI:main Jun 11, 2025
2 checks passed
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.

3 participants