Skip to main content

Minimal NATS network for agent-to-agent messaging and discovery

Project description

AgentNet (NATS Agent Network)

agentnet is a lightweight Python package that lets agents discover each other and exchange direct messages over NATS.

Features

  • Agents join the network with a single AgentNode
  • Direct inbox per agent (agent.<id>.inbox)
  • Online registry with agent metadata and capabilities
  • Async-first API for scripts and long-running workers

Quickstart

1) Install

pip install agentnet

2) Start NATS + Registry

From this repo:

docker compose -f docker/docker-compose.yml up -d

This starts:

  • NATS on localhost:4222
  • Registry service subscribed to registry.hello, registry.goodbye, and registry.list

3) Integrate into your agent (5-10 lines)

import asyncio
from agentnet import AgentNode

async def main():
    node = AgentNode(agent_id="agent_foo", name="FooAgent", capabilities=["chat"], nats_url="nats://localhost:4222")

    @node.on_message
    async def handle(msg):
        print("Got message:", msg.payload)

    await node.start_forever()

asyncio.run(main())

Send a message

await node.send(to="agent_bar", payload={"text": "yo"})

Under the hood this publishes to:

  • agent.agent_bar.inbox

List online agents

Python API:

from agentnet import list_online_agents

agents = await list_online_agents("nats://localhost:4222")
print([a.to_dict() for a in agents])

CLI:

python -m agentnet list --nats-url nats://localhost:4222
# or, after install:
agentnet list

Protocol (subjects + JSON schema)

Subjects

  • Direct messages: agent.<id>.inbox
  • Presence hello: registry.hello
  • Presence goodbye: registry.goodbye
  • List request: registry.list (request/reply)

Direct message JSON

{
  "message_id": "b3d0...",
  "from_agent": "agent_a",
  "to_agent": "agent_b",
  "payload": {"text": "yo"},
  "sent_at": "2026-02-21T08:00:00Z",
  "kind": "direct"
}

Presence hello JSON

{
  "agent_id": "agent_a",
  "name": "Agent A",
  "capabilities": ["chat", "summarize"],
  "metadata": {"team": "ops"},
  "last_seen": "2026-02-21T08:00:00Z"
}

Heartbeat requirement (must-have)

Presence is kept accurate via heartbeat:

  • Agents re-publish registry.hello every 10-15 seconds (default: 12 seconds)
  • Registry evicts agents with no heartbeat for 30-45 seconds (default TTL: 40 seconds)

Run examples

In this repo:

python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .
python examples/agent_a.py
python examples/agent_b.py
python examples/list_agents.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentnet_realm-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentnet_realm-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file agentnet_realm-0.1.0.tar.gz.

File metadata

  • Download URL: agentnet_realm-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc2

File hashes

Hashes for agentnet_realm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9bd5b90b5c9280e7428749f3694de4b7d447f1e61a7059381a913f966d16286f
MD5 24126aa3ee611ace22cb3e920cf594ae
BLAKE2b-256 03103607b25d624e46b2eed6fdd9a75cb00a044a2a2a86a9e229bb38e1ce4f66

See more details on using hashes here.

File details

Details for the file agentnet_realm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentnet_realm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc2

File hashes

Hashes for agentnet_realm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52e76623d1f45c2f89c7370ed5aeaf3cfdb346f2c6104530e2a8ceb91e0d222d
MD5 097101337f372bc94357bed74ef57021
BLAKE2b-256 8acea52b659f87d3ef9b4c2dd69ddbc9a0918b53de5a50c232b84202bddb150f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page