What Is the Agentic OS Heartbeat Pattern? How to Keep Your AI Agent Proactive 24/7
The heartbeat pattern runs your AI agent on a schedule, gathers context from APIs, and takes action before you ask. Here's how to build it with Claude Code.
Reactive AI Is Already Outdated
Most AI agents today sit and wait. You type a message, they respond. You submit a form, they run. That’s useful, but it’s not what “agentic” really means.
The heartbeat pattern changes that. It’s a design approach where your AI agent wakes up on a schedule, checks what’s happening across your systems, decides what matters, and takes action — without you asking. The result is an agent that behaves more like a diligent colleague than a chatbot.
This article explains what the agentic OS heartbeat pattern is, how it works, when to use it, and how to implement it using tools like Claude Code.
What the Heartbeat Pattern Actually Is
The term “heartbeat” comes from systems programming, where a heartbeat signal is a periodic pulse that confirms a process is alive and functioning. In agentic AI, the concept is repurposed: instead of just checking for liveness, each “beat” is an opportunity for the agent to observe, reason, and act.
The pattern has three core properties:
- Scheduled execution — The agent runs at a fixed or dynamic interval (every 15 minutes, every hour, at 8 AM daily, etc.)
- Context gathering — At the start of each cycle, the agent fetches fresh data from APIs, databases, calendars, inboxes, or any other source it needs
- Autonomous action — Based on what it finds, the agent decides what to do: send an alert, update a record, trigger a workflow, draft a message, or do nothing at all
This is sometimes called a “polling loop” in traditional automation, but the key difference is the reasoning layer. A standard cron job executes the same fixed logic every time. A heartbeat agent uses a language model — typically Claude — to evaluate context and make judgment calls.
The Four Phases of a Heartbeat Cycle
Each time the agent “ticks,” it runs through a consistent set of phases. Understanding these phases helps you design and debug agents more effectively.
Phase 1: Wake
The scheduler fires the agent. This could be a cron expression, a time-based trigger in your automation platform, or a loop in your application code. The agent initializes, loads its configuration, and prepares to gather data.
No reasoning happens yet. This phase is just “wake up and get ready.”
Phase 2: Observe
The agent queries every data source it needs to do its job. This might include:
- Calling a CRM API to check for new deals or status changes
- Reading the last 24 hours of support tickets
- Pulling Slack messages from a specific channel
- Fetching a weather forecast or market data feed
- Checking a calendar for upcoming deadlines
- Reading from a database or spreadsheet
The observation phase is where freshness matters. You’re not relying on cached state — you’re looking at what’s true right now.
Phase 3: Reason
The gathered context gets passed to a language model (Claude, in most production heartbeat implementations). The model’s job is to evaluate what it’s seeing and decide whether any action is warranted.
This is the step that distinguishes a heartbeat agent from a simple cron job. The model can:
- Identify patterns or anomalies in the data
- Compare current state against previous state
- Weigh multiple signals before deciding
- Apply nuanced rules that would be brittle to hard-code
Claude is particularly well-suited here because its extended context window lets you pass in large amounts of observational data without chunking or summarizing prematurely.
Phase 4: Act
If the reasoning phase determines that action is needed, the agent executes. Actions can range from lightweight (logging a note, updating a field) to high-impact (sending an email, creating a ticket, triggering a downstream workflow).
Well-designed heartbeat agents follow a principle of minimal footprint: they do what’s necessary and nothing more. Irreversible or high-stakes actions should require confirmation or use guardrails.
After acting, the agent logs its decision, stores any relevant state, and goes back to sleep until the next cycle.
Why This Pattern Matters for Multi-Agent Systems
The heartbeat pattern becomes more powerful when you think about it in a multi-agent context. A single heartbeat agent monitoring one data source is useful. But a network of agents, each running on its own schedule and monitoring its own slice of the world, creates something much more capable.
In an agentic OS model, different agents act as persistent background processes — like services running on an operating system. Each has its own responsibility, its own heartbeat rate, and its own set of actions it’s authorized to take. An orchestrator agent can coordinate their outputs.
This is the direction Anthropic has been moving with Claude’s design. The model is built with agentic use cases in mind: it handles long tool-call sequences gracefully, maintains context across multi-step decisions, and is trained to be cautious about irreversible actions. Those properties translate well to heartbeat agents that need to act repeatedly without constant human supervision.
When to Use the Heartbeat Pattern
Not every problem needs a heartbeat agent. Here’s a quick way to decide.
Good fit:
- You need the agent to notice something before a human would
- The data you care about changes continuously (market prices, support queues, deployment status)
- The required action is time-sensitive (escalating an outage, following up on a deal before it goes cold)
- You’re building something that needs to feel proactive to end users
Not a good fit:
- The task only makes sense when initiated by a user
- The data source only updates on demand
- The actions are expensive to reverse and you want explicit human approval each time
Some common use cases where heartbeat agents genuinely shine:
- Sales monitoring — Check CRM for stalled deals and send nudge emails automatically
- DevOps alerting — Poll error logs and notify Slack when anomaly rates spike
- Content moderation — Review new submissions and flag rule violations without manual review
- Meeting prep — 30 minutes before each calendar event, pull relevant context and brief the attendee
- Financial monitoring — Watch for unusual spending patterns and alert the right person
- Customer health scoring — Reassess churn risk daily based on usage data and trigger retention workflows
How to Build a Heartbeat Agent with Claude Code
Building a heartbeat agent from scratch involves a few components. Here’s a practical walkthrough using Claude Code as the reasoning layer.
Prerequisites
- Claude API access (via Anthropic’s API directly or through a platform)
- Access to the data sources you want to observe (APIs, databases, etc.)
- A scheduler (cron on a server, a cloud scheduler, or a platform with native scheduling)
- Storage for agent state between cycles (so the agent can compare “now” to “last time”)
Step 1: Define the Agent’s Observation Scope
Before writing any code, answer these questions:
- What data sources does the agent need to observe?
- How frequently should it check each source?
- What signals indicate that action is needed?
- What actions is the agent authorized to take?
Write these down explicitly. Ambiguity here causes agents that act too often, not enough, or in the wrong situations.
Step 2: Build the Observation Layer
Create functions that fetch fresh data from each source. Keep these modular — one function per data source. Errors in one fetch shouldn’t crash the entire cycle.
async function observeTicketQueue() {
const tickets = await supportApi.getTickets({
status: 'open',
since: lastCheckTime
});
return tickets;
}
async function observeCRMDeals() {
const deals = await crmApi.getDeals({
stage: 'proposal',
lastActivityBefore: daysAgo(3)
});
return deals;
}
Step 3: Build the Reasoning Prompt
Construct a prompt that gives Claude everything it needs to make a good decision. This usually includes:
- Current observations (the fresh data)
- Historical context (what the agent did last cycle)
- Decision criteria (what counts as “worth acting on”)
- Available actions (what the agent is allowed to do)
const systemPrompt = `
You are a sales operations agent. Your job is to identify deals that
need follow-up and take appropriate action.
Available actions:
- send_follow_up_email(dealId, message)
- create_task(dealId, description, dueDate)
- escalate_to_manager(dealId, reason)
- no_action()
Rules:
- Only follow up on deals where the last activity was more than 3 days ago
- Escalate deals worth over $50,000 that have been stalled for 7+ days
- Never send more than one email to the same contact in a 24-hour period
`;
const userPrompt = `
Current deals needing attention:
${JSON.stringify(deals, null, 2)}
Recent actions taken (last 24 hours):
${JSON.stringify(recentActions, null, 2)}
What actions, if any, should be taken right now?
`;
Step 4: Parse and Execute Actions
Claude returns structured output describing what should happen. Your execution layer parses that output and runs the actions.
Use structured output (JSON mode or tool use) rather than free text. It makes action parsing reliable and deterministic.
Step 5: Log Everything
Every heartbeat cycle should produce a log entry that captures:
- When the cycle ran
- What was observed
- What Claude decided
- What actions were taken (or why no action was taken)
This isn’t just for debugging — it’s how you build trust in the agent over time. When something goes wrong, the logs let you trace exactly what happened and why.
Step 6: Schedule the Loop
Deploy the agent to run on whatever schedule fits the use case. For a sales monitoring agent, hourly is probably sufficient. For an error alerting agent, every 5 minutes might be more appropriate.
If you’re using a cloud environment, services like AWS EventBridge, Google Cloud Scheduler, or Vercel Cron work well. On-premises, a standard cron job does the job.
Common Mistakes (and How to Avoid Them)
Skipping State Persistence
If the agent doesn’t remember what it did last cycle, it will repeat actions indefinitely. Always store state between runs — at minimum, record what actions were taken and when.
Passing Too Little Context
If Claude doesn’t have enough information to make a good decision, it will either act on incomplete data or fail to act when it should. Be generous with context in the observation phase.
Making Every Action Irreversible
Design your action set with reversibility in mind. Drafting an email and queuing it for human approval is better than sending immediately when you’re still tuning the agent’s behavior.
Setting the Heartbeat Too Fast
Running every minute when hourly would suffice wastes compute and can cause rate-limiting issues with external APIs. Start conservatively and increase frequency only when you have evidence it’s needed.
No Circuit Breaker
If an external API goes down or returns garbage data, the agent should fail gracefully — not take wrong actions based on corrupted observations. Add validation checks before passing data to the reasoning layer.
How MindStudio Makes Heartbeat Agents Easier to Build
Building the heartbeat pattern from scratch requires wiring together a scheduler, multiple API connections, a language model, action execution logic, state storage, and logging. That’s a full engineering project.
MindStudio’s autonomous background agents handle most of that infrastructure for you. You can create a scheduled agent visually — no code required for the basic structure — and connect it to over 1,000 pre-built integrations. The scheduling, retry logic, and execution environment are all managed for you.
Within the agent, you choose which AI model runs the reasoning step. Claude is available out of the box alongside 200+ other models, and you don’t need to set up your own API keys or manage billing separately.
For developers who want to go deeper, MindStudio’s Agent Skills Plugin (@mindstudio-ai/agent) lets you call MindStudio’s capabilities from any agentic framework — including Claude Code, LangChain, or a custom agent. Methods like agent.sendEmail(), agent.searchGoogle(), or agent.runWorkflow() give Claude Code agents a clean interface to over 120 typed capabilities, so the reasoning layer can focus on what to do rather than how to connect to every service.
If you want to try building your first scheduled agent, you can start free at mindstudio.ai. The average build takes under an hour for a working prototype.
Frequently Asked Questions
What is the heartbeat pattern in AI agents?
The heartbeat pattern is a design approach where an AI agent runs on a regular schedule — its “heartbeat” — rather than waiting for user input. Each cycle, the agent gathers fresh data from relevant sources, passes that data to a language model for reasoning, and takes action if something warrants it. The result is an agent that stays proactive rather than reactive.
How is the heartbeat pattern different from a cron job?
A cron job executes fixed, predetermined logic on a schedule. A heartbeat agent also runs on a schedule, but it uses a language model in the middle to evaluate what it observes and decide what to do. That reasoning layer lets the agent handle situations that would be difficult or impossible to anticipate with hard-coded rules.
Why is Claude recommended for heartbeat agents?
Claude handles extended context well, which matters when the observation phase pulls in large amounts of data. It also follows nuanced instructions reliably and is designed with agentic use cases in mind — including being cautious about irreversible actions. Anthropic’s model documentation covers the specific capabilities relevant to agentic workloads.
How do I prevent a heartbeat agent from taking the same action repeatedly?
State persistence is the answer. After each cycle, log what actions were taken. At the start of the next cycle, pass that action history to the reasoning prompt so the model knows what’s already been done. For things like emails, enforce a cooldown period in your prompt instructions and check against it before allowing the action.
How frequently should a heartbeat agent run?
It depends entirely on the use case. Financial monitoring or error alerting might need a 1–5 minute interval. Sales follow-up or content moderation might be fine at hourly or even daily. The right frequency is the slowest one where you’d still catch important events before they become problems. Start slow and tune up from there.
Can heartbeat agents work in a multi-agent system?
Yes, and that’s where they get most interesting. In a multi-agent architecture, different heartbeat agents can monitor different parts of your system independently. An orchestrator agent can receive signals from each and coordinate responses. This mirrors how operating systems manage multiple background processes simultaneously.
Key Takeaways
- The heartbeat pattern runs an AI agent on a schedule so it can observe, reason, and act without waiting for user input.
- Each cycle has four phases: wake, observe, reason, and act. The reasoning phase — powered by a model like Claude — is what separates this from basic automation.
- State persistence between cycles is essential. Without it, agents repeat actions and lose context.
- Design action sets with reversibility in mind, especially while the agent’s behavior is still being tuned.
- The pattern scales well in multi-agent systems where different agents monitor different domains.
- Platforms like MindStudio let you build scheduled heartbeat agents visually, without setting up infrastructure from scratch — try it free to see how quickly a working prototype comes together.