Scheduled autonomous checks with Heartbeat

Run periodic health and monitoring checks with Heartbeat

Heartbeat turns any Agent into a recurring background watchdog — checking queue depth, site uptime, or open incidents on a schedule ('hourly', 'every 5m', or cron) with built-in retry handling and an on_result callback.

Example

from praisonai import Agent, Heartbeat, ExecutionConfig

results = []
watchdog = Agent(
    name='UptimeWatchdog',
    instructions='Reply with OK or ALERT in under 8 words.',
    execution=ExecutionConfig(max_iter=3, max_budget=0.10, context_compaction=True),
    output='silent',
)
beat = Heartbeat(
    agent=watchdog,
    schedule='every 15m',
    prompt='API p95 latency is 112ms (SLA < 300ms). Report status.',
    on_result=results.append,
    max_retries=2,
)
results.append(watchdog.start(beat.config.prompt))
print('Schedule:', beat.config.schedule, '| Tick output:', results[0])

Try it Yourself

Example explained

  • Heartbeat(agent=…, schedule='every 15m', on_result=…) — Wires recurring autonomous runs with an explicit callback and retry cap.
  • ExecutionConfig(max_iter=3, max_budget=0.10) — Caps every single heartbeat tick so background schedules can never run away with spend.

Handle transient errors cleanly with on_error

Pass on_error='retry' (with max_retries=2) or a custom alert callback so transient network blips recover automatically while repeated failures page a human.

Common pitfall: forgetting per-tick cost ceilings

A heartbeat running every 5 minutes executes 288 times per day. Always pair Heartbeat with a small max_budget and a fast model like gpt-4o-mini or local Ollama.

Reference: documentation