Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

docs(browser): Browser Service Update

xiaoxiawangf39d1e643dba
diff --git a/docs/assets/images/browser1.png b/docs/assets/images/browser1.png
index 35e97653f0..c052d0f20c 100644
Binary files a/docs/assets/images/browser1.png and b/docs/assets/images/browser1.png differ
diff --git a/docs/assets/images/browser2.png b/docs/assets/images/browser2.png
index 4be7241609..37f6f5744c 100644
Binary files a/docs/assets/images/browser2.png and b/docs/assets/images/browser2.png differ
diff --git a/docs/en/Browser.md b/docs/en/Browser.md
index b8cfde69cf..bf2a489f73 100644
--- a/docs/en/Browser.md
+++ b/docs/en/Browser.md
@@ -1,34 +1,34 @@
# Browser tools
-## 1. Overview
+## 1. Conceptual Overview
-Browser tools drive a real Chrome instance for form filling, clicks, uploads, and web tasks. Configure Chrome in the web UI and start the browser service; the system launches an attachable Chrome instance. When needed, the agent connects and controls it.
+Browser tools in JiuwenSwarm enable driving a real Chrome instance for form filling, clicks, uploads, and web tasks. Users first configure Chrome path in the web UI and start the browser service; the system launches an attachable Chrome instance. When needed, the agent connects to and controls this browser.
-## 2. Architecture
+### 1.1 Key Capabilities
-- **Web UI**: “Browser service” panel — Chrome path and start/stop.
-- **Backend**: `browser_start_client.py` starts local Chrome with remote debugging.
-- **Runtime**: Playwright MCP wrapper; tools talk to the runtime via MCP.
-- **Agent**: `browser_run_task` turns natural language into browser actions.
-- **Sessions**: Browser state is reused per `session_id` (logins, tabs, permissions).
+The browser tools currently support the following capabilities:
-Flow: **UI config → start Chrome → runtime attaches → agent runs tasks**.
+- Open web pages and wait for loading
+- Continue operations on already logged-in websites
+- Click buttons, input text, select page elements
+- Execute multi-step web tasks
+- Reuse the same browser session to reduce repeated logins
+- Read page titles, URLs, and page content when needed
+- Support complex tasks like file uploads, email composition, and web form submissions
-## 3. Capabilities
+### 1.2 Typical Use Cases
-- Open pages and wait for load
-- Continue on sites where you are already logged in
-- Click, type, select elements
-- Multi-step flows
-- Reuse one browser session
-- Read title, URL, page content
-- Forms, attachments, mail, etc.
+- **Web Information Extraction**: Extract structured information from news sites, document pages, etc.
+- **Email Operations**: Log in to email to send messages, check inbox, download attachments
+- **Form Filling**: Automatically fill out online registration, application forms
+- **Online Shopping**: Browse products, compare prices, add to cart
+- **Enterprise System Operations**: Complete approvals, queries, etc. in internal systems
-## 4. Web UI steps
+## 2. Quick Start (Frontend Operations Only)
Install Chrome first.
-### Step 1: Chrome path and profile
+### 2.1 Step 1: Chrome path and profile
1. Open Chrome.
2. Visit `chrome://version`.
@@ -36,62 +36,118 @@ Install Chrome first.
- **Executable path** → `CHROME_PATH`
- **Profile path** → confirms user data for login debugging
-### Step 2: Open the browser service panel
+Where:
+- Executable path is generally the complete path to `chrome.exe`.
+- Profile directory helps confirm the current browser account and data directory, facilitating troubleshooting of login state or authorization issues.
+
+### 2.2 Step 2: Open the browser service panel
1. Open the JiuwenSwarm web UI.
-![Browser panel](../assets/images/browser1.png)
+ ![Browser panel](../assets/images/browser1.png)
2. Go to **Settings** → **Browser service**.
3. Find the Chrome path field.
-![Chrome path](../assets/images/browser2.png)
+ ![Chrome path](../assets/images/browser2.png)
-### Step 3: Set `CHROME_PATH`
+### 2.3 Step 3: Set `CHROME_PATH`
1. Copy the executable path from `chrome://version`.
-![Chrome version](../assets/images/browser3.png)
+ ![Chrome version](../assets/images/browser3.png)
2. Paste into **CHROME_PATH** and **Save path**.
-### Step 4: Start the browser service
-
+### 2.4 Step 4: Start the browser service
1. Click **Start browser service**.
2. A new Chrome window should open — that instance is controlled by the agent.
-### Step 5: Log in manually
+This popped-up Chrome is the browser instance that can be controlled by the agent later.
+
+### 2.5 Step 5: Log in manually
For mail, SSO, or intranet, complete login **in that Chrome window** first.
-### Step 6: Use from chat
+If your tasks require website login, email authorization, enterprise system access, or using existing account states, complete the necessary manual operations in that Chrome, such as:
+
+- Log in to Gmail / Outlook / corporate email
+- Complete manual authentication via SMS, verification code, QR code scan, etc.
+- Allow site access permissions
+- Open the target page to be operated
+
+### 2.6 Step 6: Use from chat
Ask the agent to open pages, fill forms, or continue logged-in flows. It uses the authorized Chrome, not a cold profile.
-## 5. Backend configuration
+After completing authorization, you can ask the agent to perform browser tasks in the conversation, such as:
-- **`config/config.yaml`**: Chrome launch (path, debugging port, profile).
-- **`.env`**: MCP, Playwright, timeouts.
+- Open a webpage and read information
+- Continue clicking and filling forms after login
+- Compose emails, upload attachments, wait for confirmation in email
-### 5.1 `config/config.yaml`
+When the task requires a browser, the agent will control this already authorized Chrome, not create a completely stateless browser again.
-```yaml
-browser:
- chrome_path: "C:\\Users\\YOUR_USER\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
- remote_debugging_address: "127.0.0.1"
- remote_debugging_port: 9222
- user_data_dir: ""
- profile_directory: "Default"
-```
+## 3. Usage Tips
+
+To make the browser tools more stable, follow these recommendations:
+
+- Prefer using the real Chrome installed locally rather than a temporary browser.
+- After starting the browser service, prioritize completing login and authorization in the popped-up Chrome.
+- For long-flow tasks, try to maintain the same session to avoid frequently changing browser states.
+- For scenarios involving email, enterprise systems, online banking, etc., it is recommended to complete manual login first before letting the agent continue operations.
+- If the browser state is abnormal, restart the browser service and test again.
+- Ensure `PLAYWRIGHT_CDP_URL` matches the debugging address and port in `config.yaml`.
+- Keep `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0` to prevent the model from splitting browser tasks into too many short calls.
+
+## 4. Practical Cases
+
+### 4.1 Case 1: Web Information Extraction
+**Task Description**: Extract news titles and summaries from a specific web page
+
+**Operation Steps**:
+1. Start the browser service and complete necessary authorization
+2. Enter in the conversation: "Please extract today's headline news title and summary from https://example.com/news"
+3. The agent will automatically call browser tools to access the specified web page
+4. The browser will parse the page content and extract the required information
+5. The agent will organize the extracted information and return it to the user
+
+### 4.2 Case 2: Email Sending (with Attachment)
+**Task Description**: Send an email with attachment using Gmail
+
+**Operation Steps**:
+1. Start the browser service
+2. Log in to Gmail account in the popped-up Chrome
+3. Enter in the conversation: "Please send an email to [email protected], subject: Test Email, content: This is a test email, attachment: /path/to/file.pdf"
+4. The agent will call browser tools to open Gmail compose page
+5. The browser will automatically fill in recipient, subject, content, and upload the attachment
+6. After sending is complete, the agent will notify the user that the email has been sent
+
+> **Note**: Operation screenshots will be added after future frontend updates. Each case will display 1-2 images, mainly showing the key execution process and final results.
+
+## 5. Backend Configuration
+
+### 5.1 Configuration Files Overview
+
+The browser tool configuration involves several core files that work together to configure and run the browser:
+
+- **`config/config.yaml`**: Mainly configures Chrome startup parameters, such as Chrome executable path, remote debugging address and port. These configurations are the foundation for browser startup.
+- **`.env`**: Configures browser runtime, MCP connection, Playwright parameters, timeout settings and other environment variables that affect the browser's runtime behavior.
+- **`.env.template`**: Environment variable template file containing all available environment variables and their default values, which can be used as a configuration reference.
-- **`chrome_path`**: Executable; can be a string or per-OS map.
-- **`remote_debugging_address`**: Usually `127.0.0.1`.
-- **`remote_debugging_port`**: Often `9222`.
-- **`user_data_dir`**: Empty uses OS default.
-- **`profile_directory`**: Often `Default`.
+The relationship between these three files is: `config/config.yaml` provides the basic parameters for browser startup, and `.env` provides the runtime environment configuration. Together, they ensure the browser tools work properly.
-Per-OS example:
+### 5.2 Browser Configuration in config.yaml
+| Configuration Item | Type | Default Value | Description |
+|--------------------|------|---------------|-------------|
+| `browser.chrome_path` | string/map | - | Chrome executable path, can be a single string or a map by OS |
+| `browser.remote_debugging_address` | string | "127.0.0.1" | Chrome remote debugging listening address |
+| `browser.remote_debugging_port` | integer | 9222 | Chrome remote debugging port |
+| `browser.user_data_dir` | string | "" | Chrome user data directory, use system default when empty |
+| `browser.profile_directory` | string | "Default" | Chrome Profile name to use |
+
+**Example configuration by OS**:
```yaml
browser:
chrome_path:
@@ -104,47 +160,46 @@ browser:
profile_directory: "Default"
```
-### 5.2 `.env` — browser runtime
+### 5.2 Browser Configuration in .env
-#### A. Browser MCP wrapper
+#### 5.2.1 Browser MCP Wrapper Configuration
-```dotenv
-BROWSER_RUNTIME_MCP_ENABLED=1
-BROWSER_RUNTIME_MCP_CLIENT_TYPE=streamable-http
-BROWSER_RUNTIME_MCP_SERVER_ID=playwright_runtime_wrapper
-BROWSER_RUNTIME_MCP_SERVER_NAME=playwright-runtime-wrapper
-BROWSER_RUNTIME_MCP_SERVER_PATH=http://127.0.0.1:8940/mcp
-BROWSER_RUNTIME_MCP_TIMEOUT_S=300
-BROWSER_RUNTIME_MCP_HOST=127.0.0.1
-BROWSER_RUNTIME_MCP_PORT=8940
-BROWSER_RUNTIME_MCP_PATH=/mcp
-BROWSER_RUNTIME_MCP_COMMAND=
-BROWSER_RUNTIME_MCP_ARGS=
-BROWSER_RUNTIME_MCP_AUTO_SSE_FALLBACK=1
-```
+| Environment Variable | Default Value | Description |
+|----------------------|---------------|-------------|
+| `BROWSER_RUNTIME_MCP_ENABLED` | 1 | Whether to enable browser MCP wrapper |
+| `BROWSER_RUNTIME_MCP_CLIENT_TYPE` | streamable-http | MCP client type |
+| `BROWSER_RUNTIME_MCP_SERVER_ID` | playwright_runtime_wrapper | Wrapper identifier information |
+| `BROWSER_RUNTIME_MCP_SERVER_NAME` | playwright-runtime-wrapper | Wrapper name |
+| `BROWSER_RUNTIME_MCP_SERVER_PATH` | http://127.0.0.1:8940/mcp | Wrapper access address |
+| `BROWSER_RUNTIME_MCP_TIMEOUT_S` | 300 | MCP connection or call layer timeout control |
+| `BROWSER_RUNTIME_MCP_HOST` | 127.0.0.1 | Host used when automatically starting wrapper locally |
+| `BROWSER_RUNTIME_MCP_PORT` | 8940 | Port used when automatically starting wrapper locally |
+| `BROWSER_RUNTIME_MCP_PATH` | /mcp | Path used when automatically starting wrapper locally |
+| `BROWSER_RUNTIME_MCP_COMMAND` | - | Wrapper startup command override, usually left empty |
+| `BROWSER_RUNTIME_MCP_ARGS` | - | Wrapper startup arguments override, usually left empty |
+| `BROWSER_RUNTIME_MCP_AUTO_SSE_FALLBACK` | 1 | Whether to allow SSE fallback in certain modes |
-#### B. Official Playwright MCP
+#### 5.2.2 Official Playwright MCP Configuration
-```dotenv
-PLAYWRIGHT_MCP_COMMAND=npx
-PLAYWRIGHT_MCP_ARGS=-y @playwright/mcp@latest
-PLAYWRIGHT_CDP_URL=http://127.0.0.1:9222
-```
+| Environment Variable | Default Value | Description |
+|----------------------|---------------|-------------|
+| `PLAYWRIGHT_MCP_COMMAND` | npx | Command to start official Playwright MCP |
+| `PLAYWRIGHT_MCP_ARGS` | -y @playwright/mcp@latest | Arguments to start official Playwright MCP |
+| `PLAYWRIGHT_CDP_URL` | http://127.0.0.1:9222 | CDP address to connect to the started Chrome, should match debugging address and port in config.yaml |
-`PLAYWRIGHT_CDP_URL` must match `config.yaml` debugging host/port.
+#### 5.2.3 Timeout and Execution Strategy Configuration
-#### C. Timeouts
+| Environment Variable | Default Value | Description |
+|----------------------|---------------|-------------|
+| `PLAYWRIGHT_TOOL_TIMEOUT_S` | 300 | Total watchdog timeout for browser tool execution |
+| `BROWSER_TIMEOUT_S` | 300 | Default long timeout for browser tasks; if the model passes a smaller timeout_s, it will be clamped to at least this value |
+| `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE` | 0 | Whether to allow the model to shorten task timeouts, recommended to keep as 0 |
-```dotenv
-PLAYWRIGHT_TOOL_TIMEOUT_S=300
-BROWSER_TIMEOUT_S=300
-BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
-```
+### 5.3 Recommended Minimal Configuration
-### 5.3 Minimal recommended setup
-
-`config/config.yaml`:
+To use the browser tools properly, ensure at least the following fields are correct:
+**config/config.yaml**
```yaml
browser:
chrome_path: "C:\\Users\\YOUR_USER\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
@@ -154,8 +209,7 @@ browser:
profile_directory: "Default"
```
-`.env`:
-
+**.env**
```dotenv
BROWSER_RUNTIME_MCP_ENABLED=1
BROWSER_RUNTIME_MCP_CLIENT_TYPE=streamable-http
@@ -168,15 +222,19 @@ BROWSER_TIMEOUT_S=300
BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
```
-## 6. Tips
+## 6. Principle and Code Architecture
+
+### 6.1 Technical Architecture
-- Prefer a real local Chrome install.
-- **Log in** in the launched window before heavy automation.
-- Keep one session for long flows.
-- **Align `PLAYWRIGHT_CDP_URL`** with `config.yaml` debugging settings.
-- Keep **`BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0`** so the model cannot shorten timeouts too aggressively.
+The core flow of the current browser tools is as follows:
-## 7. Code index
+- **Web UI**: Provides a "Browser service" panel for configuring Chrome executable path and starting/stopping the browser service
+- **Backend Application**: Starts local Chrome with remote debugging capabilities via `browser_start_client.py`
+- **Browser Runtime**: Based on Playwright MCP encapsulation, browser tools communicate with the runtime via MCP client
+- **Agent Call**: When the agent calls tools like `browser_run_task`, the runtime converts natural language tasks into browser operation steps
+- **Session Management**: Browsers are reused by `session_id`, maintaining login state, page context, and authorization status within the same session
+
+In simple terms:
### Frontend
- `jiuwenswarm/channels/web/frontend/src/components/BrowserPanel/index.tsx` — path, save, start service.
@@ -188,9 +246,28 @@ BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
- `jiuwenswarm/agents/harness/common/tools/browser-move/src/playwright_runtime_mcp_server.py` — MCP server.
- `.../playwright_runtime/runtime.py`, `service.py`, `agents.py`, `config.py` — runtime orchestration.
-### Config
-- `config/config.yaml`, `.env`, `.env.template`
+`UI config → start Chrome → runtime attaches → agent runs tasks`
+
+### 6.2 Core Code
+
+The core code of the browser tools is mainly distributed in the following modules:
+
+- **Tool Management Module**: `jiuwenswarm/agents/harness/common/tools/` is the underlying module that manages all tools in the system. Browser-related tools are mainly implemented under this module.
+- **Frontend Interface Module**: `jiuwenswarm/channels/web/frontend/` is responsible for user interface interaction.
+
+Specific file descriptions:
+
+| Module | File Path | Function Description |
+|--------|-----------|----------------------|
+| Frontend Browser Service Panel | `jiuwenswarm/channels/web/frontend/src/components/BrowserPanel/index.tsx` | Responsible for reading path, saving path, triggering "Start browser service" |
+| Backend Application Entry | `app.py` | Provides frontend call entries like `path.get`, `path.set`, `browser.start` |
+| Chrome Startup Script | `tools/browser_start_client.py` | Reads `browser.*` configuration from `config/config.yaml`, starts Chrome with remote debugging capabilities |
+| Browser MCP Access | `tools/browser_tools.py` | Browser MCP wrapper access, automatic startup, client patch, configuration building |
+| Browser Runtime MCP Server | `tools/browser-move/src/playwright_runtime_mcp_server.py` | Browser runtime MCP server entry |
+| Browser Runtime Orchestration Layer | `tools/browser-move/src/playwright_runtime/runtime.py` | Browser runtime orchestration layer |
+| Browser Task Execution | `tools/browser-move/src/playwright_runtime/service.py` | Browser task execution, session reuse, timeout guardrails |
+| Browser Runtime Configuration | `tools/browser-move/src/playwright_runtime/config.py` | Playwright MCP and browser runtime configuration parsing |
-## 8. Summary
+## 7. Summary
-Browser tools let the agent run **in your authenticated Chrome**: the UI configures and starts Chrome; the backend attaches and automates via Playwright MCP.
+The essence of browser tools is to allow the agent to execute web operations on your already authorized real Chrome; the frontend is responsible for configuration and startup, while the backend is responsible for takeover and automated execution.
\ No newline at end of file
diff --git a/docs/en/Quickstart.md b/docs/en/Quickstart.md
index 4fc472dccb..0fd7e268bf 100644
--- a/docs/en/Quickstart.md
+++ b/docs/en/Quickstart.md
@@ -120,20 +120,12 @@ Page display after clearing:
**When to clear a session?**
-<<<<<<< HEAD
- Navigate to the frontend directory `jiuwenswarm/channels/web/frontend` and install dependencies:
- ```bash
- cd jiuwenswarm/channels/web/frontend
- npm install
- ```
-=======
| Scenario | Description |
|----------|-------------|
| **Topic Switch** | Current conversation is complete, want to start a completely new topic |
| **Context Confusion** | Too much content in current session, model understanding deviates |
| **Repeated/Wrong Response** | Model falls into loop response or gives irrelevant answers |
| **Privacy/Sensitive Info** | Current session contains temporary sensitive information that needs immediate clearing |
->>>>>>> 6e8b643 (docs(Quickstart): 同步中英文版本,补充环境要求)
**Comparison: Clear vs Not Clear Session:**
diff --git a/docs/zh/Quickstart.md b/docs/zh/Quickstart.md
index 44ca5192fb..4d583c5c24 100644
--- a/docs/zh/Quickstart.md
+++ b/docs/zh/Quickstart.md
@@ -58,8 +58,7 @@ jiuwenswarm-start
当看到类似上述提示时,表示服务已启动,在浏览器中访问 `http://localhost:5173` 即可使用。
-<<<<<<< HEAD
-​适合基于JiuwenSwarm进行二次开发适配的用户。
+适合基于JiuwenSwarm进行二次开发适配的用户。
### `uv`方式安装
- 使用`uv`新建虚拟环境
diff --git "a/docs/zh/\346\265\217\350\247\210\345\231\250.md" "b/docs/zh/\346\265\217\350\247\210\345\231\250.md"
index e113ba8c3f..ed16c7d36e 100644
--- "a/docs/zh/\346\265\217\350\247\210\345\231\250.md"
+++ "b/docs/zh/\346\265\217\350\247\210\345\231\250.md"
@@ -1,24 +1,11 @@
# 浏览器工具说明
-## 1. 简介
+## 1. 概念科普
浏览器工具是 JiuwenSwarm 中用于驱动真实浏览器完成网页任务的一套能力。它适合处理需要表单填写、页面点击、文件上传、网页检索等场景。
从使用方式上看,用户先在前端页面中配置本机 Chrome 路径并启动浏览器服务。系统会拉起一个可被授权的 Chrome 浏览器实例;后续在任务需要时,Agent 会连接并操控这个浏览器完成操作。
-## 2. 技术简介
-当前浏览器工具的核心链路如下:
-
-- 前端页面提供“浏览器服务”面板,用于配置 Chrome 可执行文件路径并启动浏览器服务。
-- 后端通过 `browser_start_client.py` 启动本机 Chrome,并开启远程调试能力。
-- 浏览器自动化运行时基于 Playwright MCP 封装,浏览器工具通过 MCP client 与运行时通信。
-- Agent 调用 `browser_run_task` 等工具时,运行时会把自然语言任务转换为浏览器操作步骤。
-- 浏览器会按 `session_id` 复用,同一会话下可以保持登录态、页面上下文和授权状态。
-
-可以简单理解为:
-
-`前端配置 -> 启动 Chrome -> 运行时接管 Chrome -> Agent 在需要时操控浏览器执行任务`
-
-## 3. 主要功能
+### 1.1 主要功能
浏览器工具目前主要支持以下能力:
- 打开网页并等待页面加载
@@ -29,10 +16,19 @@
- 在需要时读取页面标题、URL、页面结果
- 配合附件上传、邮件填写、网页表单提交等复杂任务
-## 4. 前端使用步骤
+### 1.2 典型使用场景
+
+- **网页信息提取**:从新闻网站、文档页面等提取结构化信息
+- **邮件操作**:登录邮箱发送邮件、查看收件箱、下载附件
+- **表单填写**:自动填写在线报名、注册、申请等表单
+- **在线购物**:浏览商品、比较价格、加入购物车
+- **企业系统操作**:在内部系统中完成审批、查询等任务
+
+## 2. 快速上手(仅展示前端操作即可)
+
如果要在前端使用浏览器工具,请先确保本机已经安装 Chrome 浏览器。
-### 步骤 1:确认 Chrome 安装路径和 Profile 目录
+### 2.1 步骤 1:确认 Chrome 安装路径和 Profile 目录
1. 打开 Chrome 浏览器。
2. 在地址栏输入 `chrome://version` 并回车。
3. 记录以下两个信息:
@@ -43,34 +39,34 @@
- 可执行文件路径一般是 `chrome.exe` 的完整路径。
- Profile 目录用于帮助确认当前浏览器账户和资料目录,方便排查登录态或授权问题。
-### 步骤 2:打开前端的“浏览器服务”面板
+### 2.2 步骤 2:打开前端的“浏览器服务”面板
1. 打开 JiuwenSwarm 前端页面。
-![浏览器服务面板示意图](../assets/images/browser1.png)
+ ![浏览器服务面板示意图](../assets/images/browser1.png)
2. 进入“设置”中的“浏览器服务”区域。
3. 找到 Chrome 路径输入框。
-![浏览器路径配置示意图](../assets/images/browser2.png)
+ ![浏览器路径配置示意图](../assets/images/browser2.png)
-### 步骤 3:填写 CHROME_PATH
+### 2.3 步骤 3:填写 CHROME_PATH
1. 将在 `chrome://version` 中看到的 Chrome 可执行文件完整路径复制出来。
-![chrome系统路径查询示意图](../assets/images/browser3.png)
+ ![chrome系统路径查询示意图](../assets/images/browser3.png)
2. 粘贴到前端页面的 `CHROME_PATH` 输入框中。
3. 点击“保存路径”。
-### 步骤 4:启动浏览器服务
+### 2.4 步骤 4:启动浏览器服务
1. 在浏览器服务面板中点击“启动浏览器服务”。
2. 系统会调用后端启动脚本,拉起一个 Chrome 浏览器。
3. 如果启动成功,通常会弹出一个新的 Chrome 窗口。
这个弹出的 Chrome 就是后续可被 Agent 操控的浏览器实例。
-### 步骤 5:在弹出的浏览器中完成必要授权
+### 2.5 步骤 5:在弹出的浏览器中完成必要授权
如果你的任务需要登录网站、授权邮箱、访问企业系统或使用已有账号状态,请在这个 Chrome 中完成必要的人工操作,例如:
- 登录 Gmail / Outlook / 企业邮箱
@@ -78,7 +74,7 @@
- 允许站点访问权限
- 打开需要操作的目标页面
-### 步骤 6:交给 Agent 使用浏览器工具
+### 2.6 步骤 6:交给 Agent 使用浏览器工具
完成授权后,用户就可以在对话里提出需要浏览器执行的任务,例如:
- 打开某个网页并读取信息
@@ -87,45 +83,66 @@
当任务需要浏览器时,Agent 会操控这个已经获得授权的 Chrome,而不是重新新建一个完全无状态的浏览器。
+## 3. 使用建议
+
+为了让浏览器工具更稳定,建议遵循以下做法:
+
+- 尽量使用本机真实安装的 Chrome,而不是临时浏览器。
+- 启动浏览器服务后,优先在弹出的 Chrome 中完成登录和授权。
+- 对于长流程任务,尽量保持同一个会话,避免频繁更换浏览器状态。
+- 如果任务涉及邮箱、企业系统、网银等场景,建议先人工完成一次登录,再交给 Agent 继续操作。
+- 如果浏览器状态异常,可以重新启动浏览器服务后再测试。
+- 建议让 `PLAYWRIGHT_CDP_URL` 与 `config.yaml` 中的远程调试地址、端口保持一致。
+- 建议保持 `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0`,避免模型把浏览器任务拆成过多短调用。
+
+## 4. 案例实践
+
+### 4.1 案例一:网页信息提取
+**任务描述**:从特定网页提取新闻标题和摘要
+
+**操作步骤**:
+1. 启动浏览器服务并完成必要的授权
+2. 在对话中输入:"请从 https://example.com/news 提取今天的头条新闻标题和摘要"
+3. Agent 会自动调用浏览器工具访问指定网页
+4. 浏览器会解析页面内容并提取所需信息
+5. Agent 将提取到的信息整理后返回给用户
+
+### 4.2 案例二:邮件发送(带附件)
+**任务描述**:使用 Gmail 发送一封包含附件的邮件
+
+**操作步骤**:
+1. 启动浏览器服务
+2. 在弹出的 Chrome 中登录 Gmail 账号
+3. 在对话中输入:"请帮我发送一封邮件,收件人:[email protected],主题:测试邮件,内容:这是一封测试邮件,附件:/path/to/file.pdf"
+4. Agent 会调用浏览器工具,打开 Gmail 写信页面
+5. 浏览器会自动填写收件人、主题、内容,并上传附件
+6. 发送完成后,Agent 会通知用户邮件已发送
+
+> **说明**:后续前端更新后会补充操作配图,每个案例将展示1-2张图片,主要展示关键执行流程和最终结果。
+
## 5. 后端配置方式
-后端配置主要分为两部分:
-- `config/config.yaml`:负责本机 Chrome 启动参数
-- `.env`:负责浏览器运行时、MCP 通信、Playwright 和超时参数
+### 5.1 配置文件概述
-### 5.1 config/config.yaml
-`config/config.yaml` 中的 `browser` 配置块用于启动本机 Chrome。当前支持的字段如下:
+浏览器工具的配置涉及以下几个核心文件,它们共同协作完成浏览器的配置和运行:
-```yaml
-browser:
- chrome_path: "C:\\Users\\YOUR_USER\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
- remote_debugging_address: "127.0.0.1"
- remote_debugging_port: 9222
- user_data_dir: ""
- profile_directory: "Default"
-```
+- **`config/config.yaml`**:主要配置 Chrome 启动参数,如 Chrome 可执行文件路径、远程调试地址和端口等,这些配置是浏览器启动的基础
+- **`.env`**:配置浏览器运行时、MCP 连接、Playwright 参数和超时设置等环境变量,这些配置会影响浏览器的运行时行为
+- **`.env.template`**:环境变量模板文件,包含所有可用的环境变量及其默认值,可作为配置参考
+
+这三个文件的关系是:`config/config.yaml` 提供浏览器启动的基础参数,`.env` 提供运行时环境配置,两者结合确保浏览器工具正常工作。
+
+### 5.2 config.yaml 中浏览器配置
-字段说明:
-
-- `browser.chrome_path`
- - Chrome 可执行文件路径
- - 可以是单个字符串,也可以按 OS 写成 map
- - 前端“保存路径”本质上就是把这个字段写回 `config/config.yaml`
-- `browser.remote_debugging_address`
- - Chrome 远程调试监听地址
- - 一般保持 `127.0.0.1`
-- `browser.remote_debugging_port`
- - Chrome 远程调试端口
- - 默认通常为 `9222`
-- `browser.user_data_dir`
- - Chrome 用户数据目录
- - 留空时,启动脚本会按系统使用默认目录
-- `browser.profile_directory`
- - 要使用的 Chrome Profile 名称
- - 常见值是 `Default`
-
-如果你希望按操作系统分别配置 `chrome_path`,可以这样写:
+| 配置项 | 类型 | 默认值 | 说明 |
+|--------|------|--------|------|
+| `browser.chrome_path` | string/map | - | Chrome 可执行文件路径,可以是单个字符串或按 OS 写成 map |
+| `browser.remote_debugging_address` | string | "127.0.0.1" | Chrome 远程调试监听地址 |
+| `browser.remote_debugging_port` | integer | 9222 | Chrome 远程调试端口 |
+| `browser.user_data_dir` | string | "" | Chrome 用户数据目录,留空时使用系统默认目录 |
+| `browser.profile_directory` | string | "Default" | 要使用的 Chrome Profile 名称 |
+**按操作系统配置示例**:
```yaml
browser:
chrome_path:
@@ -138,92 +155,46 @@ browser:
profile_directory: "Default"
```
-### 5.2 .env 中的浏览器运行时配置
-`.env` 中和浏览器工具直接相关的字段主要有以下几组。
+### 5.2 .env 中浏览器配置
-#### A. 浏览器 MCP wrapper 配置
+#### 5.2.1 浏览器 MCP wrapper 配置
-```dotenv
-BROWSER_RUNTIME_MCP_ENABLED=1
-BROWSER_RUNTIME_MCP_CLIENT_TYPE=streamable-http
-BROWSER_RUNTIME_MCP_SERVER_ID=playwright_runtime_wrapper
-BROWSER_RUNTIME_MCP_SERVER_NAME=playwright-runtime-wrapper
-BROWSER_RUNTIME_MCP_SERVER_PATH=http://127.0.0.1:8940/mcp
-BROWSER_RUNTIME_MCP_TIMEOUT_S=300
-BROWSER_RUNTIME_MCP_HOST=127.0.0.1
-BROWSER_RUNTIME_MCP_PORT=8940
-BROWSER_RUNTIME_MCP_PATH=/mcp
-BROWSER_RUNTIME_MCP_COMMAND=
-BROWSER_RUNTIME_MCP_ARGS=
-BROWSER_RUNTIME_MCP_AUTO_SSE_FALLBACK=1
-```
-
-字段说明:
-
-- `BROWSER_RUNTIME_MCP_ENABLED`
- - 是否启用浏览器 MCP wrapper
- - `1` 表示启用
-- `BROWSER_RUNTIME_MCP_CLIENT_TYPE`
- - MCP client 类型
- - 当前推荐 `streamable-http`
-- `BROWSER_RUNTIME_MCP_SERVER_ID` / `BROWSER_RUNTIME_MCP_SERVER_NAME`
- - wrapper 的标识信息
-- `BROWSER_RUNTIME_MCP_SERVER_PATH`
- - wrapper 访问地址
- - `streamable-http` 模式通常为 `http://127.0.0.1:8940/mcp`
-- `BROWSER_RUNTIME_MCP_TIMEOUT_S`
- - MCP 连接或调用层的超时控制
-- `BROWSER_RUNTIME_MCP_HOST` / `BROWSER_RUNTIME_MCP_PORT` / `BROWSER_RUNTIME_MCP_PATH`
- - 本地自动拉起 wrapper 时使用的 host、port、path
-- `BROWSER_RUNTIME_MCP_COMMAND` / `BROWSER_RUNTIME_MCP_ARGS`
- - wrapper 启动命令覆盖项
- - 通常留空,使用系统默认行为即可
-- `BROWSER_RUNTIME_MCP_AUTO_SSE_FALLBACK`
- - 某些模式下是否允许 SSE fallback
-
-#### B. Playwright 官方 MCP 配置
-
-```dotenv
-PLAYWRIGHT_MCP_COMMAND=npx
-PLAYWRIGHT_MCP_ARGS=-y @playwright/mcp@latest
-PLAYWRIGHT_CDP_URL=http://127.0.0.1:9222
-```
-
-字段说明:
-
-- `PLAYWRIGHT_MCP_COMMAND`
- - 启动官方 Playwright MCP 的命令
- - 当前默认是 `npx`
-- `PLAYWRIGHT_MCP_ARGS`
- - 启动官方 Playwright MCP 的参数
-- `PLAYWRIGHT_CDP_URL`
- - 连接到已启动 Chrome 的 CDP 地址
- - 这里应与 `config.yaml` 中的调试地址和端口保持一致
+| 环境变量 | 默认值 | 说明 |
+|----------|--------|------|
+| `BROWSER_RUNTIME_MCP_ENABLED` | 1 | 是否启用浏览器 MCP wrapper |
+| `BROWSER_RUNTIME_MCP_CLIENT_TYPE` | streamable-http | MCP client 类型 |
+| `BROWSER_RUNTIME_MCP_SERVER_ID` | playwright_runtime_wrapper | wrapper 的标识信息 |
+| `BROWSER_RUNTIME_MCP_SERVER_NAME` | playwright-runtime-wrapper | wrapper 的名称 |
+| `BROWSER_RUNTIME_MCP_SERVER_PATH` | http://127.0.0.1:8940/mcp | wrapper 访问地址 |
+| `BROWSER_RUNTIME_MCP_TIMEOUT_S` | 300 | MCP 连接或调用层的超时控制 |
+| `BROWSER_RUNTIME_MCP_HOST` | 127.0.0.1 | 本地自动拉起 wrapper 时使用的 host |
+| `BROWSER_RUNTIME_MCP_PORT` | 8940 | 本地自动拉起 wrapper 时使用的 port |
+| `BROWSER_RUNTIME_MCP_PATH` | /mcp | 本地自动拉起 wrapper 时使用的 path |
+| `BROWSER_RUNTIME_MCP_COMMAND` | - | wrapper 启动命令覆盖项,通常留空 |
+| `BROWSER_RUNTIME_MCP_ARGS` | - | wrapper 启动参数覆盖项,通常留空 |
+| `BROWSER_RUNTIME_MCP_AUTO_SSE_FALLBACK` | 1 | 某些模式下是否允许 SSE fallback |
-#### C. 超时与执行策略配置
+#### 5.2.2 Playwright 官方 MCP 配置
-```dotenv
-PLAYWRIGHT_TOOL_TIMEOUT_S=300
-BROWSER_TIMEOUT_S=300
-BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
-```
+| 环境变量 | 默认值 | 说明 |
+|----------|--------|------|
+| `PLAYWRIGHT_MCP_COMMAND` | npx | 启动官方 Playwright MCP 的命令 |
+| `PLAYWRIGHT_MCP_ARGS` | -y @playwright/mcp@latest | 启动官方 Playwright MCP 的参数 |
+| `PLAYWRIGHT_CDP_URL` | http://127.0.0.1:9222 | 连接到已启动 Chrome 的 CDP 地址,应与 config.yaml 中的调试地址和端口保持一致 |
-字段说明:
+#### 5.2.3 超时与执行策略配置
-- `PLAYWRIGHT_TOOL_TIMEOUT_S`
- - 浏览器工具执行的总 watchdog 超时
-- `BROWSER_TIMEOUT_S`
- - 浏览器任务默认长超时
- - 如果模型传入的 `timeout_s` 更小,默认会被钳回至少这个值
-- `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE`
- - 是否允许模型把任务超时改得更短
- - `0` 表示不允许,推荐保持为 `0`
+| 环境变量 | 默认值 | 说明 |
+|----------|--------|------|
+| `PLAYWRIGHT_TOOL_TIMEOUT_S` | 300 | 浏览器工具执行的总 watchdog 超时 |
+| `BROWSER_TIMEOUT_S` | 300 | 浏览器任务默认长超时,如果模型传入的 timeout_s 更小,默认会被钳回至少这个值 |
+| `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE` | 0 | 是否允许模型把任务超时改得更短,推荐保持为 0 |
-### 5.3 推荐的最小后端配置
-如果你要跑当前推荐链路,至少保证下面这些字段正确:
+### 5.3 推荐最小配置
-`config/config.yaml`
+要正常使用浏览器工具,至少保证下面这些字段配置正确:
+**config/config.yaml**
```yaml
browser:
chrome_path: "C:\\Users\\YOUR_USER\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
@@ -233,8 +204,7 @@ browser:
profile_directory: "Default"
```
-`.env`
-
+**.env**
```dotenv
BROWSER_RUNTIME_MCP_ENABLED=1
BROWSER_RUNTIME_MCP_CLIENT_TYPE=streamable-http
@@ -247,39 +217,36 @@ BROWSER_TIMEOUT_S=300
BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
```
-## 6. 使用建议
-为了让浏览器工具更稳定,建议遵循以下做法:
+## 6. 原理与代码架构
-- 尽量使用本机真实安装的 Chrome,而不是临时浏览器。
-- 启动浏览器服务后,优先在弹出的 Chrome 中完成登录和授权。
-- 对于长流程任务,尽量保持同一个会话,避免频繁更换浏览器状态。
-- 如果任务涉及邮箱、企业系统、网银等场景,建议先人工完成一次登录,再交给 Agent 继续操作。
-- 如果浏览器状态异常,可以重新启动浏览器服务后再测试。
-- 建议让 `PLAYWRIGHT_CDP_URL` 与 `config.yaml` 中的远程调试地址、端口保持一致。
-- 建议保持 `BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0`,避免模型把浏览器任务拆成过多短调用。
+### 6.1 技术架构
+
+当前浏览器工具的核心链路如下:
-## 7. 相关代码与配置索引
-下面这些文件是浏览器工具链路中最重要的入口。
+- **前端页面**:提供「浏览器服务」面板,用于配置 Chrome 可执行文件路径并启动浏览器服务
+- **后端应用**:通过 `browser_start_client.py` 启动本机 Chrome,并开启远程调试能力
+- **浏览器运行时**:基于 Playwright MCP 封装,浏览器工具通过 MCP client 与运行时通信
+- **Agent 调用**:Agent 调用 `browser_run_task` 等工具时,运行时会把自然语言任务转换为浏览器操作步骤
+- **会话管理**:浏览器会按 `session_id` 复用,同一会话下可以保持登录态、页面上下文和授权状态
+
+可以简单理解为:
-### 前端
-- `jiuwenswarm/channels/web/frontend/src/components/BrowserPanel/index.tsx`
- - 前端浏览器服务面板
- - 负责读取路径、保存路径、触发“启动浏览器服务”
+`前端配置 → 启动 Chrome → 运行时接管 Chrome → Agent 在需要时操控浏览器执行任务`
-### 后端应用入口
-- `app.py`
- - 提供 `path.get`、`path.set`、`browser.start` 等前端调用入口
+### 6.2 核心代码
-### Chrome 启动脚本
+浏览器工具的核心代码主要分布在以下模块:
+
+#### Chrome 启动脚本
- `jiuwenswarm/agentserver/tools/browser_start_client.py`
- 读取 `config/config.yaml` 中的 `browser.*` 配置
- 启动带远程调试能力的 Chrome
-### 浏览器 MCP 接入
+#### 浏览器 MCP 接入
- `jiuwenswarm/agentserver/tools/browser_tools.py`
- 浏览器 MCP wrapper 的接入、自动拉起、client patch、配置构建
-### 浏览器运行时
+#### 浏览器运行时
- `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime_mcp_server.py`
- 浏览器 runtime 的 MCP server 入口
- `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime/runtime.py`
@@ -291,13 +258,22 @@ BROWSER_ALLOW_SHORT_TIMEOUT_OVERRIDE=0
- `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime/config.py`
- Playwright MCP 与浏览器运行时配置解析
-### 配置文件
-- `config/config.yaml`
- - Chrome 启动参数
-- `.env`
- - 浏览器 runtime、MCP、Playwright、超时等环境变量
-- `.env.template`
- - 环境变量模板
+- **工具管理模块**:`jiuwenswarm/agents/harness/common/tools/` 是系统管理所有工具的底层模块,浏览器相关工具主要在此模块下实现
+- **前端界面模块**:`jiuwenswarm/channels/web/frontend/` 负责用户界面交互
+
+具体文件说明:
+
+| 模块 | 文件路径 | 功能说明 |
+|------|----------|----------|
+| 前端浏览器服务面板 | `jiuwenswarm/channels/web/frontend/src/components/BrowserPanel/index.tsx` | 负责读取路径、保存路径、触发「启动浏览器服务」 |
+| 后端应用入口 | `app.py` | 提供 `path.get`、`path.set`、`browser.start` 等前端调用入口 |
+| Chrome 启动脚本 | `jiuwenswarm/agentserver/tools/browser_start_client.py` | 读取 `config/config.yaml` 中的 `browser.*` 配置,启动带远程调试能力的 Chrome |
+| 浏览器 MCP 接入 | `jiuwenswarm/agentserver/tools/browser_tools.py` | 浏览器 MCP wrapper 的接入、自动拉起、client patch、配置构建 |
+| 浏览器运行时 MCP 服务 | `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime_mcp_server.py` | 浏览器 runtime 的 MCP server 入口 |
+| 浏览器运行时编排层 | `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime/runtime.py` | 浏览器 runtime 编排层 |
+| 浏览器任务执行 | `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime/service.py` | 浏览器任务执行、session 复用、timeout guardrails |
+| 浏览器运行时配置 | `jiuwenswarm/agentserver/tools/browser-move/src/playwright_runtime/config.py` | Playwright MCP 与浏览器运行时配置解析 |
+
+## 7. 一句话总结
-## 8. 一句话总结
-浏览器工具的本质,是让 Agent 在用户已经授权过的真实 Chrome 上执行网页操作;前端负责配置和启动,后端负责接管和自动化执行。
+浏览器工具的本质,是让 Agent 在用户已经授权过的真实 Chrome 上执行网页操作;前端负责配置和启动,后端负责接管和自动化执行。
\ No newline at end of file