TLDR: An agent was running an entire data workflow and performing work that a script should have been doing. Splitting the steps into code and keeping the agent for real judgement made the workflow faster, cheaper, more deterministic. Anyone else splitting workflows into code?
## Context
I recently read the argument we need to use code more in our AI workflows since its fast, deterministic, and costs 0 tokens to run 🥳. I revisited a slow and token expensive workflow to see if any improvement can be made (Hint: there was), here is my story.
## The workflow
I built a workflow to enrich data on a directory site I am building.
- Find records to enrich
- Discover the official source ( e.g. company website)
- Extract information
- Decide what needs adding or fixing
- Write it back into the directory
- Open a PR
My first instinct was to throw (possibly too hard) an agent at the whole thing, one smart loop.
It was slow and had some performance issues (skill issue I know). Some steps were obvious to switch:
- Deciding which records to process is a filter, not a decision.
- Writing changes to a database is an API call, not a choice.
I was tolerating token cost and hallucination risk for steps a script does perfectly, every time, for free.
Side note: I didn't run token cost comparison or analysis of many tokens were used for orchestration vs actual work.
## Reframing the workflow
The workflow has 3 actors:
Thinking about it this way, the agent only touches the part a script structurally can't do.
Some problems it solved:
- The agent didn't try loading the entire database of options into context
- It kept extracting a value the schema had no column for, and improvising a workaround every time
## Insights
The big insight for me is: if an agent is solving the same structural problem repeatedly instead of once, it's not doing judgment work, it's doing the job code should've done from the start.
The LLM brain works on the decision steps.
## Open Questions
- Anyone else splitting workflows into code?
- Is there a more ICM way to handle this? Just add instructions in the workflow to call the scripts?
## 🎁 Bonus question
If anyone is running these data <-> LLM pipelines, I would be curious to connect as I have another project around text to metadata extraction. ~50k records to parse through.