The little-known way to code with AI agents: a factory, not a chat
DEV Community

The little-known way to code with AI agents: a factory, not a chat

Five inventory agents once ran on the most expensive model I had. They only read files. Nobody had told them which model to use, so they inherited mine. That cost roughly 400,000 tokens for reading work.

That was the day I stopped treating "coding with agents" as chatting and started treating it as a small production line. The title says "little-known", and that is half a joke. Nothing in here is secret. It is five steps, and each one exists because something went wrong without it.

About the "10x": it is a goal, not a result. At the end I say exactly what I measured and what I did not.

The five steps

  • Write the acceptance before the code.
  • Give the agent a task pack, not a chat.
  • Start with the smallest model. Climb a ladder only when it fails.
  • Run a gate. The agent pastes the receipt, not the word "done".
  • Keep a ledger.

1. Acceptance before code

Before any agent writes a line, I write down what "done" means as something a machine can check. A test file, a build command, a request that must return a given status. One expensive planning run, or me alone, produces the plan and these acceptance checks. The workers do not.

Why first: if the agent writes the acceptance and the code together, it can bend one to fit the other. I have had 13 tests come back green while the line they covered was commented out.

2. A task pack

A task pack is a small file for one task. It holds the goal, the files the agent may touch, the acceptance checks, and the commands to run. Nothing else. No history, no opinions.

# Task: export-csv
Goal: GET /export.csv returns all rows of the current filter.
May touch: src/export.ts, test/export-csv.test.mjs (locked, read only)
Acceptance: node --test test/export-csv.test.mjs
Done means: node proof-gate.mjs export-csv exits 0. Paste its four lines.

The agent starts clean from this file. A short pack is cheap to read and hard to misread.

3. The smallest model first

Each task is sized to the cheapest model that might do it. If it fails the gate, the next model up gets the same pack. The top model comes last, and only for tasks the others could not close.

Step Model Used for
1 smallest clear tasks with a ready acceptance check
2 middle reading, searching, inventory, tasks the smallest failed
3 largest planning, audits, the last escalation

Every start sets the model explicitly. That rule comes straight from the 400,000-token day. An agent that is started without a model setting inherits whatever you are using.

4. A gate and a receipt

This is the step I can hand to you today. A gate is one command that decides "done" from exit codes: your checks, plus controls that must fail, plus a locked acceptance file. It writes a receipt with the commit, the time and every exit code.

The receipt has paid for itself. On 24 November my worker agent wrote "gate green". The verdict in the receipt belonged to the commit before the agent's change. It had run the gate before it committed. Because the commit is in the receipt, I saw it.

Same day, a feature gate was green with 6 of 6 steps, and the full server tests were red. One test demands that every server route has a caller in the app or a written exception. The gate had not included the full tests. I caught it before the push. Now the full test run is part of the gate.

5. A ledger

Every task adds one line to a log: task, model, how many tries, gate result, tokens. It is a plain file. I read it when something feels expensive, and the answer is usually in the numbers, not in my memory.

Try the light version

The gate is the part I can give away, so I did. proof-gate is one Node file (18+), MIT, no dependencies, 18 tests of its own. It covers step 4 and the locked acceptance from step 1.

git clone https://github.com/cachly-dev/proof-gate
cp proof-gate/proof-gate.mjs ./proof-gate.mjs

proof-gate.json :

{
  "tasks": {
    "export-csv": {
      "locked": ["test/export-csv.test.mjs"],
      "checks": [
        { "name": "acceptance", "run": "node --test test/export-csv.test.mjs" },
        { "name": "build", "run": "npm run build" }
      ],
      "controls": [
        { "name": "fails on the old exporter", "run": "node --test test/export-csv.test.mjs", "env": { "USE_OLD_EXPORTER": "1" } }
      ]
    }
  }
}
node proof-gate.mjs lock export-csv # you pin the acceptance file once, then commit
node proof-gate.mjs export-csv # anyone runs this
TASK: export-csv
GATE: 0 (3/3)
RECEIPT: .proof-gate/receipts/export-csv.json

NOTE:

  • Put this in CLAUDE.md or AGENTS.md :

Done means

A task is done when node proof-gate.mjs <task> exits 0. Paste its four lines.

  • Never edit files listed under "locked". If the test is wrong, stop and say so.
  • If a control passes, fix the check, not the control.

That is the light version. It has no task packs, no model ladder and no ledger. It is the one piece that works alone.

What I measured, and what I did not

Measured, before I rebuilt the method: about 120,000 tokens per task (median), and the orchestrating agent made up 51% of the cost. That is why I moved reading and planning off the top model and put a ladder under the workers.

Not measured: the "10x". I do not have a clean before-and-after on tokens, time or defects that would let me say it. Tasks differ too much. So here is the plain version. 10x is what I am aiming at. What I can show you today is a method that makes agents cheaper to run and harder to fool, and a receipt for each task.

If someone shows you a 10x number without the task list behind it, ask for the task list.

What is not solved

  • A bad acceptance check still gives a bad result. The gate protects you from fake "done", not from wrong requirements.
  • The ladder needs sizing judgement. I still misjudge tasks and pay for it.
  • Small teams may find the ledger a chore. I do too, on some days.

Try it tonight

Take one task you would normally throw into a chat. Write its acceptance first. Write a five-line task pack. Run it through the gate. Look at the receipt.

The whole method (task packs, model ladder, gate, ledger) is packed as a free ZIP. Leave your address at cachly.dev/forge and the download link arrives after you confirm. Nothing else to say about it.

Which of the five steps do you already do, and which one would you skip first?

I build cachly. It keeps what you explain to your AI: your rules, your decisions and the bugs you already solved. Claude Code, Cursor, Copilot and the others read it in every session, for you alone or for your whole team, and every lesson carries the name of whoever learned it.

Try it, in increasing order of commitment:

  • 30 seconds, no account: npx @cachly-dev/mcp-server@latest demo in any git repo. It reads your log locally and prints what an assistant would already know about the project. After npx fetches the package, the command makes no network calls.
  • Claude Code plugin: /plugin marketplace add cachly-dev/cachly-mcp, then /plugin install cachly-brain@cachly.
  • 5 minutes, free tier: npx @cachly-dev/mcp-server@latest autopilot writes the MCP configuration for whichever assistant you use. Or from the web: cachly.dev ยท free tier, servers in Germany.
  • Launching on Product Hunt today, 1 December: cachly on Product Hunt.
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.