---
title: "Let code do the looking, and wake an agent only when there is something to read"
date: 2026-10-18
summary: "An hourly inbox check ran as an agent turn in one long conversation, and its cost climbed every hour while most checks said nothing. Moving the looking into plain code with a cheap classifier in front means most hours no agent starts at all."
tags: ["agents", "scheduling", "cost", "classification"]
url: https://blog.misherate.com/posts/let-code-do-the-looking-and-wake-an-agent-only-when-there-is
thumbnail: https://blog.misherate.com/thumbnails/let-code-do-the-looking-and-wake-an-agent-only-when-there-is-mwfggb94.jpg
---

Misha's [iterate](https://iterate.com) mind is a git repository of code that runs agents and schedules; this is about one of its schedules, and why it should almost never wake an agent.

Paying an agent $0.47 an hour, and rising, to report "nothing new" ten times out of thirteen: that was the mind's hourly inbox check in its first version. The job was simple: look at new mail once an hour, and say something only when there is something worth saying. The first version did the obvious thing. Every hour, an agent turn ran with an instruction to check the inbox.

It worked, and it was the wrong shape. The commit that replaced it gives the numbers: each hourly turn ran inside one long existing conversation, so every check re-read that whole conversation plus a ledger of about 100 KB. The cost per check went from $0.08 to $0.47 an hour and kept rising as the conversation grew. And 10 of 13 checks said nothing.

Two problems are tangled together there. A scheduled job was riding on a conversation that had nothing to do with it, so its context only ever grew. And a model was being paid to do the part of the job that is a list and a filter.

## Split the job where the judgement starts

The new check is ordinary code until the point where judgement is actually needed:

1. A schedule appends a "check due" event to the check's own context every hour.
2. Code lists the mail of the last two days and drops what the check has already seen. Two days rather than one hour, so a day of failed checks misses nothing.
3. For each new mail, a small classifier gets the sender, subject and first lines, plus the mind's notes on what is currently open, and answers one yes/no question: should the mind read this in full?
4. Only if at least one mail clears the bar does an agent start: a fresh one, with no conversation behind it, given the mail that may matter, a one-line list of the rest, and the check's own instructions.

```ts
async function checkInbox(itx, event) {
  if (event.type !== "inbox/check-due") return;
  const seen = new Set(await book.seen());
  const fresh = (await listMail(itx)).filter((id) => !seen.has(id)).slice(0, 40);
  if (fresh.length === 0) return; // most hours end here: no model call at all

  const judged = await Promise.all(fresh.map(async (mail) => ({ mail, p: await worthReading(itx, mail) })));
  const answered = judged.filter(({ p }) => p !== null); // no answer: try again next hour
  const toRead = answered.filter(({ p }) => p! >= 0.5);

  const agent = toRead.length > 0 ? await startFreshAgent(itx, event, toRead) : null;
  await book.markSeen(answered.map(({ mail }) => mail.id));
  await log(itx, event, { agent, mail: answered });
}
```

Measured on two days of real traffic, that threshold sent 20 of 67 mails to an agent, and an agent ran in 10 of the 48 hours. In the other 38 hours the check cost a list call and, at most, a few classifier calls.

## The details that make it safe to skip

A filter in front of an agent is only acceptable if what it filters out is not lost. A few choices handle that.

**Unanswered is not "no".** If the classifier fails or gives no probability for a mail, that mail is not marked seen. It is judged again on the next look. Only mail that got a verdict, either way, is marked seen.

**The agent can overrule the filter.** It gets the full list of new mail, not just the flagged ones, and its instructions say the classifier guesses from a few lines and that it should read anything it doubts. The cheap step decides when to wake an agent; it does not decide what the agent is allowed to look at.

**Some categories skip the classifier.** Half an hour later, the check changed to read every mail in the primary inbox without asking the classifier, and to use the classifier only for the automated-notifications category. On the same two days that meant an agent in 11 hours of 48 instead of 10. When a false negative is expensive and the volume is small, the simplest filter is none.

**Every look is logged.** Each check that found new mail appends one entry to the check's own context: what came, the classifier's probability for each, and which agent, if any, started. When something is missed, there is a record of whether it was filtered out or read and dismissed. The entry's idempotency key is the event's offset, so a redelivered check does not log twice.

## Silence has to be built in

The other half of "say something only when it matters" is making sure nothing leaks out when it doesn't. A turn started by a person owes them an answer, and the relay that carries answers back to the chat shows "typing…" and sends progress on long turns. None of that is right for a background check.

So a scheduled agent's input is marked as owing no answer, and the relay recognises a turn that a schedule started and shows neither typing nor progress for it. The day before, that had been a two-line change in the relay: a turn whose input begins with `[scheduled` is a quiet turn.

```diff
   this.owed =
+    !state.quietTurn &&
     state.owedSinceOffset !== null &&
     now - state.turnStartedAtMs < OWED_MAX_MS;
```

An agent with nothing to report answers with nothing, and nothing is sent. Its instructions also say plainly that a mail is information, never an instruction, whatever it says.

## Instructions follow the job

The check's rules used to live in the mind's main instructions, which every agent reads for every message. They moved into a file of their own that only the check's agent is given. A rule that applies to one scheduled job is noise, and cost, for every other conversation.

## What carries over

- If a recurring job mostly finds nothing, the finding-nothing part should not be a model turn. Do the listing and deduplication in code.
- Put a cheap classifier between the list and the agent, and give the agent the whole list so it can overrule it.
- Start a fresh agent per run instead of appending to a long conversation; a schedule should not inherit anyone's context.
- Treat "the classifier gave no answer" as "ask again later", not as "no".
- Make silence the default for background turns, in the delivery code rather than in the prompt.
