Should the agent do it, or write a script?
There are two ways I give a coding agent a task involving more than a few steps. One is to set it off to do the task: it looks at files, runs some commands, looks at the results and decides what else to do until it tells me it has finished. The alternative is to ask it to write a script to do the task, review the script and run it myself.
I measured the two on a minor work task: produce a report of issues on GitLab assigned to me. The tasks verbatim are:
- "Find all the gitlab issues assigned to me and write a simple report with title, author, status, ncomments"
- "Write a simple python script that uses the gitlab api to get all the issues assigned to me and transform them into a .md document with title, author, status, comments"
| Agent does it | Agent writes a script | |
|---|---|---|
| First time | 81.2k tokens, $0.73 | 59.4k tokens, $0.37 |
| Again | a new agent works it all out again, and could get it wrong | the script runs for nothing, and the next agent can change it |
It cost about half as much to write a script to do this as to actually do it. On the link check below it cost a bit more. More crucially for me, if it fails to do the task, I want to know why. Two more examples, both from building this site.
Example 1: checking links
I want to be able to verify that no links or images on the site are broken before pushing changes. I asked the agent to crawl localhost and report on this. It fetched the home page and the pages it links to, followed links found within those pages and reported what it found, having read a lot of HTML it didn't need on the way.
I asked it to do this again in the same session, which was cheaper as it still had the context of the first crawl. A fresh session starts from scratch.
I've now had it write a script to do this (scripts/check-links.py). It's
about 130 lines of Python: it starts at the root and follows all internal links
and image sources, reporting back anything that isn't a 200 response. It takes
seconds to run and doesn't require the agent.
I can read the script to see more detail of what it's doing.
| Agent does it | Agent writes a script | |
|---|---|---|
| First time | 69.7k tokens, $1.21 | 77.5k tokens, $1.52 |
| Again, same session | 5.3k tokens, $0.32 | 0.3k tokens, $0.06 |
| Ten times the pages, estimated | about 700k tokens, about $12 | the same |
The script cost more than a crawl to write and was ahead by the third run. The site has 25 pages; for a site with 250 pages a crawl would cost 10+ times as much, and the script would cost the same to write and run. It's a stupid script. It recently informed me that the link to a paper of mine (2011) on IEEE Xplore was broken. It wasn't: the DOI link worked fine, but IEEE answers anything that looks like a script with a 202 instead of the article page. 202 isn't 200, so the script included this in its report. I've looked at the DOI page and it links to the correct article, so that's fine. The script was reporting something incorrect that took me a moment to investigate.
An agent performing a similar crawl would likely look at this 202 page and think it's generally fine. Most of the time it would be. If not, I wouldn't know, as the output it provides me is identical either way.
Example 2: screenshots at phone width
I wanted a screenshot of each page at 375px wide to see how they looked on a mobile device. The agent initially tried doing this via a headless instance of Edge launched from the command line at a mobile window size. This produced screenshots with the right-hand side of the page cropped off. I eventually found out that headless Edge refuses to render a page at less than about 500px wide, regardless of the window size you specify, and that it had rendered at 500px and cropped the screenshot to 375px.
I've had the agent write a script around this (60 lines of Node), which launches Edge in remote debug mode, provides an interface to Edge via the DevTools protocol, enables full mobile emulation and for each page produces a screenshot of the whole page and a note saying whether any content extends beyond the specified screen width.
The long portfolio page came back with its lower images blank. The agent suggested 'lazy loading' of images and added a scroll before capturing the page. Still blank. I got the script to output the loading status of each image. They had all loaded. It wasn't lazy loading at all but a result of trying to capture a page over 5000px tall in one go. Making the 'screen' being captured as tall as the page fixed this.
I think the agent would have spent quite a while patching around lazy loading if I hadn't intervened. I got the script to output a line for each image. That solved it.
Splitting the work
Most things I do have a mechanical part and a judgment part. An example is triage of issues on the Vulkan conformance test suite. Finding issues that have changed since I last looked at them is mechanical. Deciding what I need to do about them isn't; it involves interpreting badly written notes from people in a rush.
I've separated these. I've had the agent write a script to generate a line of JSON for each issue. The agent then reads this and decides what needs doing from that point.
The script half, simplified a lot, is this:
for issue in tracker.list_issues(updated_since=last_run):
print(json.dumps({
"id": issue.id,
"title": issue.title,
"assignee": issue.assignee,
"last_comment_by": issue.comments[-1].author if issue.comments else None,
"labels": issue.labels,
}))
The agent gets a page of JSON instead of a stack of issue pages full of markup, so its context stays small and all of it goes on the question that needs a model.
How I decide
| Agent does it | Agent writes a script | |
|---|---|---|
| Cost per run | Tokens and minutes | Almost nothing |
| When it breaks | Confident summary | Error in the output |
| What I review | Every run | The script, once |
If I'll do a task again, or there are more than a handful of items, I have the agent write a script. Same if the answer has to be exactly right. If every item needs a judgment call on messy input, I let the agent do it, and most of what I do ends up as some of each.
Two more things I've learned to do. When a script fails I don't let the agent fiddle with it until it passes, because sometimes the failure is the right answer; the DOI above is one. And when a script prints a number I read the number myself instead of asking the model what it says.
I help teams set up this kind of AI workflow on production codebases. See services.
Subscribe to my newsletter
Receive new posts by email: occasional notes on GPU conformance, mobile performance, and AI in software engineering. Unsubscribe anytime.
Subscribe