Agent Heartbeat: Automated Background Inspection for AI Agents

    This article explains an agent heartbeat pattern for unattended background checks: it runs at a fixed interval, uses a lightweight model, and notifies only when something is wrong. It covers how heartbeat differs from cron-style scheduling, configuration parameters, model registration, HEARTBEAT.md task files, production details, common pitfalls, and a practical rollout path.

    From hunting for information to being notified at the right time

    As AI agents enter everyday engineering work, a recurring gap is not query capability but timely reminders. Build status, dependency updates, test coverage, and backlog in background jobs are easy to fetch; the hard part is doing it continuously, reliably, and unattended.

    Two common approaches fall short. Manual polling is expensive and easy to miss. Cron-style schedules (minute, hour, day, month, weekday) make scripts run on time, but they do not solve who reads the output: every run produces a result, even when nothing is wrong, which leads to alert fatigue.

    Heartbeat is a middle path: it fires at a fixed interval, runs a lightweight check, and notifies only when there is an issue; otherwise it stays silent. That sentence is the core of the design.

    Heartbeat vs. traditional scheduled jobs

    They are complementary, not substitutes:

    Dimension Heartbeat Traditional scheduling
    Trigger Fixed interval Exact time expression
    Role Background monitoring, light checks Timed jobs, report generation
    Model Can use a dedicated lightweight model Usually the default model
    Results Notify on issues; silent otherwise Run and push every time
    Typical use Inspection, monitoring, reminders Digests, automated reports

    Selection rules:

    1. Choose heartbeat for quiet, always-on work. Long-running tasks that speak only on anomalies.
    2. Choose scheduling for exact timing. Example: a daily report at 09:00 is a business constraint.
    3. Choose scheduling for heavy work. Heartbeat should stay light; it is a poor fit for long, high-throughput batch jobs.

    Configuration: three parameters

    Heartbeat usually lives under agents.defaults.heartbeat:

    1. {
    2. "agents": {
    3. "defaults": {
    4. "heartbeat": {
    5. "every": "30m",
    6. "model": "lightweight-chat",
    7. "includeReasoning": false
    8. }
    9. }
    10. }
    11. }

    every (interval): string, default "30m". Supports minutes (m) and hours (h), e.g. "15m", "2h", "1h30m". Interval is a trade-off between detection delay and cost: 5–15 minutes for critical paths; 30 minutes to several hours for cheaper inspection summaries.

    model: string, default inherits the main model. Inspection semantics are usually simple (anomaly or not, notify or not). A small, fast model cuts cost and keeps inspection traffic from competing with interactive quotas.

    includeReasoning: boolean, default false. Useful when debugging prompts and false positives. Turn it off in production to avoid extra tokens and latency.

    Prerequisite: register the model first

    The heartbeat model must be registered with the provider (endpoint, credentials, protocol, metadata):

    1. {
    2. "models": {
    3. "providers": {
    4. "default": {
    5. "baseUrl": "https://<your-endpoint>/v1",
    6. "apiKey": "<your-key>",
    7. "api": "compatible-completions",
    8. "models": [
    9. {
    10. "id": "lightweight-chat",
    11. "name": "lightweight-chat",
    12. "contextWindow": 128000,
    13. "maxTokens": 4096
    14. }
    15. ]
    16. }
    17. }
    18. }
    19. }

    contextWindow and maxTokens matter: prompts and inspected snippets must fit. Long logs truncated by a small window cause bad judgments. Configure via a wizard or by editing the file. For hosted models, put secrets in a key manager or environment variables—do not hardcode them into the repo.

    Task file: decouple “what to check” from code

    On each beat, the agent reads HEARTBEAT.md at the workspace root, typically ~/.openclaw/workspace/HEARTBEAT.md. Scheduling policy and task semantics stay separate: change frequency in config, change checks in the file, without restarting.

    Template:

    1. # Inspection task
    2. ## Checks
    3. 1. Latest main-branch build status
    4. 2. Whether critical API error rate exceeds 1%
    5. 3. Whether pending reviews exceed 3
    6. ## Decision rules
    7. - All healthy: reply SILENT only, nothing else
    8. - Issues found: list items, impact, and suggested actions
    9. ## Constraints
    10. - Keep a single response under 200 words
    11. - Do not re-report the same issue within 24 hours

    Write a silent protocol (e.g. SILENT so “all clear” is machine-readable), a structured output format (for notifications or tickets), and a dedup window.

    Six production details

    1. Silence first. Notification value comes from scarcity.
    2. Idempotency and dedup. Periodic runs rediscover the same issue; suppress with issue fingerprint plus time window.
    3. Timeouts and retries. External APIs flap; use timeouts and limited backoff so query failures are not treated as business incidents.
    4. Cost guards. Lightweight model, bounded input, longer interval, plus a daily call cap.
    5. Observability. Log each run’s outcome, latency, and decision. Watch judgment and delivery separately so “nothing found” is distinct from “did not run.”
    6. Change history. Version config and HEARTBEAT.md so a false alarm maps to a specific change.

    Pitfalls and troubleshooting

    • Using heartbeat as a cron replacement for exact times or long jobs.
    • Always using the main model (cost, latency, quota).
    • No silent convention, so “all good” every 30 minutes gets muted.
    • Context too small; truncated inputs, wrong verdicts.
    • Secrets in config or task files.

    Check in order: config loaded → model registered and callable → task file read → decision logic and notification path.

    Combining with cloud primitives

    Heartbeat only discovers. Close the loop with logging for search and audit, metrics and alerts for thresholds, object storage for long-period reports, and queues or ticketing when humans must act. On a container platform and logging stack such as Baidu AI Cloud, you can reuse monitoring, alerting, and key management so heartbeat is a tenant-isolated, auditable service rather than a one-off script.

    Rollout

    Start with one high-frequency, low-complexity inspection. Add a lightweight model and silent protocol; watch false positives for 24 hours. Then add dedup and logging. Expand to builds, dependencies, reviews, and capacity, and keep reusable task templates. Heartbeat’s value is not how “smart” it is, but how light, quiet, and stable it stays—the qualities automated monitoring needs most.