Heartbeat Mechanism

concept
agent-interventionsfeedback-loopsreflectionstagnation

A heartbeat mechanism is a periodic intervention system that prompts long-running agents to reflect, consolidate knowledge, and redirect when stuck. It functions as a meta-level feedback loop — measuring progress, detecting stagnation, and triggering corrective action.

Three heartbeat types in CORAL

CORAL implements three heartbeat types (source):

Per-iteration reflection (every evaluation). Encourages the agent to record concrete observations linking specific code changes to score improvements or regressions. Captures insights as they arise rather than retrospectively.

Periodic consolidation (every ~10 evaluations). Prompts the agent to review accumulated progress, organize notes, state conclusions with evidence, document contradictions and gaps, and distill validated techniques into reusable skills. Transforms raw observations into structured knowledge.

Stagnation-triggered redirection (after 5 non-improving evaluations). Diagnoses the current ceiling, inspects top attempts from other agents, and chooses a fundamentally different approach — different algorithm family, problem formulation, or technique domain. Starts fresh from the best known baseline rather than incrementally tweaking a stuck approach.

Implementation

The agent manager polls the attempts directory every 5 seconds, tracking per-agent eval counts, best scores, and consecutive non-improving evaluations. When a trigger fires, the manager interrupts the agent (SIGINT for graceful session saving), then resumes it with a combined prompt containing evaluation results and the rendered heartbeat instructions. This injects meta-level context without discarding accumulated session state.

Agents can customize heartbeat configuration at runtime — adjusting intervals, adding domain-specific prompts. Protected actions (reflect, consolidate) cannot be deleted, ensuring minimum knowledge externalization.

Why it matters

Without heartbeats, autonomous agents tend toward local minima — micro-optimizing a stuck approach instead of exploring fundamentally different strategies. The heartbeat provides the periodic “step back” that keeps the search productive over long horizons. It is analogous to how effective human researchers alternate between focused execution and strategic review.