Computer Use Agents: How LLMs Learn to Operate a PC in Practice

    This article explains how large language models move beyond function calling to operate a full computer through screenshots, mouse, and keyboard. It breaks down the perception-decision-execution loop, the sandbox architecture and security boundaries required for deployment, a four-dimension evaluation framework with common failure modes, and the cost model with practical optimization techniques. It also offers guidance on suitable use cases and how to decide between computer use and traditional function calling.

    1. The Shift from Purpose-Built Tools to General-Purpose Operation

    Over the past two years, the mainstream approach to giving large language models external capabilities has been function calling: developers define a set of structured interfaces in advance, the model outputs parameters, and a host program executes the call and returns the result. This approach is controllable and stable, but it has an inherent ceiling—the capability boundary is limited to whatever developers enumerate ahead of time. When facing a legacy system that has no API and only a graphical interface, it is stuck.

    The newer approach moves the level of abstraction up. Instead of building a custom tool for every task, it treats the entire computer as a perceivable and controllable environment, letting the model use the keyboard, mouse, screen, and applications designed for humans. The essence is still tool calling; what changes is that the tool set goes from a handful of functions to atomic actions at the operating system level.

    This shift has two direct consequences. First, coverage expands dramatically—in theory, any software a human can operate can be driven. Second, uncertainty expands dramatically—pixel-level actions lack type constraints, so errors accumulate. Understanding this tension is the prerequisite for evaluating such capabilities.

    2. How It Works: The Perception-Decision-Execution Loop

    2.1 Environment Perception

    The host program periodically captures desktop images and sends them to the model as context, together with the UI element tree when it can be obtained. Visual input lets the model locate buttons, input fields, and menus, while the element tree provides precise coordinates for clickable targets. The two are complementary and can significantly reduce misclicks.

    2.2 Decision and Action Space

    The model outputs structured action instructions. A typical action set includes: move pointer, left click, right click, double click, drag, keyboard input, key combination, scroll, wait, and return screenshot. The finer the action granularity, the better the controllability, but the more inference rounds are required.

    2.3 Execution and Feedback

    On the host side, instructions are parsed and executed on a virtual desktop, and a new screenshot is sent back, closing the loop. A schematic loop skeleton looks like this:

    1. while not finished:
    2. screenshot = capture_desktop()
    3. action = model.act(screenshot, goal, history)
    4. if action.type == "left_click":
    5. click(action.x, action.y)
    6. elif action.type == "type":
    7. keyboard.write(action.text)
    8. elif action.type == "key":
    9. keyboard.press(action.key)
    10. elif action.type == "screenshot":
    11. continue
    12. else:
    13. finished = True

    2.4 Context Management

    Screenshots are heavy consumers of image tokens, so a strategy is needed in practice: keep only the most recent few frames, compress historical frames to low resolution, and distill confirmed facts into text summaries. This is both a cost control measure and a key factor in maintaining success rates on long tasks.

    3. Deployment Architecture and Security Boundaries

    Because the model can click anywhere on the desktop, isolation is a hard requirement, not an option. A common reference architecture in the industry has four layers:

    • Sandbox layer: a container hosts a full desktop and virtual display, isolated from the host file system and network;
    • Protocol layer: a remote desktop protocol exposes the screen and input channels, making it easy for humans to observe and take over at any time;
    • Orchestration layer: handles session management, task timeouts, failure retries, and action audit logs;
    • Control layer: sets human confirmation gates for high-risk actions (deletion, payment, sending email, changing permissions).

    It should be clear that prompt injection risk is amplified in such systems: any text on a web page or in a document may be treated as an instruction by the model. Therefore, “untrusted content must not change the established goal” should be written into the orchestration layer as a system-level constraint, rather than relying on the model’s own judgment.

    4. Evaluation: Four Metrics and Common Failure Modes

    Evaluation should not stop at the demo level of “looks impressive.” A four-dimension set of metrics is recommended:

    1. Task success rate: measured in layers by task type, distinguishing form filling, information retrieval, cross-application transfer, and so on;
    2. Steps and rounds: reflects efficiency and directly determines cost;
    3. Recovery capability: whether it can self-correct when encountering pop-ups, loading failures, or layout changes;
    4. Safety and compliance rate: whether unauthorized actions and sensitive operations are effectively intercepted.

    High-frequency failure modes include: coordinate positioning drift, loss of target after scrolling, goal drift on long tasks, timing races on dynamic pages, and strong human-machine boundaries such as CAPTCHAs and two-factor authentication. The engineering responses are, respectively: introduce element-tree assistance for positioning, re-capture and recalibrate at every step, restate the goal periodically, use explicit waits for state stability, and hand strong authentication steps back to humans.

    5. Cost Model and Optimization

    Cost has three components: image input tokens per round, accumulated conversation history, and extra rounds from failure retries. Because per-round cost grows roughly linearly with task length, the bill for long tasks often exceeds expectations.

    Available optimization directions:

    • Image side: lower screenshot resolution and frame rate, and capture frames only after actions;
    • Context side: sliding window plus text-based history summaries;
    • Process side: write deterministic scripts for high-frequency fixed flows, and hand only exceptions to the model;
    • Model side: use a smaller-parameter model for simple steps, and escalate to a larger-parameter model for complex decisions;
    • Cache side: short-term caching of repeated UI element recognition results.

    For deployment, container platforms handle elastic scaling of sandboxes, object storage keeps audit screenshots, logging services and monitoring alerts track success rates and token consumption, and message queues handle peak shaving and asynchronous task queuing. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the underlying components for building such a system.

    6. Suitable Use Cases and Selection Advice

    At this stage, it is better suited to “low-risk, rollback-friendly, stable-interface” scenarios: internal system data transfer, batch form entry, UI inspection in test regression, and cross-system report consolidation. It is not suitable for direct use in fund operations, production configuration changes, or batch processing involving personal privacy.

    For selection, it is advisable to start with a small-scale feasibility validation: pick twenty to fifty real tasks, establish a baseline success rate and cost per task, and then decide whether to expand the scope. If an enterprise already has many legacy systems lacking APIs, the marginal value of this general operation capability is highest; conversely, if the target systems have complete interfaces, traditional function calling is still the more stable and cheaper choice.

    7. Conclusion

    Letting models operate computers marks a shift in tool use from “interface enumeration” to “environment interaction.” Its value lies in connecting legacy systems without APIs, at the cost of introducing pixel-level uncertainty and a new security surface. The rational path to adoption is: sandbox first, human in the loop, metrics-driven, and cost-controlled.