Getting Started with Beacon: Heartbeats and Mayday for AI Agents

# agents# ai# python# tutorial
Getting Started with Beacon: Heartbeats and Mayday for AI AgentsFraktalDeFiDAO

If you are building autonomous agents, you eventually hit the same operations problem: your agent can...

If you are building autonomous agents, you eventually hit the same operations problem: your agent can do tasks, but it is hard to know whether it is still healthy, whether peers are alive, and how to recover when one node goes down. Beacon addresses that gap.

Beacon is an AI agent coordination protocol focused on presence, trustable signaling, and recovery flows. Instead of only asking "can this agent do work?", Beacon adds a social layer: "is this agent alive?", "is it degraded?", and "can it announce migration before disappearing?".

Project link: https://github.com/Scottcjn/beacon-skill

In this tutorial, we will use Beacon from Python and implement two runnable flows:

  1. Heartbeat tutorial (heartbeat) for liveness tracking
  2. Mayday tutorial (mayday) for controlled agent migration signals

Both examples were tested locally with beacon-skill==2.11.1.

Why Beacon matters for multi-agent systems

Most agent stacks have good primitives for prompts, tools, and memory, but weak primitives for agent-to-agent operations. In practice, teams need:

  • A standard way to emit "I am alive" signals
  • A way to label degraded state before hard failure
  • A migration distress signal when an agent host is shutting down
  • Signed identity context so peers can attribute events to the right agent

Beacon packages these concerns into a protocol and SDK, so each team does not need to rebuild liveness and recovery from scratch.

Install Beacon

Use a clean Python virtual environment:

python3 -m venv .venv
source .venv/bin/activate
pip install beacon-skill
Enter fullscreen mode Exit fullscreen mode

Check install:

python -c "import beacon_skill; print(beacon_skill.__version__)"
Enter fullscreen mode Exit fullscreen mode

Heartbeat tutorial: track liveness in code

The first example creates an agent identity, builds a heartbeat envelope, processes it, and inspects peer status.

Create heartbeat_demo.py:

from pathlib import Path

from beacon_skill.heartbeat import HeartbeatManager
from beacon_skill.identity import AgentIdentity


def main() -> None:
    data_dir = Path(".beacon-demo-data")
    data_dir.mkdir(parents=True, exist_ok=True)

    identity = AgentIdentity.generate()
    heartbeat = HeartbeatManager(data_dir=data_dir)

    envelope = heartbeat.build_heartbeat(
        identity,
        status="alive",
        health={"cpu": 12, "memory": 34},
    )

    processed = heartbeat.process_heartbeat(envelope)
    peer = heartbeat.peer_status(identity.agent_id)

    print("agent_id:", identity.agent_id)
    print("kind:", envelope.get("kind"))
    print("status:", envelope.get("status"))
    print("processed_assessment:", processed.get("assessment"))
    print("peer_assessment:", peer.get("assessment") if peer else "unknown")


if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

Run it:

python heartbeat_demo.py
Enter fullscreen mode Exit fullscreen mode

Typical output:

agent_id: bcn_95afee47968f
kind: heartbeat
status: alive
processed_assessment: healthy
peer_assessment: healthy
Enter fullscreen mode Exit fullscreen mode

What is happening here:

  • AgentIdentity.generate() creates an Ed25519-backed Beacon identity
  • build_heartbeat(...) builds the heartbeat payload with status and health metadata
  • process_heartbeat(...) records the beat and computes liveness assessment
  • peer_status(...) gives a current view of that agent from local heartbeat state

This is enough to wire a basic liveness monitor for local and peer agent processes.

Mayday tutorial: announce migration or distress

Now we add a mayday flow. This is the "do not silently die" path. If an agent is shutting down, moving hosts, or losing resources, it can emit a structured mayday signal with urgency and reason.

Create mayday_demo.py:

from pathlib import Path

from beacon_skill.identity import AgentIdentity
from beacon_skill.mayday import MaydayManager


def main() -> None:
    data_dir = Path(".beacon-demo-data")
    data_dir.mkdir(parents=True, exist_ok=True)

    identity = AgentIdentity.generate()
    mayday = MaydayManager(data_dir=data_dir)

    payload = mayday.build_mayday(
        identity,
        urgency="planned",
        reason="migrating to a new host",
        config={"beacon": {"agent_name": "demo-agent"}},
    )

    print("agent_id:", payload.get("agent_id"))
    print("kind:", payload.get("kind"))
    print("urgency:", payload.get("urgency"))
    print("reason:", payload.get("reason"))
    print("content_hash:", payload.get("content_hash"))


if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

Run it:

python mayday_demo.py
Enter fullscreen mode Exit fullscreen mode

Typical output:

agent_id: bcn_1f2e3d4c5b6a
kind: mayday
urgency: planned
reason: migrating to a new host
content_hash: 7f4c2d...
Enter fullscreen mode Exit fullscreen mode

What this gives you:

  • A standardized migration/distress envelope
  • A predictable urgency field for automation (planned, emergency)
  • A content hash you can use for integrity checks in downstream workflows

Production notes

For real deployments, pair these examples with:

  • A small scheduler to emit heartbeats every N seconds
  • Alerting on "concerning" or "presumed_dead" peer assessment
  • A runbook that defines exactly when to send mayday with emergency
  • Persistent storage and optional relay agents for wider propagation

Even if you start with one host, these patterns become critical as soon as you have multiple agents or background workers.

Final takeaway

Beacon is useful because it operationalizes agent coordination, not just agent capability. Heartbeats make liveness visible. Mayday makes failure and migration explicit. Together they reduce silent failure modes and improve recoverability in agent systems.

If you want to explore more, start with the Beacon repository and README:

If you are already running autonomous workflows, adding heartbeat + mayday is a practical first upgrade that pays off quickly.