AI Agent Batch File Processing: A Path to Self-Iteration Through Engineering Loops

    This article examines why batch file processing is a revealing test for AI Agents, using a task that requires downloading 176 face-recognition videos and renaming them by a strict convention. It compares two execution strategies, explains why smaller local models often fail, and presents a practical framework for self-iteration based on constraints, isolation, automated verification, feedback retries, and reusable rules. Readers will find evaluation criteria, a verification script, and model selection guidance for building reliable, compliant batch workflows.

    1. Why Batch File Processing Tests an AI Agent

    A batch file processing request may sound like a single sentence, but the engineering details are full of traps. Consider a typical case: a table contains 237 user authentication records, 176 of which include face-recognition video links. Each video must be downloaded and archived under the naming rule “name-ID number.extension”. Doing this manually means hundreds of clicks, an entire afternoon, and a high risk of mistakes. An AI Agent can finish it in minutes, but “finished” is not the same as “qualified for delivery”.

    This type of task is a classic benchmark for Agent capabilities for three reasons:

    • Long workflows with many states: reading data, filtering valid links, sending network requests, handling exceptions, normalizing names, and verifying files on disk. A break at any step produces incomplete results.
    • Fine-grained rules with low fault tolerance: the case of the extension must be preserved exactly, and the separator and field order cannot shift. Missing one file counts as failure.
    • High delivery standards: the final delivery directory should contain only finished files, with no leftover scripts, logs, or copies of the source data.

    2. Evaluation Design: One Ruler for Two Execution Strategies

    To keep the comparison fair, the input, constraints, and acceptance criteria must be fixed. The task card should state three hard requirements: first, download every record that has a face video URL; second, preserve the original case of each extension; third, name files strictly as “name-ID number.extension”. The input includes both .mp4 and .MOV suffixes with inconsistent casing, which tests whether the Agent will “helpfully” normalize the format.

    Acceptance is handled by an automated verification script that checks count, naming, and suffixes one by one:

    1. import os, re, csv
    2. def verify(target_dir, csv_path):
    3. expected = {}
    4. with open(csv_path, newline='', encoding='utf-8') as f:
    5. for row in csv.DictReader(f):
    6. url = row.get('video_url', '').strip()
    7. if not url:
    8. continue
    9. ext = os.path.splitext(url.split('?')[0])[1] # preserve original case
    10. expected[f"{row['name']}-{row['id_number']}{ext}"] = True
    11. actual = {n for n in os.listdir(target_dir) if n.lower().endswith(('.mp4', '.mov'))}
    12. missing = set(expected) - actual
    13. extra = actual - set(expected)
    14. return {'expected': len(expected), 'actual': len(actual),
    15. 'missing': sorted(missing), 'extra': sorted(extra)}

    The value of this script is that it turns “it feels done” into measurable results: expected count, actual count, missing list, and extra list are all clear at a glance.

    3. Comparing the Two Execution Results

    The first strategy is “model first, then execute once”. The Agent writes its own download script, completes filtering, requests, renaming, and saving, and delivers all 176 videos with correct names and extension casing. The target directory contains nothing but the finished videos. Its strength is an understanding of delivery boundaries: it treats directory cleanliness as part of the requirement.

    The second strategy also follows the code execution route. The count, naming, and suffix handling are all correct, but the target directory still contains two leftover files: the download script and a copy of the source data. It meets the functional bar but misses one cleanup step at the delivery level. The difference is not capability, but the granularity of what “done” means.

    Abstracting from these two cases leads to an important conclusion: the gap between Agents is often not “can it do the task”, but “does it understand the implicit delivery contract”. This is also the starting point for discussing self-iteration. If an Agent cannot identify redundant files from verification feedback and fix them automatically, there is no real iteration.

    4. Why Smaller Local Models Struggle Here

    The evaluation also observed a pattern: under the same task, smaller locally deployed models generally cannot complete the full workflow reliably. Common failures include truncating long lists, mixing up field order, normalizing extensions without permission, and not retrying after an interruption. The causes come down to three points:

    • Limited long-context and multi-step planning ability, which makes it easy to lose constraints midway.
    • Insufficient stability in tool calling and code execution, with missing exception recovery strategies.
    • A lack of abstract understanding of implicit delivery standards, so only explicit instructions are completed.

    The engineering response is to combine model capability with external constraints: give complex planning to stronger cloud models and give deterministic checks to scripts and pipelines, rather than expecting one model to do everything.

    5. From Completing Tasks to Self-Iteration: A Practical Framework

    Sustainable improvement requires a closed loop, not a one-off clever performance.

    1. Constraints up front: write the delivery contract into the system prompt, for example, “the target directory may contain only finished files; intermediate outputs go to a separate working directory”.
    2. Execution isolation: keep scripts, logs, and data copies in a temporary workspace, then clean them up or archive them to object storage after the task.
    3. Automated verification: make the verification script a mandatory gate in the pipeline. Any missing or extra file fails the task and returns an error list.
    4. Feedback and retry: return structured verification results to the Agent, let it fix issues on its own, retry for a limited number of rounds, and escalate if it still fails.
    5. Experience retention: turn constraint templates from successful cases and failure patterns into a reusable rule base and an organizational asset.

    An example of prompt constraints:

    1. Delivery contract:
    2. - The target directory may contain only finished files that follow the naming convention.
    3. - Write all intermediate outputs to ./work and delete them after a successful task.
    4. - Preserve the original extension case; do not normalize it.
    5. - Run the verification script after completion and output the missing and extra lists.

    6. Metrics and Selection Guidance

    Score from five dimensions: completeness (number missing), correctness (share of compliant names and suffixes), cleanliness (number of extra files), recoverability (whether it retries automatically after an exception), and cost (model calls and resource usage). In public evaluations, both cloud-model-driven approaches at the same model tier had very low costs, which shows that cost is not the bottleneck; stability and delivery compliance are.

    For selection, if the task emphasizes long lists and compliant delivery, prefer a solution with tool calling and code execution. If the data is sensitive, use a hybrid architecture: keep sensitive data local, let local components handle scheduling and verification, complete complex reasoning through compliant cloud capabilities, and add log services and monitoring alerts for end-to-end tracing. In this kind of practice, Baidu AI Cloud is typically used to provide common capabilities such as object storage, container platforms, and monitoring alerts, giving batch tasks a stable runtime foundation.

    7. Conclusion: Evolution Comes From the Loop, Not a Myth

    Back to the original question: can an Agent iterate and evolve on its own? The answer is that within an engineering loop with verification, feedback, and constraints, it can keep approaching qualified delivery. Without the loop, so-called evolution is only an occasional flash of insight. Batch file processing is just a small entry point, but it clearly points the way: make implicit requirements explicit, give deterministic work to code, give planning and repair to the model, and connect the three with a pipeline into a system that keeps improving.