AI Agent Development in Practice: Code Repair, Chart Parsing, and GUI Operation Controls

    This practical guide explains how to use LLM agents for code repair, chart and screenshot parsing, and GUI automation with verifiable acceptance criteria. It covers task boundaries, reproducible debugging workflows, sample-based validation, permissions and risk controls, private deployment data boundaries, cost estimation, and a pre-launch checklist.

    Large models can already take on part of the work in code debugging, chart parsing, and software operation. But what they can do, to what extent, and where they fail need to be judged in verifiable ways. This article provides practical methods by task type, with preconditions and acceptance criteria for each step.

    1. Define Task Boundaries First

    Before handing a task to an agent, answer three questions: Can the result be automatically tested and verified? Can the operations be rolled back? Does the input data contain sensitive information? Tasks for which all three answers are “yes” are suitable for letting the agent produce a first draft. Operations involving funds, production releases, and permission changes should retain human confirmation. The purpose of these confirmation points is to ensure that every output has an acceptance basis.

    2. A Reproducible Workflow for Code Repair

    Code repair is currently the most common production use case. A reliable workflow includes the following steps:

    1. Fix the environment: Record the Python version, dependency versions, and operating system, and write dependencies into requirements.txt or a lock file.
    2. Minimal reproduction: Have the model first write a test that stably reproduces the problem, then modify the code. Without a reproduction case, it is impossible to judge whether the model’s fix is effective.
    3. Limit the change scope: State in the prompt which files and functions may be modified, and prohibit changes to interface signatures unless the requirement explicitly asks for them.
    4. Run tests and compare: After all original tests and new tests pass, perform human code review.
    5. Preserve a rollback path: Make changes on an independent branch, keep the original commit before merging, and revert directly if problems arise.

    Below is a runnable example. The original code may deadlock when two threads acquire locks in opposite orders. The fix is to lock in a fixed order based on account ID and reject requests that transfer funds from an account to itself.

    1. import threading
    2. from dataclasses import dataclass, field
    3. @dataclass
    4. class Account:
    5. id: int
    6. balance: int
    7. lock: threading.Lock = field(default_factory=threading.Lock)
    8. def transfer(src: Account, dst: Account, amount: int) -> None:
    9. if src.id == dst.id:
    10. raise ValueError("source and destination must differ")
    11. if amount <= 0:
    12. raise ValueError("amount must be positive")
    13. # Lock in ID order so all threads acquire locks in the same order and avoid circular waiting that can cause deadlock
    14. first, second = sorted((src, dst), key=lambda a: a.id)
    15. with first.lock:
    16. with second.lock:
    17. if src.balance < amount:
    18. raise ValueError("insufficient funds")
    19. src.balance -= amount
    20. dst.balance += amount

    The corresponding test is as follows:

    1. from concurrent.futures import ThreadPoolExecutor
    2. def test_concurrent_transfers_keep_total_and_finish():
    3. a = Account(1, 1000)
    4. b = Account(2, 1000)
    5. def worker(i: int) -> None:
    6. for _ in range(200):
    7. if i % 2 == 0:
    8. transfer(a, b, 1)
    9. else:
    10. transfer(b, a, 1)
    11. with ThreadPoolExecutor(max_workers=8) as pool:
    12. futures = [pool.submit(worker, i) for i in range(8)]
    13. for f in futures:
    14. f.result(timeout=10) # Timeout is treated as blocking or deadlock
    15. assert a.balance + b.balance == 2000

    Deadlocks depend on thread scheduling and may not reproduce every time. When running tests, you can install the pytest-repeat plugin and execute pytest --count=50 to repeat the run. The model’s fix must also pass the same tests; it is not enough to judge only its explanation of the problem.

    3. Chart and Screenshot Parsing: Validate with a Sample Set

    Models can read blurry screenshots, skewed documents, and chart data, but recognition errors often occur at decimal points, units, and visually similar characters. The validation method is as follows:

    • Prepare 50 to 100 real samples covering clear, blurry, skewed, and low-resolution cases.
    • Manually label the ground truth and calculate accuracy by field rather than looking only at overall performance.
    • Set validation rules for fields such as amounts, dates, and units. For example, the total value should equal the sum of the line items.
    • Send records that fail validation to manual review, and add the error samples to the next round of the test set.

    4. GUI Agents: Permissions and Risk Control

    GUI agents understand the interface through screenshots and then complete operations with a virtual mouse and keyboard. This approach can cover software that does not expose APIs. However, its failure modes differ from API calls. Interface redesigns, popup occlusion, and input focus misalignment can all cause operation errors, and the errors are often not reported immediately.

    The following controls should be implemented before launch:

    • Least privilege: Create a dedicated system account for the agent and grant only the directory and application permissions required to complete the task.
    • Sandbox execution: Run in a virtual machine or container, not directly on a personal host or production machine.
    • Human confirmation: Actions such as deleting files, sending emails, submitting payments, and changing permissions must be executed only after a human clicks to confirm.
    • Sensitive information masking: Mask ID numbers, bank card numbers, keys, and other content on the screen before sending it to the model. Windows containing sensitive information must not be accessible to the agent.
    • Operation logs: Record the screenshot, action, and time of each step for post-hoc audit and replay.
    • Failure stop: If the interface has not changed after two consecutive operations, or if recognition confidence is low, the agent stops running and requests human intervention.

    5. Enterprise Private Deployment: Data Boundaries and Cost Accounting

    Finance, healthcare, and other industries have strict requirements on cross-border data transfer. Private deployment usually takes three forms: deploying the model in a self-owned data center, using a cloud provider’s dedicated compute cluster, or connecting the model service to the enterprise intranet through a virtual private network (VPC). Which option to choose depends on data classification rules, operations capability, and budget. Whether data meets cross-border requirements should be confirmed by the compliance department based on specific regulations and service agreements; the technical team should not draw conclusions on its own.

    Cost accounting should be based on actual call volume, not unit price alone. The formula is as follows:

    Monthly cost = monthly input tokens ÷ 1,000,000 × input unit price + monthly output tokens ÷ 1,000,000 × output unit price

    Unit prices should be based on the provider’s official pricing page, with the query date noted. Estimates should also include extra tokens generated by retries, long context, and tool calls. Response speed and throughput should likewise be measured with your own business workload; vendor marketing data should not be used directly.

    6. Pre-Launch Checklist

    • Evaluation: Measure accuracy, latency, and failure rate with your own task set, and record the model version and test date.
    • Security: Complete the four checks for permissions, sandboxing, masking, and logging.
    • Compliance: Confirm data storage location, retention period, and third-party access terms.
    • Cost: Estimate monthly cost using the formula and set usage alerts.
    • Rollback: Keep manual processes so you can switch quickly if anomalies occur.

    7. Conclusion

    Agents already produce usable results in code repair, chart parsing, and software operation. However, results depend on model version, task design, test coverage, and permission controls. Developers should first accumulate experience with small, verifiable tasks, and expand usage only after confirming that results are reliable. Enterprises should proceed with private deployment only after completing compliance confirmation.