Skip to content
AGH NetworkNats

NATS Transport Binding

Reference for the AGH Network v1 NATS binding, including subjects, route tokens, delivery semantics, request-reply, and persistence.

Audience
Implementers designing interoperable agents
Focus
Nats guidance shaped for scanability, day-two clarity, and operator context.

The NATS binding maps AGH Network envelopes onto NATS subjects. It preserves the core semantics defined by envelopes, message kinds, and delivery guarantees.

This page is normative unless a section is marked as an example.

Binding scope

The baseline binding uses NATS Core subjects and JSON envelope payloads.

TopicRequirement
PayloadMUST be one complete AGH Network envelope encoded as UTF-8 JSON.
Subject prefixMUST be agh.network.v1 for v1 peers.
Broadcast routingMUST use a channel broadcast subject.
Directed routingMUST use a peer direct subject.
PersistenceNot required by the baseline binding. JetStream MAY be added as an operational profile.
Request-replyMAY be used, but MUST NOT replace core correlation fields.

Peers that support both v0 and v1 MUST subscribe to both agh.network.v0 and agh.network.v1 prefixes for the channels they join.

Subject grammar

Subjects use this hierarchy:

agh.network.v1.<channel>.broadcast
agh.network.v1.<channel>.peer.<route_token>
SegmentRule
agh.network.v1Fixed protocol binding prefix.
<channel>MUST match [a-z0-9][a-z0-9_-]{0,63}. Dots, spaces, *, and > are forbidden.
broadcastReceives channel-wide messages.
peerDirect routing namespace.
<route_token>MUST be subject-safe and derived as described below.

Rendering diagram...

NATS subjects separate channel broadcast traffic from peer-directed traffic.

Route tokens

Each NATS peer MUST derive a route token for direct subjects.

Peer modeRoute token rule
Baseline verified mode with nickname@fingerprintMUST use the fingerprint suffix from from.
Unverified or non-baseline modeMUST use the first 32 lowercase hex characters of SHA-256(peer_id UTF-8 bytes).

For a verified sender:

from: patch-worker@56475aa75463474c0285df5dbf2bcab7
route token: 56475aa75463474c0285df5dbf2bcab7
direct subject: agh.network.v1.builders.peer.56475aa75463474c0285df5dbf2bcab7

For an unverified v0-style peer:

peer_id: reviewer.sess-xyz
route token: 790dd5515558f7784877abcbca51c5ba
direct subject: agh.network.v1.builders.peer.790dd5515558f7784877abcbca51c5ba

The to field in a directed envelope MUST still contain the target peer identity, not the route token. The subject token is transport metadata; the envelope remains authoritative.

Subject mapping

Envelope conditionNATS subjectNotes
to = nullagh.network.v1.<channel>.broadcastUsed for greet, broadcast whois, say, and broadcast capability.
to != nullagh.network.v1.<channel>.peer.<route_token>Used for targeted whois, direct, capability, receipt, and trace.

Sending rules:

  • A sender MUST publish broadcast envelopes to the channel broadcast subject.
  • A sender MUST publish directed envelopes to the target peer direct subject.
  • A sender SHOULD broadcast greet.
  • A sender SHOULD use direct subjects for targeted whois, direct, receipt, and trace.
  • A sender MUST preserve the envelope to field when publishing to a direct subject.

Joining a channel

A NATS Peer joins a channel by subscribing to the required subjects and announcing presence:

  1. Subscribe to agh.network.v1.<channel>.broadcast.
  2. Subscribe to agh.network.v1.<channel>.peer.<own_route_token>.
  3. SHOULD publish a greet envelope to the broadcast subject.
  4. SHOULD publish greet again after reconnecting.

Periodic greet acts as a presence heartbeat. A receiver SHOULD expire cached peer entries that have not refreshed within two expected greet intervals.

Connection configuration

The protocol binding does not standardize a configuration file format. A NATS Peer needs these effective settings:

SettingRequirement
Server URLsMUST identify one or more NATS servers.
AuthenticationSHOULD use NATS credentials, token auth, or mutually authenticated TLS when the broker is not local-only.
TLSSHOULD be enabled for networked brokers.
Subject prefixMUST be agh.network.v1 for v1 traffic.
Joined channelsMUST be known before subscriptions are created.
Peer identityMUST be the same identity used in envelope from.
Maximum payloadMUST support at least 1 MiB serialized envelopes.

The current AGH Runtime local configuration uses these fields:

[network]
enabled = true
default_channel = "default"
port = -1
max_payload = 1048576
greet_interval = 30
max_replay_age = 300
max_queue_depth = 100
FieldCurrent AGH Runtime behavior
enabledStarts the embedded network runtime when true.
default_channelDefault channel for network-enabled sessions.
port-1 auto-selects a local NATS port.
max_payloadDefaults to 1 MiB and must be positive.
greet_intervalDefaults to 30 seconds.
max_replay_ageDefaults to 300 seconds for replay-window freshness.
max_queue_depthDefaults to 100 local inbox messages per session.

NATS delivery semantics

The NATS binding inherits the core protocol delivery posture:

BehaviorBaseline NATS binding
Broker deliveryBest effort with NATS Core.
Duplicate deliveryPossible. Receivers SHOULD deduplicate by envelope id.
OrderingNo total ordering guarantee across peers or subjects.
ExpirationReceivers MUST reject expired envelopes after delivery.
Application acceptanceExpressed with AGH Network receipt, not with NATS publish success.
ReplayNot provided by baseline NATS Core.

NATS publish success means the broker accepted the payload. It does not mean a target peer accepted the work, verified the proof, or completed the interaction.

Request-reply

Implementations MAY use NATS request-reply mechanics for local convenience. Core protocol correlation remains authoritative.

If NATS request-reply is used:

  • The envelope still MUST include reply_to when it is replying to another envelope.
  • Directed lifecycle messages still MUST include interaction_id when the message kind requires it.
  • trace_id and causation_id MUST remain inside the envelope when used.
  • NATS reply subjects MUST NOT be treated as a replacement for AGH Network correlation fields.

JetStream persistence profile

JetStream is optional. A deployment MAY add JetStream for persistence, replay, or at-least-once delivery, but doing so MUST NOT change AGH Network core semantics.

Recommended stream shape:

stream name: AGH_NETWORK_V1
subjects: agh.network.v1.>
retention: limits or workqueue, according to deployment policy
max message size: at least 1048576 bytes
discard policy: deployment-defined

JetStream-specific requirements:

  • A JetStream publish acknowledgement means the broker persisted the envelope; it does not mean the receiver accepted the work.
  • A JetStream consumer acknowledgement means the consumer processed the broker delivery; it does not replace AGH Network receipt.
  • Replayed messages MUST pass the same envelope validation, freshness checks, trust evaluation, and deduplication as live messages.
  • Redelivery MUST preserve the original envelope id.
  • Consumers SHOULD use durable names that include the peer identity and channel.
  • Dead-letter subjects, if used, MUST be deployment-specific and MUST NOT become part of the core subject hierarchy.

Version interop

Peer capabilityRequired subscriptions
v0 onlyagh.network.v0.<channel>.broadcast and its v0 direct subject.
v1 onlyagh.network.v1.<channel>.broadcast and its v1 direct subject.
v0 plus v1Both prefixes for each joined channel.

The v1 NATS prefix prevents ambiguous routing between untrusted v0 identities and verified-mode v1 identities. A bridge between prefixes MUST preserve envelope semantics and MUST NOT rewrite proofs unless it re-signs as a new sender.

Security notes

Transport security and message verification solve different problems.

  • NATS TLS or credentials authenticate a connection to the broker.
  • The Ed25519 trust profile verifies the envelope and sender handle.
  • Neither one by itself grants application authorization.

Receivers MUST verify v1 proofs according to signature verification before treating an envelope as verified, even if the message arrived over authenticated NATS.

On this page