

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用電腦使用工具，透過 Amazon Bedrock 模型自動化 GUI 任務
<a name="computer-use"></a>

電腦使用是一種AnthropicClaude工具系列 （測試版），用於自動化圖形使用者介面 (GUI) 任務。此模型會在 JSON `scroll`中傳回`tool_use`動作`screenshot`，例如 `left_click`、`type`、 和 。您的應用程式會在桌面或容器上執行這些動作，並在之後Claude將產生的螢幕擷取畫面傳回 。

如需基礎工具通訊協定、動作的完整清單和提示工程指引，請參閱 Anthropic 文件中的[電腦使用](https://docs.anthropic.com/en/docs/build-with-claude/computer-use)。此頁面涵蓋該通訊協定上的 Amazon Bedrock 特定用量。

**警告**  
您可以使用電腦做為「Beta Service」，如 AWS 服務條款所定義。它受您與 的協議、 AWS AWS 服務條款和適用模型 EULA 的約束。電腦使用 API 會產生與標準 API 功能或聊天介面不同的唯一風險。使用電腦使用 API 與網際網路互動時，這些風險會提高。為了將風險降至最低，請考慮採取預防措施，例如：  
在專用虛擬機器或容器中以最低權限操作電腦使用功能，以防止直接系統攻擊或意外事故。
為避免資訊遭竊，請避免讓電腦使用 API 存取敏感帳戶或資料。
限制電腦使用 API 對必要網域的網際網路存取，以減少對惡意內容的暴露。
為了確保適當的監督，請在執行敏感任務 (例如可能對現實世界產生重大影響的決策) 以及需要明確同意的任何項目 (例如接受 Cookie、執行金融交易，或同意服務條款) 時，保留人工介入環節。
您啟用 Claude 以查看或存取的任何內容都可能覆寫指示，或導致 Claude 發生錯誤或執行意外動作。採取適當的預防措施 (例如將 Claude 與敏感表面隔離) 至關重要，包括避免與提示注入相關的風險。在啟用或請求啟用自有產品中電腦使用功能所需的許可之前，請通知最終使用者任何相關風險，並適時取得其同意。

**Topics**
+ [在 Amazon Bedrock 上使用電腦](#computer-use-bedrock-specifics)
+ [範例請求](#computer-use-example-code)

## 在 Amazon Bedrock 上使用電腦
<a name="computer-use-bedrock-specifics"></a>

`bedrock-runtime` 和 `bedrock-mantle`端點都支援電腦使用。若要尋找哪些模型支援電腦在每個端點上使用 ，請參閱每個 中的*功能和功能*表[模型一目了然](model-cards.md)。向不支援電腦使用的模型提交請求，或將工具類型與不支援的模型配對， 會傳回 `400 invalid_request_error`。

若要在請求上啟用電腦使用，請同時包含：
+ 命名電腦使用 Beta 版`anthropic_beta`的項目 （例如，在 的請求內文`"anthropic_beta": ["computer-use-2025-11-24"]`中`bedrock-runtime`，或 的 `anthropic-beta: computer-use-2025-11-24` HTTP 標頭中`bedrock-mantle`)。
+ `tools` 陣列中的一或多個Anthropic預先定義工具項目，其`type`欄位符合 Beta 版本 （例如 `computer_20251124`、 `bash_20250124`或 `text_editor_20250124`)。

如需 beta-version-to-tool-type 配對、其他 Anthropic定義的工具 (bash 和文字編輯器），以及完整的請求和回應欄位文件，請參閱 [電腦使用 (Beta 版)](model-parameters-anthropic-claude-messages-tool-use.md#model-parameters-anthropic-claude-messages-computer-use)。

## 範例請求
<a name="computer-use-example-code"></a>

下列 Python 範例使用電腦使用工具，透過`bedrock-runtime`端點傳送 Messages API 請求。`modelId` 將 取代為支援電腦使用的 （請參閱 [模型一目了然](model-cards.md))。

```
import boto3
import json

client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.invoke_model(
    modelId="us.anthropic.claude-opus-4-7",
    body=json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "anthropic_beta": ["computer-use-2025-11-24"],
        "max_tokens": 1024,
        "messages": [
            {"role": "user", "content": "Take a screenshot of the desktop."}
        ],
        "tools": [
            {
                "type": "computer_20251124",
                "name": "computer",
                "display_width_px": 1024,
                "display_height_px": 768,
            }
        ],
    }),
)

result = json.loads(response["body"].read())
print(result["stop_reason"])  # "tool_use" when the model issues a computer action
print(result["content"])      # contains the tool_use block describing the action
```

如需同等`bedrock-mantle`的訊息 API 請求形狀，請參閱 [使用 Anthropic Messages API 的推論](inference-messages-api.md)。