Skip to content

Commit 10d2435

Browse files
Merge pull request #6405 from MicrosoftDocs/main
Auto Publish – main to live - 2025-08-05 22:05 UTC
2 parents 90fefbd + c160460 commit 10d2435

38 files changed

+964
-672
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: How to use the Browser Automation tool with the Azure AI Foundry Agent Service
3+
titleSuffix: Azure AI Foundry
4+
description: Learn how to automate browser use and interact with websites using AI Agents.
5+
services: azure-ai-agent-service
6+
manager: nitinme
7+
ms.service: azure-ai-agent-service
8+
ms.topic: how-to
9+
ms.date: 07/29/2025
10+
author: aahill
11+
ms.author: aahi
12+
ms.custom: azure-ai-agents
13+
---
14+
15+
# How to use the Browser Automation tool (preview)
16+
17+
Use this article to find step-by-step instructions and code samples for using the Browser Automation tool in the Azure AI Foundry Agent Service.
18+
19+
## Prerequisites
20+
21+
* The requirements in the [Browser Automation overview](./deep-research.md).
22+
* Your Azure AI Foundry Project endpoint.
23+
24+
[!INCLUDE [endpoint-string-portal](../../includes/endpoint-string-portal.md)]
25+
26+
Save this endpoint to an environment variable named `PROJECT_ENDPOINT`.
27+
28+
* Your playwright connection ID. You can find it in the Azure AI Foundry portal by selecting **Management center** from the left navigation menu. Then select **Connected resources**.
29+
30+
<!--
31+
:::image type="content" source="../../media/tools/deep-research/bing-resource-name.png" alt-text="A screenshot showing the Playwright connection. " lightbox="../../media/tools/deep-research/bing-resource-name.png":::
32+
-->
33+
Save this name to an environment variable named `PLAYWRIGHT_CONNECTION_NAME`.
34+
35+
* [!INCLUDE [model-name-portal](../../includes/model-name-portal.md)]
36+
37+
Save this name to an environment variable named `MODEL_DEPLOYMENT_NAME`.
38+
39+
## Example code
40+
41+
```python
42+
import os
43+
from azure.identity import DefaultAzureCredential
44+
from azure.ai.agents import AgentsClient
45+
from azure.ai.agents.models import MessageRole
46+
from azure.ai.projects import AIProjectClient
47+
48+
project_endpoint = os.environ["PROJECT_ENDPOINT"] # Ensure the PROJECT_ENDPOINT environment variable is set
49+
50+
project_client = AIProjectClient(
51+
endpoint=project_endpoint,
52+
credential=DefaultAzureCredential()
53+
)
54+
55+
playwright_connection = project_client.connections.get(
56+
name=os.environ["PLAYWRIGHT_CONNECTION_NAME"]
57+
)
58+
print(playwright_connection.id)
59+
60+
with project_client:
61+
agent = project_client.agents.create_agent(
62+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
63+
name="my-agent",
64+
instructions="use the tool to respond",
65+
tools=[{
66+
"type": "browser_automation",
67+
"browser_automation": {
68+
"connection": {
69+
"id": playwright_connection.id,
70+
}
71+
}
72+
}],
73+
)
74+
75+
print(f"Created agent, ID: {agent.id}")
76+
77+
thread = project_client.agents.threads.create()
78+
print(f"Created thread and run, ID: {thread.id}")
79+
80+
# Create message to thread
81+
message = project_client.agents.messages.create(
82+
thread_id=thread.id,
83+
role="user",
84+
content="something you want the tool to perform")
85+
print(f"Created message: {message['id']}")
86+
87+
# Create and process an Agent run in thread with tools
88+
run = project_client.agents.runs.create_and_process(
89+
thread_id=thread.id,
90+
agent_id=agent.id,
91+
)
92+
print(f"Run created, ID: {run.id}")
93+
print(f"Run finished with status: {run.status}")
94+
95+
if run.status == "failed":
96+
print(f"Run failed: {run.last_error}")
97+
98+
run_steps = project_client.agents.run_steps.list(thread_id=thread.id, run_id=run.id)
99+
for step in run_steps:
100+
print(step)
101+
print(f"Step {step['id']} status: {step['status']}")
102+
103+
# Check if there are tool calls in the step details
104+
step_details = step.get("step_details", {})
105+
tool_calls = step_details.get("tool_calls", [])
106+
107+
if tool_calls:
108+
print(" Tool calls:")
109+
for call in tool_calls:
110+
print(f" Tool Call ID: {call.get('id')}")
111+
print(f" Type: {call.get('type')}")
112+
113+
function_details = call.get("function", {})
114+
if function_details:
115+
print(f" Function name: {function_details.get('name')}")
116+
print() # add an extra newline between steps
117+
118+
# Delete the Agent when done
119+
project_client.agents.delete_agent(agent.id)
120+
print("Deleted agent")
121+
122+
# Fetch and log all messages
123+
response_message = project_client.agents.messages.get_last_message_by_role(thread_id=thread.id, role=MessageRole.AGENT)
124+
if response_message:
125+
for text_message in response_message.text_messages:
126+
print(f"Agent response: {text_message.text.value}")
127+
for annotation in response_message.url_citation_annotations:
128+
print(f"URL Citation: [{annotation.url_citation.title}]({annotation.url_citation.url})")
129+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: 'How to use Browser Automation in Azure AI Foundry Agent Service'
3+
titleSuffix: Azure AI Foundry
4+
description: Learn how to automate browser tasks using AI agents.
5+
services: cognitive-services
6+
manager: nitinme
7+
ms.service: azure-ai-agent-service
8+
ms.topic: how-to
9+
ms.date: 07/28/2025
10+
author: aahill
11+
ms.author: aahi
12+
ms.custom: azure-ai-agents
13+
---
14+
15+
# Browser Automation (preview)
16+
17+
> [!WARNING]
18+
> The Browser Automation tool comes with significant security risks. Both errors in judgment by the AI and the presence of malicious or confusing instructions on web pages which the AI encounters may cause it to execute commands you or others do not intend, which could compromise the security of your or other users' browsers, computers, and any accounts to which the browser or AI has access, including personal, financial, or enterprise systems. By using the Browser Automation tool, you are acknowledging that you bear responsibility and liability for any use of it and of any resulting agents you create with it, including with respect to any other users to whom you make Browser Automation tool functionality available, including through resulting agents. We strongly recommend using the Browser Automation tool on low-privilege virtual machines with no access to sensitive data or critical resources.
19+
20+
21+
The Browser Automation tool enables users to perform real-world browser tasks through natural language prompts. Powered by [Microsoft Playwright Workspaces](/azure/playwright-testing/overview-what-is-microsoft-playwright-testing), it facilitates multi-turn conversations to automate browser-based workflows such as searching, navigating, filling forms, and booking.
22+
23+
## How it works
24+
25+
The interaction begins when the user sends a user query to an agent connected to the Browser Automation tool. For example, *"Show me all available yoga classes this week from the following url \<url\>."* Upon receiving the request, Azure AI Foundry Agent Service creates an isolated browser session using your own provisioned Playwright workspace. Each session is sandboxed for privacy and security. The browser session mimics a real user browsing experience, enabling interaction with complex web UIs (for example, class schedules, filters, or booking pages). The browser performs Playwright-driven actions, such as navigating to relevant pages, and applying filters or parameters based on user preferences (such as time, location, instructor). Combining the model with Playwright allows the model to see the browser screen by parsing the HTML or XML pages into DOM documents, make decisions, and perform actions like clicking, typing, and navigating websites. You should exercise caution when using this tool.
26+
27+
An example flow would be:
28+
29+
1. A user sends a request to the model that includes a call to the Browser Automation tool with the URL you want to go to.
30+
31+
1. The Browser Automation tool receives a response from the model. If the response has action items, those items contain suggested actions to make progress toward the specified goal. For example an action might be a screenshot so the model can assess the current state with an updated screenshot or click with X/Y coordinates indicating where the mouse should be moved.
32+
33+
1. The Browser Automation tool executes the action in a sandboxed environment.
34+
35+
1. After executing the action, The Browser Automation tool captures the updated state of the environment as a screenshot.
36+
37+
1. The tool sends a new request with the updated state, and repeats this loop until the model stops requesting actions or the user decides to stop.
38+
39+
The Browser Automation tool supports multi-turn conversations, allowing the user to refine their request and complete a booking.
40+
41+
## Example scenarios:
42+
43+
- Booking & Reservations: Automate form-filling and schedule confirmation across booking portals.
44+
45+
- Product Discovery: Navigate ecommerce or review sites, search by criteria, and extract summaries.
46+
47+
## Setup
48+
49+
1. Create a [Playwright Workspace](https://aka.ms/pww/docs/manage-workspaces) resource.
50+
51+
1. [Generate an access token](https://aka.ms/pww/docs/manage-access-tokens) for the Playwright Workspace resource.
52+
53+
1. Access the workspace region endpoint in the **Workspace Details** page.
54+
1. Give the project identity a "Contributor" role on the Playwright Workspace resource, or [configure a custom role](https://aka.ms/pww/docs/manage-workspace-access).
55+
56+
1. Create a serverless connection in the Azure AI Foundry project with the Playwright workspace region endpoint and the Playwright workspace Access Token.
57+
58+
1. Go to the [Azure AI Foundry portal](https://ai.azure.com/) and select your project. Go to the **Management center** and select **connected resources**.
59+
60+
1. Create a new **Serverless Model** connection, and enter the following information.
61+
62+
* **Target URI**: The Playwright workspace region endpoint, for example `wss://{region}.api.playwright.microsoft.com/playwrightworkspaces/{workspaceId}/browsers`.
63+
64+
For more information on getting this value, see the [PlayWright documentation](https://aka.ms/pww/docs/configure-service-endpoint)
65+
66+
1. * **Key**: [Get the Playwright access token](https://aka.ms/pww/docs/generate-access-token)
67+
68+
For more information on creating a connection, see [Create a connection](../../../how-to/connections-add.md?pivots=fdp-project).
69+
70+
1. Create a Browser Automation tool with your connection ID.
71+
72+
## Transparency note
73+
74+
Review the [transparency note](/azure/ai-foundry/responsible-ai/agents/transparency-note#enabling-autonomous-actions-with-or-without-human-input-through-action-tools) when using this tool. The Browser Automation tool is a tool that can perform real-world browser tasks through natural language prompts, enabling automated browsing activities without human intervention.
75+
76+
Review the [responsible AI considerations](/azure/ai-foundry/responsible-ai/agents/transparency-note#considerations-when-choosing-a-use-case) when using this tool.

articles/ai-foundry/agents/how-to/tools/model-context-protocol-samples.md

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-agent-service
88
ms.topic: how-to
9-
ms.date: 07/14/2025
9+
ms.date: 08/05/2025
1010
author: aahill
1111
ms.author: aahi
1212
zone_pivot_groups: selection-mcp-code
@@ -17,6 +17,133 @@ ms.custom: azure-ai-agents-code
1717

1818
Use this article to find code samples for connecting Azure AI Foundry Agent Service with Model Context Protocol (MCP) servers.
1919

20+
:::zone pivot="csharp"
21+
22+
## Create a project client
23+
24+
Create a client object that contains the endpoint for connecting to your AI project and other resources.
25+
26+
> [!NOTE]
27+
> You can find an asynchronous example on [GitHub](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample26_PersistentAgents_MCP.md)
28+
29+
```csharp
30+
var projectEndpoint = System.Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
31+
var modelDeploymentName = System.Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME");
32+
var mcpServerUrl = System.Environment.GetEnvironmentVariable("MCP_SERVER_URL");
33+
var mcpServerLabel = System.Environment.GetEnvironmentVariable("MCP_SERVER_LABEL");
34+
35+
PersistentAgentsClient agentClient = new(projectEndpoint, new DefaultAzureCredential());
36+
37+
```
38+
39+
## Create the MCP tool definition
40+
41+
Create the MCP tool definition and configure allowed tools.
42+
43+
```csharp
44+
// Create MCP tool definition
45+
MCPToolDefinition mcpTool = new(mcpServerLabel, mcpServerUrl);
46+
47+
// Configure allowed tools (optional)
48+
string searchApiCode = "search_azure_rest_api_code";
49+
mcpTool.AllowedTools.Add(searchApiCode);
50+
```
51+
52+
Use the `MCPToolDefinition` during the agent initialization.
53+
54+
```csharp
55+
PersistentAgent agent = agentClient.Administration.CreateAgent(
56+
model: modelDeploymentName,
57+
name: "my-mcp-agent",
58+
instructions: "You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.",
59+
tools: [mcpTool]);
60+
```
61+
62+
## Create a thread and add a message
63+
64+
Create the thread, add the message containing a question for agent and start the run with MCP tool resources.
65+
66+
```csharp
67+
PersistentAgentThread thread = agentClient.Threads.CreateThread();
68+
69+
// Create message to thread
70+
PersistentThreadMessage message = agentClient.Messages.CreateMessage(
71+
thread.Id,
72+
MessageRole.User,
73+
"Please summarize the Azure REST API specifications Readme");
74+
75+
MCPToolResource mcpToolResource = new(mcpServerLabel);
76+
mcpToolResource.UpdateHeader("SuperSecret", "123456");
77+
ToolResources toolResources = mcpToolResource.ToToolResources();
78+
79+
// Run the agent with MCP tool resources
80+
ThreadRun run = agentClient.Runs.CreateRun(thread, agent, toolResources);
81+
82+
// Handle run execution and tool approvals
83+
while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress || run.Status == RunStatus.RequiresAction)
84+
{
85+
Thread.Sleep(TimeSpan.FromMilliseconds(1000));
86+
run = agentClient.Runs.GetRun(thread.Id, run.Id);
87+
88+
if (run.Status == RunStatus.RequiresAction && run.RequiredAction is SubmitToolApprovalAction toolApprovalAction)
89+
{
90+
var toolApprovals = new List<ToolApproval>();
91+
foreach (var toolCall in toolApprovalAction.SubmitToolApproval.ToolCalls)
92+
{
93+
if (toolCall is RequiredMcpToolCall mcpToolCall)
94+
{
95+
Console.WriteLine($"Approving MCP tool call: {mcpToolCall.Name}, Arguments: {mcpToolCall.Arguments}");
96+
toolApprovals.Add(new ToolApproval(mcpToolCall.Id, approve: true)
97+
{
98+
Headers = { ["SuperSecret"] = "123456" }
99+
});
100+
}
101+
}
102+
103+
if (toolApprovals.Count > 0)
104+
{
105+
run = agentClient.Runs.SubmitToolOutputsToRun(thread.Id, run.Id, toolApprovals: toolApprovals);
106+
}
107+
}
108+
}
109+
```
110+
111+
## Print the messages
112+
113+
```csharp
114+
Pageable<PersistentThreadMessage> messages = agentClient.Messages.GetMessages(
115+
threadId: thread.Id,
116+
order: ListSortOrder.Ascending
117+
);
118+
119+
foreach (PersistentThreadMessage threadMessage in messages)
120+
{
121+
Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: ");
122+
foreach (MessageContent contentItem in threadMessage.ContentItems)
123+
{
124+
if (contentItem is MessageTextContent textItem)
125+
{
126+
Console.Write(textItem.Text);
127+
}
128+
else if (contentItem is MessageImageFileContent imageFileItem)
129+
{
130+
Console.Write($"<image from ID: {imageFileItem.FileId}>");
131+
}
132+
Console.WriteLine();
133+
}
134+
}
135+
```
136+
137+
## Optional: Delete the agent
138+
139+
When you are done with your agent, you can delete it with:
140+
141+
```csharp
142+
agentClient.Threads.DeleteThread(threadId: thread.Id);
143+
agentClient.Administration.DeleteAgent(agentId: agent.Id);
144+
```
145+
:::zone-end
146+
20147
:::zone pivot="python"
21148

22149
## Initialize the client

articles/ai-foundry/agents/how-to/tools/overview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-agent-service
88
ms.topic: how-to
9-
ms.date: 06/17/2025
9+
ms.date: 07/29/2025
1010
author: aahill
1111
ms.author: aahi
1212
ms.custom: azure-ai-agents
@@ -36,6 +36,7 @@ To streamline workflows with your AI agent with capabilities to take actions. Th
3636
- **MCP tool**: Bring an existing Model Context Protocol (MCP) endpoint that you want to add to your AI agent.
3737
- **Function calling**: Write your own custom, stateless functions to define the expected behaviors.
3838
- **Azure Functions**: Write and manage your own custom, stateful functions.
39+
- **Browser Automation**: Perform real-world browser tasks through natural language prompts.
3940

4041
## How does a tool work in the Foundry Agent Service?
4142

@@ -72,6 +73,7 @@ The Foundry Agent Service provides the following built-in tools. You can use the
7273
|---------|---------|
7374
|[Azure AI Search](azure-ai-search.md) | Use an existing Azure AI Search index to ground agents with data in the index, and chat with your data. |
7475
|[Azure Functions](azure-functions.md) | Leverage your Azure Functions to create intelligent, event-driven applications. |
76+
|[Browser Automation](browser-automation.md) | Perform real-world browser tasks through natural language prompts. |
7577
|[Code Interpreter](code-interpreter.md) | Enable agents to write and run Python code in a sandboxed execution environment. |
7678
|[Deep Research (preview)](./deep-research.md) | Use OpenAI's advanced agentic research capability for analysis and reasoning. |
7779
|[File Search](file-search.md) | Augment agents with knowledge from outside its model, such as proprietary product information or documents provided by your users. |

articles/ai-foundry/agents/toc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ items:
4747
displayName: azure functions, functions
4848
- name: How to use Azure Functions
4949
href: how-to/tools/azure-functions-samples.md
50+
- name: Browser automation (preview)
51+
items:
52+
- name: Overview
53+
href: how-to/tools/browser-automation.md
54+
displayName: browser automation, web automation
55+
- name: How to use browser automation
56+
href: how-to/tools/browser-automation-samples.md
5057
- name: Code interpreter
5158
items:
5259
- name: Overview

0 commit comments

Comments
 (0)