GUIDE · OPENAI AGENTS SDK · AGENT-FIRST

Monitor OpenAI Agents — dead-man's-switch for AI agents that run on a schedule

Three lines of Python around your Runner.run() call — or connect the LastPing MCP server and let the agent set up its own monitor in one conversation. Catches missed scheduled runs, hangs on tool calls, and unhandled exceptions. Free, no monitor cap.

AI agents fail silently. Especially the unattended ones.

An OpenAI Agents SDK agent running a nightly summary, a weekly report, or a recurring data pipeline has no built-in way to tell you it stopped working. Three failure modes go undetected without an external watchdog.

Failure mode 01

Missed scheduled run

A cron job or scheduler that invokes the agent can fail silently: OOM-killed host, expired API key, scheduler process crash, temporary network outage. The agent never runs, and nothing tells you it didn't.

Failure mode 02

Hung on a tool call

Agents block on tool responses — a database query, an HTTP API, a shell command, a search result. A hung tool call means Runner.run() never returns. No exception is raised — just silence.

Failure mode 03

Unhandled exception exits quietly

An API rate limit, a malformed response, a context-length overflow, a network timeout — any unhandled exception that exits the process or is swallowed by the scheduler leaves no trace unless you've explicitly set up exception logging and alerting.


Setup: two approaches

Add pings manually in three lines of Python — or connect the LastPing MCP server and have the agent instrument itself in one conversation.

Agent self-registration via MCP (the agent-first path)

Add the LastPing MCP server at mcp.lastping.dev to your agent's MCP server list. Then prompt: "Register a LastPing heartbeat for this agent — daily at 2 AM UTC, 30-minute grace, alert on Slack. Get the ping snippets and add them to the run loop." The agent calls create_monitor, then get_ping_instructions, and wires the pings into its own code. No dashboard visit, no manual UUID copying. Learn about the LastPing MCP server →

Create a heartbeat monitor in LastPing

In the console, create a monitor, choose Heartbeat, and set the period to match your agent's cron schedule (e.g. daily). Add a grace window (e.g. 30 minutes). Copy the ping URL — it's a UUID you'll use in the Python snippet below.

https://ping.lastping.dev/<uuid>

Wrap your Runner.run() call with pings

Add a start ping before the run (arms overrun detection), a success ping after, and a fail POST in the exception handler. The /fail body is stored on the open incident — so the alert shows the exception, not just that it happened.

import httpx from agents import Agent, Runner # openai-agents PING_URL = "https://ping.lastping.dev/<uuid>" async def run_agent(): # arm overrun detection httpx.get(f"{PING_URL}/start", timeout=10) try: result = await Runner.run( starting_agent=my_agent, input="Run the nightly summary.", ) # signal success — closes any open incident httpx.get(PING_URL, timeout=10) return result except Exception as exc: # signal failure with exception detail httpx.post( f"{PING_URL}/fail", content=f"{type(exc).__name__}: {exc}", headers={"Content-Type": "text/plain"}, timeout=10, ) raise

Done — every scheduled run now reports in

LastPing receives the start and completion pings. A run that never starts is caught when the expected completion ping doesn't arrive within the grace window. Alerts go to email, Telegram, Slack, Discord, or a signed webhook. No monitor cap.


What this catches

The same durable detection engine as LastPing's cron monitoring — deadlines live in the database, so a restart never misses a due check.

  • Missed scheduled runs — scheduler crash, OOM kill, expired API key. No start ping in the expected window → incident.
  • Hung agent runs — the start ping fired but Runner.run() never returned; overrun detection opens an incident after the grace window.
  • Unhandled exceptions — the except block fires immediately, POSTing the exception type and message to the incident.
  • Recovery — the next successful run closes the incident automatically. No manual reset.
  • Agent self-registration via MCP — the agent can create its own monitor, set alerts, and wire pings into its run loop without a human in the loop.

The same pattern works for agents built with LangChain and CrewAI. For CI/CD pipelines, see GitHub Actions or the monitoring guides index. For the agent self-registration path, see the LastPing MCP server page.


Questions people ask

Front-loaded answers — the most important fact first.

  • How do I monitor an OpenAI Agents SDK agent running on a schedule?

    Wrap your Runner.run() call with a start ping before, a success ping after, and a fail POST in the exception handler. Create a heartbeat monitor in LastPing with your agent's schedule so a run that never starts also opens an incident. Or connect the LastPing MCP server and let the agent create and wire up its own monitor. Free, no cap.

  • Can the agent set up its own LastPing monitor?

    Yes. Add the LastPing MCP server (mcp.lastping.dev) to your agent's MCP server list. The agent can then call create_monitor and get_ping_instructions to create a heartbeat and receive ready-to-embed curl commands. The agent creates the monitor and instruments itself in one conversation — no human dashboard visit required.

  • What if the agent is async?

    Use httpx.AsyncClient for the ping calls inside an async context: async with httpx.AsyncClient() as client: await client.get(PING_URL). The ping endpoint accepts both GET and POST and responds in well under a second, so the async overhead is negligible.

  • How much failure detail can I attach to an incident?

    Up to 64 KB of plain text per /fail POST. In practice, that's the full exception traceback plus the last several hundred lines of context — enough to diagnose most agent failures without needing to dig into logs. The body is stored on the open incident and is never logged server-side.

  • Is this free?

    Yes. LastPing is free for individuals with no monitor cap. The MCP server at mcp.lastping.dev is included. LangChain and CrewAI agents work the same way.

AGENT-FIRST · FREE FOR INDIVIDUALS · MCP-NATIVE

Your agent's next missed run is already scheduled.

Three lines of Python or one agent prompt. First monitor wired up in under two minutes — and LastPing monitors itself the same way.