You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -31,6 +31,8 @@ Use this article to learn how to use the Computer Use tool with the Azure AI Pro
31
31
32
32
Save the name of your model's deployment name as an environment variable named `COMPUTER_USE_MODEL_DEPLOYMENT_NAME`.
33
33
34
+
* Before using the tool, you need to set up an environment that can capture screenshots and execute the recommended actions by the agent. We recommend using a sandboxed environment, such as Playwright for safety reasons.
35
+
34
36
The Computer Use tool requires the latest prerelease versions of the `azure-ai-projects` library. First we recommend creating a [virtual environment](https://docs.python.org/3/library/venv.html) to work in:
The following code sample shows a basic API request. Once the initial API request is sent, you would perform a loop where the specified action is performed in your application code, sending a screenshot with each turn so the model can evaluate the updated state of the environment. You can see an example integration for a similar API in the [Azure OpenAI documentation](../../../openai/how-to/computer-use.md#playwright-integration).
51
53
52
54
```python
55
+
import os, time, base64
56
+
from typing import List
57
+
from azure.ai.agents.models._models import ComputerScreenshot, TypeAction
53
58
from azure.ai.projects import AIProjectClient
54
-
from azure.ai.agents.models import ComputerUseTool
55
-
from azure.identity import DefaultAzureCredential
56
-
import os
57
-
import time
58
-
59
-
# Initialize client
60
-
project_client = AIProjectClient(
61
-
endpoint=os.environ["PROJECT_ENDPOINT"],
62
-
credential=DefaultAzureCredential(),
63
-
)
64
-
65
-
# Create agent with computer use capability (similar to OpenAI but enhanced)
model=os.environ["COMPUTER_USE_MODEL_DEPLOYMENT_NAME"], # computer-capable model
74
-
name="computer-assistant",
75
-
instructions="You are an assistant that can interact with computer interfaces to help users automate tasks. Always take a screenshot first to understand the current state.",
76
-
tools=[computer_use_tool]
59
+
from azure.ai.agents.models import (
60
+
MessageRole,
61
+
RunStepToolCallDetails,
62
+
RunStepComputerUseToolCall,
63
+
ComputerUseTool,
64
+
ComputerToolOutput,
65
+
MessageInputContentBlock,
66
+
MessageImageUrlParam,
67
+
MessageInputTextBlock,
68
+
MessageInputImageUrlBlock,
69
+
RequiredComputerUseToolCall,
70
+
SubmitToolOutputsAction,
77
71
)
72
+
from azure.identity import DefaultAzureCredential
78
73
79
-
# Create a thread for persistent computer automation
80
-
thread = project_client.agents.create_thread()
81
-
82
-
# Ask agent to automate a task
83
-
message = project_client.agents.create_message(
84
-
thread_id=thread.id,
85
-
role="user",
86
-
content="Check the latest Azure AI news on bing.com and summarize the top 3 articles"
87
-
)
88
-
89
-
# Run the agent - it will use computer use tool automatically
90
-
run = project_client.agents.create_run(
91
-
thread_id=thread.id,
92
-
agent_id=agent.id
93
-
)
94
-
95
-
# Poll for completion and get results
96
-
while run.status in ["queued", "in_progress", "requires_action"]:
97
-
if run.status =="requires_action":
98
-
# Handle safety checks or user confirmations
99
-
required_action = run.required_action
100
-
if required_action.type =="computer_call":
101
-
# User must acknowledge safety checks
102
-
project_client.agents.submit_tool_outputs(
103
-
thread_id=thread.id,
104
-
run_id=run.id,
105
-
tool_outputs=[
106
-
#TODO
107
-
]
108
-
)
109
-
110
-
time.sleep(1)
111
-
run = project_client.agents.retrieve_run(thread_id=thread.id, run_id=run.id)
Copy file name to clipboardExpand all lines: articles/ai-foundry/agents/how-to/tools/computer-use.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ services: cognitive-services
6
6
manager: nitinme
7
7
ms.service: azure-ai-agent-service
8
8
ms.topic: how-to
9
-
ms.date: 08/22/2025
9
+
ms.date: 09/09/2025
10
10
author: aahill
11
11
ms.author: aahi
12
12
ms.custom: references_regions
@@ -47,11 +47,11 @@ The following table lists some of the differences between the Computer Use Tool
47
47
| How it acts | A list of actions provided by the model | Virtual keyboard and mouse |
48
48
| Is it multi-step? | Yes | Yes |
49
49
| Interfaces | Browser | Computer and browser |
50
-
| Do I need to bring my own resource? | Your own Playwright resource with the keys stored as a connection. | No additional resource needed|
50
+
| Do I need to bring my own resource? | Your own Playwright resource with the keys stored as a connection. | No additional resource required but we highly recommend running this tool in a sandboxed environment.|
51
51
52
52
## Regional support
53
53
54
-
In order to use the Computer Use Tool, you need to have a Computer Use model deployment. The Computer Use model is available in the following regions:
54
+
In order to use the Computer Use Tool, you need to have a [Computer Use model](../../../foundry-models/concepts/models-sold-directly-by-azure.md#computer-use-preview) deployment. The Computer Use model is available in the following regions:
55
55
*`eastus2`
56
56
*`swedencentral`
57
57
*`southindia`
@@ -70,6 +70,9 @@ When working with the Computer Use tool, you typically would perform the followi
70
70
71
71
1. Send a new request with the updated state as a `tool_call_output`, and repeat this loop until the model stops requesting actions or you decide to stop.
72
72
73
+
> [!NOTE]
74
+
> Before using the tool, you need to set up an environment that can capture screenshots and execute the recommended actions by the agent. We recommend using a sandboxed environment, such as Playwright for safety reasons.
75
+
73
76
## Handling conversation history
74
77
75
78
You can use the `tool_call_id` parameter to link the current request to the previous response. Using this parameter is recommended if you don't want to manage the conversation history.
0 commit comments