How to monitor AI agents that run on a schedule

Updated 6 min read

On this page
  1. Five ways an unattended agent goes wrong
  2. Step 1: Create a monitor
  3. Step 2: Bracket each run
  4. Step 3: Send what the run produced
  5. Step 4: Turn on the rules that fit
  6. Example: a Python agent with no extra packages
  7. Example: a CLI agent from cron
  8. What this doesn't do
  9. FAQ
  10. Start with the agent you trust least

To monitor an AI agent that runs on a schedule, have it send a start ping when it begins and a finish ping with its exit code, its answer and its token count or cost when it ends. An outside monitor can then alert you when a run is missed, fails, hangs, returns nothing or costs far more than usual. It's plain HTTP, so there's no SDK to install and it works with any language or framework.

An agent that runs unattended, from cron, a scheduler or a worker, can go wrong in ways a normal job doesn't. It can finish with exit code 0 and an empty answer. It can run three times as many model calls as usual. And like any job, it can stop running without anyone noticing.

This guide sets up an outside check for all of that using plain HTTP. There's no SDK to install: your agent sends a few small requests to a ping URL, and Stallbell alerts you when something looks wrong.

Five ways an unattended agent goes wrong

  1. It didn't run. The scheduler stopped, the server is down, or a deploy removed the job.
  2. It failed. An exception, a rate limit from the model provider, a tool that errored.
  3. It hung. A request that never returns, a tool waiting on input, a retry loop with no end.
  4. It returned nothing useful. Blank text, whitespace, or JSON that doesn't parse, passed on as if it were fine.
  5. It cost far more than usual. A prompt that grew, a model switch, an agent that took ten times the steps.

Each of these maps to one Stallbell rule: Missed run, Failed run, Stuck run, Empty output and Cost spike.

Step 1: Create a monitor

Sign in with your email and create a monitor for the agent. Set Kind to Agent, and set How it runs to match your scheduler: On a fixed interval with an Every value, or On a cron schedule with a Cron expression and Schedule timezone. Copy the ping URL. It looks like https://stallbell.com/p/TOKEN, and the token is the secret part, so keep it out of public repos.

Step 2: Bracket each run

Send three kinds of ping, all with the same run_id:

  • /start when the run begins
  • /progress during a long run, to show it's still moving
  • the exit code when it ends: /0 for success, any code from 1 to 255 for failure (or /ok and /fail)

The run_id is any string up to 128 characters that you choose. Stallbell uses it to join the start and the finish into one run, so it can work out the duration and spot a run that never finished.

Step 3: Send what the run produced

On the finish ping, send a JSON body with what Stallbell should check:

FieldWhat it's for
outputthe agent's answer, or the part you care about. Stallbell keeps the first 2 KB
model, input_tokens, output_tokensso Stallbell can work out the cost from its own price table
cost_usdthe cost, if you already know it. It wins over the token count
msga short note, kept to 500 characters. Handy for the error text on a failure
duration_msthe run time, if you measure it yourself

The whole body has to stay under 16 KB, or the ping is rejected with a 413.

Step 4: Turn on the rules that fit

Open the monitor's settings. The defaults for a new monitor:

SettingDefaultWhat it does
Grace period5 minuteshow late a run can be before Missed run
Failures in a row1the first failed run alerts
Stuck after1 houra started run with no finish or progress for this long alerts as Stuck run
Flag empty outputonalerts when a finish sends output that's empty or only whitespace
Output must containblanka phrase the output has to include
Output must be JSONoffalerts when the output doesn't parse as JSON
Cost spike3alerts when a run costs more than 3 times its usual cost
Per-run cost cap, Per-day cost capblankoptional hard limits in dollars

"Usual cost" is the median of the last 14 runs that reported a cost. The cost spike rule waits until there are at least 5 of them, and ignores runs under $0.01. Set Stuck after a little above your slowest normal run.

Example: a Python agent with no extra packages

This uses only the standard library. Replace run_agent() with your agent call.

Python
import json, os, sys, uuid, urllib.request

PING = "https://stallbell.com/p/TOKEN"
run_id = str(uuid.uuid4())

def ping(path, body=None):
    data = json.dumps({"run_id": run_id, **(body or {})}).encode()
    req = urllib.request.Request(PING + path, data=data, method="POST",
                                 headers={"content-type": "application/json"})
    try:
        urllib.request.urlopen(req, timeout=10).read()
    except Exception as e:  # never let monitoring break the agent
        print("stallbell ping failed:", e, file=sys.stderr)

def run_agent():
    # your agent here; return (answer_text, model, input_tokens, output_tokens)
    return "Summary: 3 new leads", "gpt-4.1-mini", 1200, 80

ping("/start")
try:
    answer, model, tin, tout = run_agent()
    ping("/0", {"output": answer[:2000], "model": model,
                "input_tokens": tin, "output_tokens": tout})
except Exception as e:
    ping("/1", {"msg": str(e)[:500]})
    raise

If run_agent() raises, the agent still reports a failure with the error text, then exits with the error as before.

Example: a CLI agent from cron

For an agent you start from the command line, wrap it in a small script that sends the start, the exit code and the output. Save this as /usr/local/bin/agent-run and make it executable:

Shell
#!/bin/sh
# agent-run: run a command, report start, exit code and the first 2 KB of output.
# Usage: agent-run PING_URL command [args...]
url="$1"; shift
run_id="$(date +%s)-$$"
out="$(mktemp)"

curl -fsS -m 10 --retry 3 -o /dev/null "$url/start?run_id=$run_id"
"$@" > "$out" 2>&1
code=$?
len=$(wc -c < "$out" | tr -d ' ')
head -c 2048 "$out" | curl -fsS -m 10 --retry 3 -o /dev/null \
  -H 'content-type: text/plain' --data-binary @- \
  "$url/$code?run_id=$run_id&output_len=$len"
cat "$out"; rm -f "$out"
exit "$code"

Then in the crontab:

Code
0 6 * * * /usr/local/bin/agent-run https://stallbell.com/p/TOKEN /opt/agents/daily-digest

With a text/plain body, Stallbell treats the body itself as the run's output, so the empty-output rule sees exactly what the agent printed. The output_len field matters when the agent prints nothing: an empty body on its own doesn't count as output, but output_len=0 tells Stallbell the output was there and empty.

What this doesn't do

Be clear about the limits before you rely on it:

  • It doesn't watch inside a run. The loop rule counts runs per window, not tool calls or model calls within one run.
  • It doesn't stop spending. A cost cap sends an alert; it doesn't cancel the run or touch your provider account.
  • It doesn't read your provider bill. Stallbell only knows the cost or tokens your agent reports. A model missing from its price table gets no computed cost, so send cost_usd for those.
  • It doesn't judge quality. The output checks are empty, whitespace, a required phrase and valid JSON. Nothing more.

FAQ

Do I need an SDK? No. Every ping is a plain HTTP request. GET, POST and HEAD all work, so curl, urllib, fetch or an HTTP node in a workflow tool are enough.

What if the ping itself fails? Wrap it so it can't break the agent, as in the Python example. If pings stop arriving, you get a Missed run alert, which is what you want to know anyway.

How do I monitor a run that takes hours? Send /progress with the same run_id every so often. Each one resets the Stuck after clock. See detect stuck jobs.

Can it alert when the answer is empty but the run succeeded? Yes. Send the answer as output on the finish ping and keep Flag empty output on. See alert on empty LLM output.

What does Stallbell store? The events, times, your run_id, the exit code, model, tokens and cost, msg up to 500 characters and the first 2 KB of output. Leave anything sensitive out of output and msg.

What does it cost? There's a Free plan with no card. While Stallbell is in beta, billing is off and every account gets Pro limits with every-minute checks. Plans and limits are on the pricing page.

Start with the agent you trust least

Pick the scheduled agent whose silent failure would hurt most, bracket it with a start and a finish ping, and send its output.

Related: Alert on empty LLM output · Detect stuck jobs · What is heartbeat monitoring? · How to monitor cron jobs · How to monitor n8n workflows · n8n AI agent returns an empty answer