Paperclip

Paperclip Heartbeats & Scheduled Execution👨‍💻

Paperclip agents don't run continuously. They wake on a schedule, check their assigned work, execute through their adapter, and go back to sleep. That cycle is called a heartbeat.

This matters for three reasons. First, cost: agents only burn tokens during active heartbeats, not 24/7. Second, context: sessions persist between heartbeats, so agents pick up where they left off instead of re-reading everything from scratch. Third, control: you decide exactly when and how often each agent works. No surprises on your API bill, no agents going rogue at 3am.

Key Takeaways

  • 1A heartbeat is one execution cycle. The agent wakes up, checks its issue backlog, picks up work, runs through the adapter, and reports results. Between heartbeats, it consumes nothing -- zero tokens, zero compute.
  • 2You configure heartbeat frequency per agent. A CI/CD agent might run every 5 minutes. A code review agent every 30 minutes. A strategy agent once a day. Match the schedule to how urgent the agent's work actually is.
  • 3Agents don't start from scratch each time. The adapter returns a sessionId that Paperclip stores, and on the next heartbeat, the same session picks back up. The agent remembers what it was working on.
  • 4Every run records token usage, model costs, and execution time. Paperclip enforces monthly budgets per agent -- hit the limit and heartbeats get throttled until the next cycle. No more surprise bills from a runaway agent.
  • 5Heartbeats aren't the only way to wake an agent. Events like task assignments, @-mentions from other agents, or external webhooks can trigger a run immediately. You get responsiveness without paying for constant polling.
  • 6Each heartbeat writes an immutable audit log: which issues were checked out, what the agent did, which tools it called, how many tokens it burned, and whether it succeeded. Useful when something goes wrong at 2am and you need to trace what happened.

Master paperclip heartbeats & scheduled execution

Take the Paperclip Fundamentals course with hands-on lessons and challenges.

Examples

Configuring heartbeat schedule for an agent

bash

heartbeat.intervalMinutes controls how often the agent wakes up. Set enabled to false to pause the agent without deleting it. The monthly budget acts as a hard ceiling -- even running every 15 minutes, this agent can't spend more than $30/month on tokens.

The heartbeat execution lifecycle

typescript

Five steps, every time. The atomic checkout in step 2 is what prevents two agents from grabbing the same issue. And session persistence in step 4 is why agents can work on multi-step tasks across heartbeats without losing their place.

Viewing heartbeat history and cost data

bash

The runs API gives you the full heartbeat history -- timing, token usage, costs, outcomes. Notice the SKIPPED run: the agent woke up, checked its backlog, found nothing to do, and went back to sleep. If you see a lot of those, the agent either needs more work or a longer heartbeat interval.

Environment variables injected during heartbeat execution

typescript

These environment variables tell the agent runtime everything it needs: who it is, which company it belongs to, what run it's executing, and how to talk back to Paperclip. The session ID is what makes continuity work -- the runtime uses it to resume its previous state.

Common Mistakes

Mistake:

Setting heartbeat intervals too short (every 1-2 minutes) for agents that don't need real-time responsiveness, burning through budgets on idle checks

Fix:

Match the interval to the role. Code review agents? Every 30 minutes is fine. Strategy agents? Once a day. If something is truly urgent, use event-based triggers instead of cranking up the heartbeat frequency.

Mistake:

Setting clearSession to true after every heartbeat, forcing the agent to restart its context from scratch each time

Fix:

Leave clearSession as false unless you have a specific reason. Session continuity is the whole point -- without it, your agent re-reads the entire codebase every heartbeat, which wastes time and tokens.

Mistake:

Ignoring SKIPPED runs in the heartbeat history and missing the signal that an agent has nothing to do

Fix:

Watch the COMPLETED-to-SKIPPED ratio. If an agent is skipping most of its heartbeats, its backlog is empty. Either give it more work, slow down its heartbeat, or pause it. No point paying for an agent to wake up and go back to sleep.

Mistake:

Not setting monthly budgets and letting a misconfigured agent spend unlimited tokens

Fix:

Always set a monthlyBudget. Paperclip enforces it atomically -- once the budget is gone, heartbeats get throttled. Start low and raise it based on what you actually see the agent spending.

Best Practices

  • Start with 30-60 minute intervals and only go shorter if work is piling up faster than agents can clear it. The temptation to set everything to 5 minutes is real -- resist it. You'll burn budget on mostly-idle checks.
  • For urgent work, use event triggers instead of shortening heartbeat intervals. A webhook from your CI pipeline or an @-mention from another agent wakes the agent immediately without changing its baseline schedule.
  • Check per-agent cost data weekly. Paperclip tracks token usage and costs per run, so you can quickly spot which agents are expensive and whether that expense is justified.
  • Don't clear sessions between heartbeats unless you have a reason to. Session continuity is how agents handle multi-step work -- they remember what they did last time and pick up where they left off.
  • Set up alerts at 50%, 80%, and 100% budget thresholds. You don't want to find out an agent got throttled because it ran out of budget three days ago.
  • When something goes wrong, the audit trail is your best friend. Every heartbeat logs what was checked out, what tools were called, and how many tokens were spent. Start there.

Summary

Heartbeats are how Paperclip agents work: wake up, grab an issue, do the work, report back, go to sleep. You get cost control (agents only spend tokens when they're actually running), context continuity (sessions persist across heartbeats), and predictable scheduling. The practical advice: start with longer intervals, use event triggers for anything time-sensitive, always set monthly budgets, and keep an eye on your SKIPPED-to-COMPLETED ratio to know when agents need more work or less frequent heartbeats.

Practice Paperclip with hands-on challenges

Learn paperclip heartbeats & scheduled execution hands-on in your IDE

Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.

Related Concepts

Master Paperclip with Stanza

Interactive lessons and challenges, right in your code editor.

Check the free courses. No credit card.