LESSON 8

The Cron-AI Pattern: Script First, AI Last

Using LLMs for structured data operations is like hiring a surgeon to take your blood pressure. The cron-AI pattern fixes this.

8 min read·Automation

The most expensive mistake in AI automation isn't a bad prompt. It's routing work to an LLM that a Python script could handle for free.

Most people build AI pipelines that look like this: feed everything to Claude, get everything from Claude. Clean, simple, and completely wrong at scale.

Cron-AI Pattern

The Mistake Everyone Makes

When you first wire up an LLM to your workflow, everything feels like a nail. Need to fetch a YouTube transcript? "Claude can do that." Need to parse a JSON response? "Let's ask the model." Need to send a Discord message? "AI will figure it out."

This is how you burn through your token budget doing work that requires zero intelligence.

WARNING

Don't use Claude to parse a CSV. That's what pandas is for. Don't use a $20/million-token model to extract a field from JSON. That's what response["key"] is for.

The moment you catch yourself sending structured, deterministic data operations through an LLM, stop. That's a signal you haven't decomposed your pipeline correctly.

The Three-Stage Architecture

Every intelligent pipeline has exactly three jobs. Only one of them requires actual intelligence.

Stage 1 — Gather (Python/Bash). Fetch the raw material. Hit APIs. Pull RSS feeds. Scrape transcripts. Download market data. Run your engine. This stage is pure I/O. No reasoning required. Cost: zero.

Stage 2 — Synthesize (AI). This is the only stage where you pay for intelligence. One focused AI call with a clean context window. The model reads the intermediate file and produces the artifact — the article, the analysis, the narrative. One call. One output.

Stage 3 — Deliver (Python/Bash). Take the AI output and move it somewhere. Open a git PR. Post to Discord. Write to a file. Send a webhook. Pure execution. Cost: zero.

The intermediate file is the handoff mechanism that makes this work. Stage 1 writes /tmp/context.json. Stage 2 reads it. Stage 3 reads the output. Stages never call each other directly — they communicate through files.

Real Examples From Our Stack

These aren't hypotheticals. This is how three production pipelines actually run:

blog-autopilot: gather.py fetches YouTube RSS, selects a topic via rotation logic (no AI — deterministic Python), downloads the transcript via Supadata API, and writes /tmp/blog_context.json. Claude reads that file and synthesizes a 1,200-word article in Knox's analytical voice. deliver.py generates the hero image via Leonardo AI, commits the MDX file, and opens a GitHub PR.

trade-alerts: Python fetches Polymarket odds, Coinglass liquidation data, and fear/greed index — all structured JSON from public APIs. Claude receives the aggregated context and produces the signal analysis. A Discord webhook posts the result.

weekly briefing: The InDecision engine runs entirely in Python — no AI involved in the scoring. It writes the market snapshot to an intermediate file. Claude reads it and writes the narrative. deliver.py opens the PR.

Machines handle the mechanical. Pilots handle the decisions.

John Boyd · Patterns of Conflict

Why This Matters at Scale

Gather + Deliver Cost
~$0
Pure Python — no token spend
AI Calls Per Pipeline
1
One focused synthesis call
Pipeline Stages
3
Gather → Synthesize → Deliver

The financial discipline is obvious once you see it: 80% of a pipeline's operations are deterministic. If you route that 80% through an LLM anyway, you're spending 5x what you need to and getting worse reliability in exchange.

Scripts fail loudly. If gather.py can't reach the API, it throws an exception, writes a log entry, and the pipeline stops with a clear error message. When you embed that same logic inside an LLM call, failures become ambiguous. Did the model misunderstand? Did the API timeout? Did it hallucinate the data? You can't tell.

INSIGHT

The intermediate file pattern gives you auditability you can't get any other way. When a pipeline produces a bad article, you can open /tmp/blog_context.json and see exactly what the model was given. That's your debugging surface. Without it, you're reconstructing the crime scene from the output alone.

The Decision Rule

Before routing any task to an AI, ask one question: "Could a deterministic function with the right library do this?"

If yes — write the function.

If the answer is "yes, but the AI would do it faster right now" — that's a short-term optimization that becomes a long-term tax. Write the function.

The only tasks that belong in Stage 2 are tasks where the output depends on judgment, synthesis, or voice that can't be reduced to a deterministic rule.

Lesson 8 Drill

Pick one AI workflow you run regularly. Map every operation it performs and put each one in a column: "Could Python do this?" vs. "Requires AI reasoning."

Count the rows in each column. If more than 40% of operations are in the "requires AI" column, you haven't decomposed far enough.

That percentage is your waste ratio. Eliminate it.

Bottom Line

Scripts are free, fast, and fail loudly. AI is expensive, powerful, and fails silently. Route accordingly.

The cron-AI pattern isn't about being cheap — it's about being precise. One focused AI call on clean context produces better output than five unfocused calls on noisy input. Structure the pipeline right and you get better quality at lower cost.

That's not a tradeoff. That's architecture.

Explore the Invictus Labs Ecosystem