From Static to Dynamic: How AI Agents Generate Their Own Tools

    Computer-use agents often waste enormous effort on tasks a single script could finish, because their interfaces are fixed before deployment. This article explains why preset toolsets conflict with open-ended tasks, why test-time compute scaling and skill reuse only raise the ceiling so far, and how agents that write and register their own tools at runtime break through that limit. It includes a pseudocode comparison, plus the cloud-native sandboxing, permission control, and tool persistence practices needed to run self-generated code safely.

    The Tool Bottleneck of Computer-Use Agents

    Have you ever considered that an AI agent capable of operating a computer might, when handed a spreadsheet with thousands of rows, complete the job in the clumsiest way possible: clicking into one cell, typing, clicking the next cell, and repeating — even though a single Python script would finish the whole thing instantly.

    This is not a far-fetched scenario. It is something developers see repeatedly when observing how computer-use agents (CUAs) actually work. CUAs are AI systems that operate a computer much like a human does: they capture screenshots, simulate mouse clicks and keyboard input, and complete tasks such as booking flights, organizing files, or handling email. As task complexity grows, however, their execution efficiency tends to become a serious problem.

    The code-handling case is even more striking. Suppose you ask an agent to find the implementation of a specific function in a 2,000-line file. It may choose to print the entire file to the terminal and then “look” at it line by line through a vision model, instead of running a single text search command to locate it directly. This clumsiness is not because the underlying large language model lacks intelligence; it is because the tools the agent has been given leave it no smarter option.

    Preset Toolsets vs. Open-Ended Tasks

    Most mainstream computer-use agents follow the same technical route. Before deployment, human engineers sit down and design a fixed interaction interface. That interface typically consists of screenshot parsing, mouse and keyboard event control, and a handful of purpose-written tool functions. Once written and frozen, it becomes the “hands and feet” the agent uses for its entire lifetime.

    The problem is that this interface is guessed at by engineers based on experience — a guess about what operations the agent will need in different scenarios. But tasks in the computing world are highly open-ended. New applications, new workflows, and new file formats appear constantly, and every change in the environment can make a previously well-designed interface look clumsy and outdated.

    Terminal operation is a typical example. When an agent wants to use the command line, the logical approach is to invoke the system’s underlying shell execution environment directly and read standard output. In many existing systems, however, it must first click to open a terminal window using coordinates, then type the command one character at a time, and finally take a screenshot to check whether the command succeeded — often through a terminal window half-obscured by a scrollbar or a popup. It is like requiring a skilled driver to stop the car, pull out the manual to confirm the clutch position, and then carefully operate it every time they shift gears. The problem is not that they cannot drive; the vehicle has simply been stripped of its intuitive controls, forcing them through the most tedious process.

    Why Existing Workarounds Hit a Ceiling

    Researchers and engineers have tried several remedies for these problems, and each has clear limitations.

    1. Stacking test-time compute
    One common approach is to throw compute at the problem: let the model try more times during inference and sample several candidate execution plans, using extra reasoning compute to compensate for interface design flaws. This can raise task success rates to some degree, but the gains are limited. It wastes substantial compute resources and is fragile, breaking down on slightly complex multi-step tasks.

    2. Experience reuse and skill accumulation
    Another approach has the agent distill successful test-time experience into reusable “skills” or routines — for example, learning the fixed sequence “open browser - enter URL - click download.” But these skills are ultimately linear combinations built on top of the existing observation and action sets; they do not genuinely expand what the interface can do. If the underlying system offers no ability to read a file’s binary stream, no combination of “mouse click” and “keyboard input” will let the agent parse data efficiently.

    The Way Forward: Agents That Generate Their Own Tools

    The root of the problem is that interface design should not be a static artifact decided once by humans before deployment and then locked forever. It should evolve dynamically with the task, much like software itself. This is the core idea behind AI agents writing their own tools.

    An agent with this capability is no longer confined to preset atomic operations. At runtime, it can write code on demand, generate new tool functions, and add them to its own tool library. This shift from static tool invocation to dynamic tool generation greatly expands the agent’s capability boundary.

    Implementation path and pseudocode

    Realizing this mechanism requires the agent to be able to reflect on itself, generate code, execute it in a sandbox, and register tools. The following is a conceptual pseudocode comparison.

    Traditional static tool invocation (inefficient):

    1. # Traditional approach: rely on mouse and keyboard simulation to fill a spreadsheet
    2. agent.move_mouse(x=120, y=300) # click the first cell
    3. agent.type_text("Data")
    4. agent.press_key("Enter")
    5. agent.move_mouse(x=120, y=320) # click the next cell
    6. # ... repeated thousands of times, slow and error-prone

    Self-generated tool approach (efficient):

    1. # Evolved approach: the agent analyzes the task, then writes and registers a new tool
    2. new_tool_code = """
    3. def batch_fill_excel(file_path, data_dict):
    4. import openpyxl
    5. wb = openpyxl.load_workbook(file_path)
    6. ws = wb.active
    7. for cell, value in data_dict.items():
    8. ws[cell] = value
    9. wb.save(file_path)
    10. return "Success"
    11. """
    12. # The agent executes the code in a sandbox to verify it, then registers it as a tool
    13. agent.register_tool("batch_fill_excel", new_tool_code)
    14. # Afterwards, the new tool is called directly to complete the task
    15. result = agent.call_tool("batch_fill_excel", {"file_path": "data.xlsx", "data_dict": {"A1": "Data"}})

    This way, the agent moves beyond the surface appearance of “simulating human operations” and reaches the computer’s underlying programming capability directly, delivering an exponential gain in efficiency.

    Engineering Practice and Challenges in a Cloud-Native Environment

    Letting an AI agent write and execute code is promising, but it poses serious security and engineering challenges in real deployments. Self-generated tools must run in a controlled environment so they cannot damage the host system, which makes mature cloud-native capabilities especially relevant.

    In a practical architecture, container platforms and function-compute services such as those offered by Baidu AI Cloud can provide a securely isolated code execution environment. Each time the agent generates new tool code, it can be packaged as a microservice or container instance running in an isolated sandbox namespace, with strict RBAC permission controls and network isolation policies that prevent unauthorized access to the host file system and external networks.

    Generated tools also need to be persisted and managed. Object storage can hold the generated tool scripts and dependency configurations, while a relational or graph database can record tool metadata such as applicable scenarios, invocation parameters, and success rates. When the agent encounters a similar task again, it can retrieve and reuse the tool from its library, forming a virtuous loop of “discover a problem - write a tool - accumulate capability.”

    Summary

    An AI agent’s capability should not be boxed in by an interaction interface that humans preset in advance. Moving from static “simulated operations” to dynamic “self-written tools” is an inevitable direction for computer-use agents. Agents with this self-evolving ability can solve concrete tasks in the most efficient way, through code, while steadily enriching their own tool ecosystem over continued operation. As large models’ code generation ability strengthens and cloud-native sandbox technology matures, we can expect general-purpose assistants that think and work much like senior developers.