How AI Agents Really Operate Your Desktop and Browser
Background: From RPA to Agent
RPA: Turning repetitive operations into automated flows
Downloading reports from a website, opening Excel to tidy them up, then pasting the results into another system. Each step alone is simple, but doing it daily - finding the entry point, switching windows, copy-pasting - gets tedious.
For a long time, people have wanted software to handle this kind of repetitive manual work. RPA (Robotic Process Automation) essentially encodes these operations into a workflow that a program follows. Filling forms, reading files, choosing next steps based on conditions, even retrying after errors - all can be scripted.
For tasks with clear steps and stable rules, this works well: once the workflow is defined, it can run repeatedly without a human clicking through each time.
Challenge: Workflows need design and maintenance
But someone has to design the workflow. What if the file isn't found? What if several results share the same name? What if a dialog box pops up unexpectedly? These cases all need to be handled in advance.
Unexpected situations or UI changes may require adding rules or modifying the workflow. Repetitive operations can be delegated to software, but maintaining the workflow still needs humans.
Agent: Handing some judgment to the model
Large models offer a new idea: what if we just tell it the goal and let it watch the interface while deciding the next step? This removes the need to pre-arrange a complete workflow for each task. The model can reason in real time from what it currently sees and adjust when things change.
For example, to find a meeting note, it might search by name, see several versions, then pick the right one based on date and content. The underlying actions - search, click, type - remain tools, while some judgment is handled on the fly by the model.
Such systems, which call tools toward a goal and continue based on results, are commonly called agents. Agents like Codex have already made computer and browser operation a usable feature. Users say what they want, and the agent tries to connect the intermediate actions.
For operating software, two names often come up:
- Computer Use: letting the agent use software on the computer; we'll use Word save-as-PDF as an example.
- Browser Use: letting the agent operate the browser; we'll use searching for a file in a cloud drive as an example.
The browser is also software, so the two overlap. They're separated here because the browser offers dedicated ways to manipulate web pages. Let's break down these capabilities: how does the model know what's on the interface, and who turns its decisions into actual clicks?
二、整体机制:模型与工具怎样配合
分工:模型做判断,工具来执行
The model can decide that "next, click Save," but for Word to actually respond, a program must carry out that action. One part makes decisions, another acts - these two responsibilities are separated.
The program that reads the interface and performs clicks and input is called the executor here. Together, these physical capabilities form the execution layer. The model decides the next step based on returned information, then sends new operation requests to the executor.
The model issues requests through tools, and the executor touches the software via system or browser interfaces. "Interface" here means the operation entry points software exposes to other programs. The relationship looks like this:
Overall relationship, arrows indicate who calls whom, results return along the same path.
With an executor in place, the model still needs to know how to use it. Things like which command to take a screenshot, whether to pass a position or a control name like button or input box, and what the execution returns. This can be written into a Skill, which is like a tool manual for the model.
When actually issuing operations, you can go through the CLI, the command-line interface. The model organizes commands per the manual, the CLI passes them to the executor, and brings back results.
Flow: look at the interface, act, check results
Using Word's Save As window as an example:
- Read the interface: the executor hands the current screen or control information to the model.
- Decide and act: the model finds the "Save As" entry and asks the tool to click.
- Read the result: if the save window appears, continue filling in the filename; if other prompts appear, handle those first.
This way, the model doesn't need to guess all later steps up front. It performs the action it's confident about now, then continues with new results. If filling the filename and clicking Save are both clear, they can be done together without re-reasoning after each keystroke.
However, a tool reporting "click succeeded" only means the button operation executed. Our goal is a PDF, so we still need to confirm the file was created and its content is correct. That check is also part of the task.
Orchestration: Chaining continuous actions with scripts
Back to the Word save-as-PDF example. Assume the model has opened the save window, confirmed the format is PDF, and next must fill in the filename, click Save, and check the result. Since these steps are clear, can we hand them to a program all at once?
One approach is to write the actions as a JavaScript (JS) script and run it in a JS execution environment. That environment executes code, processes data, arranges call order, and then has the executor interact with the UI through its interface. The earlier tool capabilities get chained together by the script.
The script execution environment handles computation, data processing, and call ordering; the executor still performs the actual UI actions.
For example, the current document name is "meeting_notes.docx". The script below derives "meeting_notes.pdf", fills it into the save box, then computes the button center and clicks. The ui in the code is a simplified interface for the executor, not tied to any product SDK.
// JS pseudocode: ui is a simplified interface provided by the executor, not a product SDK.
// Assumption: the model has opened the Save As window and confirmed the format is PDF.
async function savePdf(ui) {
// 1. Read the current window and turn the document name into a PDF filename.
const dialog = await ui.readSaveDialog();
const name = dialog.documentName.replace(/\.[^.]+$/, "");
const pdfName = `${name}.pdf`;
await ui.fill(dialog.windowId, "filename", pdfName);
// 2. Re-read the button position after filling, then compute the center coordinates.
const button = await ui.readButton(dialog.windowId, "Save");
if (!button.enabled) {
throw new Error("Save button disabled; need to re-check the interface");
}
const x = button.left + button.width / 2;
const y = button.top + button.height / 2;
// 3. Click and wait for the actual save result, then hand back to the model.
await ui.click(dialog.windowId, { x, y });
return await ui.waitForSavedFile(pdfName);
}
Looking at this example, you can distinguish three kinds of work in the script:
- Data handling: takes the document name from the previous step, strips the old extension, and passes the new filename to the fill operation.
- Computation: works out the center from the button's actual position and size, so the model doesn't have to pre-calculate and then send a click request.
- Step orchestration: completes read, fill, click, and wait in code order. If the button is disabled, the script can stop and hand the problem back to the model.
When the model writes the confirmed steps, the program can execute continuously, saving the back-and-forth of reporting each step and waiting for the next model instruction. The await in code means wait for this step to finish before continuing; actual waits like window opening and file saving still exist.
If an unexpected dialog appears, or if several file contents need to be reviewed before choosing one, the new observation must go back to the model. Scripts suit known action chains; the model continues to handle situations that need re-interpretation.
State: Remembering the window being operated on
Last turn opened Word's save window; this turn says "click Save". How does the tool know which window to click? Two approaches exist:
The tool can keep the connection and target used for this task in a session. Session state is that saved information. The second approach in the table remembers "currently selected window" so later requests can omit it.
The browser works the same way: the executor can remember which tab is currently selected. Saying "click search" later looks in that page. But remembering the target isn't the same as knowing the latest screen. If the user closes the window or the page navigates, old information may be stale and needs re-reading. The appendix expands on the difference between session and application state.
三、Computer Use:怎样操作桌面应用
架构:借助操作系统接口
Continuing with Word save-as-PDF. A person usually opens the Save As window, selects PDF, checks filename and location, then clicks Save. The agent needs to do the same steps.
To have a program do these, we need to see what the OS provides. The system can capture window screens, provide control information like buttons and input boxes, and let programs simulate keyboard and mouse. The executor reads and operates them through system interfaces.
Desktop architecture, three connections correspond to different system capabilities; the executor can choose as needed.
Screenshots are easy to understand: capture the window and give it to a vision-capable model to decide where the filename field is and where the Save button is. The accessibility interface on the left provides another way of "seeing".
Observation: Screen and control information
Besides the screen, a program can be told directly: "There is an input box named 'filename' with the content 'meeting_notes.pdf'; next to it is a Save button, currently clickable." The OS's Accessibility Interface provides this kind of information.
It was originally built to help assistive software like screen readers understand the UI. Even if a user can't see the screen, assistive software needs to know which controls exist, what they're called, and their current state. Applications supply this info to the system, and other programs read it through the interface.
Windows contain panels, panels contain input boxes and buttons; this information forms an accessibility tree. Automation programs can use it too.
Two views of the same save window, interface simplified, assuming PDF format selected.
With this info, the tool can tell the model "the Save button is currently enabled" without guessing from a screenshot whether it's gray. Control names, values, and states are provided by the application, organized into a text list for the model.
Therefore, a text-only LLM can also use this list to decide the next step. To read screenshots directly, the model needs vision capabilities or other image-processing tools. This is why accessibility info is well-suited for reuse by agents.
Each view has its strengths:
Back to Word's save window: we mainly care about what's in the filename field and whether Save is clickable. For standard forms like this, reading control info first and supplementing with a screenshot when needed is practical, saving the effort of recognizing controls from an image.
But if the task is "check this page's layout for problems," button names don't help much; looking at the image directly is better. So the choice of observation depends on the task; some implementations are vision-first from the start.
Text isn't always cheaper. Stuffing a huge control tree into the model increases input size and latency. Efficiency depends on how much info is returned and how many retries after misjudgments, not just text vs. image.
Execution: Making the application respond
Now that the model knows where the Save button is, the most straightforward implementation is: move the mouse there, press left, release.
A program can call system input interfaces to simulate these actions. For an input box, it's similar: click to focus, then simulate keystrokes. These manual actions are broken into a set of program calls.
With the accessibility interface, another path exists: if the application supports it, the program can directly trigger the Save button's functionality without moving the mouse pointer.
Two execution approaches; the right side requires the control to support the corresponding action.
Finding the button and clicking it are two different things. For example, you can locate the Save button from accessibility info, then take its position and simulate a mouse click.
The on-screen mouse cursor doesn't have to move either. Some executors hand simulated actions directly to the target application; some products additionally draw a mouse icon with animation to show where the agent is acting. Codex is an example.
Drawing a mouse animation is mainly for users to see where the agent is acting. It can be handled separately from the real click; details in the appendix.
Implementation: Reusing desktop automation libraries
Screenshots, keyboard and mouse operations don't need to be written from scratch against OS interfaces. Existing open-source automation components, "libraries", already do much of that work.
PyAutoGUI can take screenshots, move the mouse, click, and type. We can write a small script that exposes these operations as commands, and then use a Skill to explain how to call them.
With Claude Code as an example, the components can be wired like this:
One scheme for wiring Claude Code to PyAutoGUI; a connection script must be written, dashed lines indicate reading references or screenshots.
During actual execution, they cooperate in this order:
- Claude Code runs a screenshot command and reads the generated image.
- The model looks at the image, decides the target position, and calls the click command.
- Take a new screenshot to confirm interface changes, then decide the next step.
This scheme mainly uses screenshots for positioning. PyAutoGUI handles screenshots and key/mouse operations; it doesn't understand "save this document as PDF" and doesn't provide a generic accessibility-tree reader. To read system controls, tools like pywinauto on Windows are available.
Integration: Ready-made desktop operation solutions
The previous examples are for understanding implementation. If you just want to add desktop operation capability to your agent, connection scripts and command interfaces have already been built.
Such solutions can be integrated via the CLI described earlier, or via MCP, a generic way for agents to connect external tools. The two open-source projects below both provide such entry points:
They fill in the agent's ability to use the desktop; goal understanding and subsequent judgment still belong to the agent. When choosing, look at OS, application support, and input method, not just the presence of a "click" command.
四、Browser Use:怎样操作浏览器
架构:借助浏览器接口
Desktop tools can operate Word, so they can obviously treat Chrome as a normal application too: screenshot, locate, click. Following that path handles many web tasks.
But the browser maintains the internal structure of web pages, knows which elements are input boxes and which are buttons, and provides dedicated control interfaces. Connecting directly to these lets you select tabs, read page structure, and act on elements without always starting from screen coordinates. This is the dedicated Browser Use path.
Browser architecture: the executor connects directly to the browser and operates a specified tab.
This time we'll use a cloud-drive task: search for "meeting notes", find the right PDF, and open it. The agent needs to identify the search box, type keywords, wait for the list, then select a file based on name and date.
Observation: Screen and web page structure
The browser organizes text, input boxes, buttons, etc., into a tree, recording their types, attributes, and relationships. This structure is the DOM, the Document Object Model; tools can search it for elements.
The browser also provides accessibility info describing how elements are used by people: button or input, name, current interactability. The relationship between the two structures and the rendered page can be viewed together:
Three views of the same web page; the middle uses HTML to illustrate the DOM structure; text and buttons align with the left rendering.
With this info, the executor can find the input box by "filename" and the button by "search". If the page only moves the button, these attributes stay unchanged, so the tool may still find it; relying on old coordinates risks mis-clicks.
Scanned documents, charts, etc., may still need images. Reuse the earlier trade-off: read control info when it suffices; use images when appearance and content matter.
The browser also exposes page accessibility info to the OS, so desktop tools can read web controls too. But the dedicated browser path can directly use DOM, tab management, and file upload interfaces, saving some UI operations.
Execution: Making the web page respond
Using the cloud-drive search for "meeting notes" as an example, the division between model and executor is:
There are two different kinds of judgment here. If the list hasn't loaded yet, the executor can wait; no need to make the model guess against a blank page. Once several same-named files appear, only then does the model need to judge by date, name, and content.
Clicking follows the desktop idea: the tool finds an element, computes its position, and sends mouse down/up via browser interfaces. These actions go to the specified page directly and don't necessarily move your physical pointer.
Implementation: Reusing browser automation libraries
Element locating, filling, and clicking don't need to be built from scratch. Playwright is a ready-made browser automation library, common in web testing, and can serve as an agent execution layer. Like PyAutoGUI on the desktop, put it back in the full chain:
Playwright handles browser operations; the connection script wires these capabilities to the agent; bidirectional arrows indicate calls and result returns.
The earlier search operation in Playwright calls looks like:
// page represents the connected cloud-drive page; control names match the earlier diagram.
// Find the input box and fill in the keyword.
await page.getByLabel("filename", { exact: true }).fill("meeting notes");
// Find the search button and click.
await page.getByRole("button", { name: "search", exact: true }).click();
The "click" in the code also waits for the button to be visible, enabled, and clickable, and reports failure on timeout. As for when search results finish loading and which content to send back to the model, the connection script still has to handle per-page conditions.
Wrapping such calls as commands or tools the agent can use is one integration approach. The ready-made solutions below have already done this wiring.
Integration: Ready-made browser operation solutions
Tools already encapsulated for agents handle command entry, page observation results, and session continuity in addition to browser operations. Two open-source options:
Here browser-use specifically refers to the open-source project of the same name. Both it and Playwright CLI can be called by existing agents like Claude Code or pi, saving you from writing connection scripts.
Browser extensions: Connecting to existing tabs
In practice, users are often already logged in and have the page they want open. We want the agent to work there; switching to another browser environment might require re-login and re-finding pages.
A browser extension offers a way to attach to an existing browser. It's a small program installed in the browser, commonly called a plugin. With it, an external control program can reach tabs already open in the browser.
Taking Codex connecting to Chrome as an example, the local browser service receives commands, keeps connections, and through the extension attaches to the target tab. A "service" here is a program running in the background on the machine, continuously accepting requests:
Extension attachment diagram, omitting message forwarding details between local components.
The extension uses Chrome's interfaces to push commands like reading the page and clicking, then sends results back. The Chrome prompt "has started debugging this browser" is related to this control channel. Specific protocol is in the appendix.
Extensions can also work with automation libraries. For example, Playwright has a way to connect to an existing browser via an extension: the library provides operation capabilities, the extension attaches to the target page inside the browser.
五、总结
From RPA to Agent, the basic actions of screenshot, click, and input haven't suddenly become black magic. With models in the loop, they decide the next step based on the goal and current observation, then borrow existing tools to carry out the action.
- Reading the UI can reuse software-provided info. When the system already exposes control info, the agent doesn't always need to recognize buttons from screenshots.
- Acting can call control interfaces directly. Browsers accept control commands directly, so pages respond to clicks without moving the user's physical mouse.
- Finishing a task still requires checking results. If the app doesn't provide complete control info, the model may misread; if a window moves, old coordinates can miss. Chaining steps, catching wrong results, and adjusting are the real core of this approach.
Real tasks need not stick to one method. If a programmatic interface can finish the job directly, call it; use browser tools in web pages and desktop abilities for native windows. The goal is to get things done, not to emulate human operations unnecessarily.
六、附录
Browser connection and background service
"Has a background service" and "has a browser extension" both sound like they work in the background for the agent, but they may be in different places. Taking Playwright CLI's extension connection mode as an example, separate the components inside and outside the browser:
Component relationships in Playwright CLI extension mode. The background process sits outside the browser, the extension inside. Results return along the connection.
Outside the browser, a background process holds the connection. It receives CLI commands and saves sessions. Once a command finishes, the CLI can exit, but the background process keeps the connection for later commands. Such background processes are usually called daemons.
Inside the browser, the extension attaches to the target tab. It uses chrome.debugger to speak CDP (Chrome DevTools Protocol), feeding control commands like reading the page and mouse clicks into the browser, then passes results back.
The extension has its own background script, but it's still inside Chrome, managed by the browser. The daemon outside and the extension's background script are two different programs.
Under Manifest V3, the extension background script runs as a Service Worker and may be terminated when idle; active connections affect how long it can run. Connecting to the browser doesn't always need an extension. A normal Playwright library can launch Chromium and establish a control connection over a pipe. Using a library call, a separate background process, or an extension depends on the runtime setup.
Control info and OCR: what's the difference
The accessibility interface returns data like control type, name, value, and hierarchy. The executor can organize this into structured text like a text tree or JSON. Playwright MCP uses control info from the current page to provide browser tools for the agent, without needing the model to recognize screenshots first.
This differs from OCR, which extracts text from images. OCR can recognize the characters "Save", but still doesn't know whether it's a button or whether it's clickable. The DOM describes element structure, accessibility info describes how controls are used, and OCR extracts text from images. These three provide different information.
Mouse animation and input focus
When using the mouse manually, onlookers can follow the pointer to see what you clicked. But an agent may deliver clicks directly to the application without moving the system mouse. The interface changes, yet humans may not know what happened.
Drawing a separate mouse pointer that moves along with operations displays the process. This animation is a visual cue for humans to see where the agent is clicking; the actual click is still done through input interfaces.
In the two earlier cases, display and input are handled separately:
- The Chrome page case: the extension overlays a layer on the page to draw the pointer; clicks are sent via CDP.
- The desktop app case: a separate transparent window can show the animation, while a local program delivers simulated actions to the target application.
Display can be separate, but keyboard input still needs a recipient. Which window or input box receives text is decided by input focus. This is separate from how many mouse pointers are drawn on screen.
When we click a window manually, the window comes to front and the input box gets focus, often together. Automation programs may handle these states separately. So two mouse pointers not following each other doesn't necessarily mean human and agent operations are interference-free; it depends on the application and input method.
Session state and software state
The session mentioned in the main text can save connection and current operation target. Different tasks need to distinguish their targets to avoid sharing a single "current tab" and clicking the wrong page. Even if every request explicitly carries the target, the browser itself still holds form and login state.
These states live in different places:
Re-selecting a tab does not automatically restore previous form input; clearing a tool session does not log you out of a website. Even if the screen shows two mouse pointers, humans and agents may still be editing the same document or input box.
七、参考资料
- UiPath: Creating RPA workflows
- Chromium: Accessibility tree and system interfaces
- Claude Code: Using Skill to describe tool usage
- Chrome extensions: Development guide and API docs
- PyAutoGUI: Desktop screenshot and key/mouse automation
- pywinauto: Windows control automation primer
- Peekaboo: macOS desktop observation and operation tool
- Cua Driver: Desktop control CLI and MCP integration
- Playwright: Browser automation, CLI and MCP docs
- browser-use: Browser operation CLI and open-source project
往期回顾
- From dev experience to team knowledge: Akashic knowledge engineering practice | Dewu Tech
- Stress-testing AI Agent governance and evaluation tuning practice
- Three reversals in multi-agent architecture: from centralized dispatch to self-driven collaboration | Dewu Tech
- Jev in practice: introducing a lightweight decision layer for AI workflows, 10x speedup | Dewu Tech
- Domestic compute · Ascend 910C LLM inference optimization (part 2): source modification and operator tuning, 30% speedup | Dewu Tech
文 /羊羽
关注得物技术,每周四更新技术干货
要是觉得文章对你有帮助的话,欢迎评论转发点赞~
未经得物技术许可严禁转载,否则依法追究法律责任。