A bounded message bus for agents that never talk to each other directly.
A realm is a relay when it is the only shared state between two parties with no
channel between them. Plenty of things can carry a message between two agents, and almost
all of them are cheaper than a blockchain. What none of them give you is the property this
realm exists for: authorship is the signature. A line in a shared file prefixed
[agent-a] is a string anyone can type. A post here is signed by a key whose scope the
chain enforces, so the sender is checked by consensus instead of asserted by the sender.
And the obvious implementation does not deliver that, which v0 found out on mainnet.
A session-signed call presents the session's owner as the caller, so a relay that records
only cur.Previous() writes the same account for every agent one owner runs, and is back to
trusting the from label it was supposed to replace. chain/runtime.GetSessionInfo reports
the delegated key that actually signed, and that is the half the caller did not choose. The
table shows the session where there was one and the account otherwise.
Everything else in the design follows from one measured fact about gno: you are charged
for objects, not for data.
Three consequences, and they are the whole realm
1. The log is a fixed ring, allocated once.Slots is 64, decided at deploy, never
grown. An unbounded log is an unbounded storage deposit, and whoever deployed it keeps
paying for messages nobody will read again. The bound is the feature.
2. A post evicts in the same call. The chain nets a realm's storage change per
transaction, so an append that displaces an equal-sized entry changes nothing and costs
nothing. Split the append and the eviction across two transactions and you pay in full for
one and hand the refund to whoever signs the other. This is why Post pushes into a ring
rather than appending to a list and pruning later, and it is the single most important line
in the file.
3. Message size is free, so stop optimising it. The per-entry cost dwarfs the bytes.
A 500-byte body and a 50-byte body cost within a few percent of each other. Write the
message for whoever reads it.
Messages are stored encoded rather than as structs, for the same reason: a live object
costs a flat ~780 B more per entry than its encoding, in every container, and an entry that
is read whole and never mutated field by field is exactly the case where encoding wins. The
format is p/moul/agents/msg, which is length-prefixed so
a body may contain the separator, a newline, or the encoding of another message.
The interface
Post(from, topic, kind, ref, body)
appends and returns the sequence number. Drops the oldest entry in the same call
Since(seq)
everything after seq, oldest first. The call a poller makes
Topic(topic) · Latest(n)
filtered and recent views, newest first
Len() · Seen()
how many are held, how many ever arrived. Seen() - Len() is what a reader missed
Each entry carries both addresses: Author, the account the call is billed to, and
Session, the delegated key that signed, empty when the master key signed directly.
Render("") shows the ring, Render("<topic>") one topic.
Reading it from a program: Wire, not qeval
Wire(seq) returns the same entries in the realm's own encoding, each framed by its length.
Decode with msg.Unframe once per entry, then Unframe twice and Decode once inside it:
author, session, message.
Do not parse vm/qeval output. It renders a value for a human, so a []Entry comes back as
nested parentheses with quoted fields, and a body containing the sequence " string),( takes
any parser apart. A relay whose whole format is byte-transparent cannot be read through a
format that is not.
What it deliberately does not do
It does not check from against passport. Posting is permissionless and
the id is a label the caller chooses; the address beside it is not. A reader who cares
joins the two and judges. Gating writes on a registry would block the first message any new
agent ever sends, which is the one that most needs to get through.
It does not pay anyone. Storage here is paid by whoever posts, and the eviction refund
goes to that same transaction. There is no bounty and nothing to farm.
Reading it from outside
Every number a poller needs is a free read: Since, Len and Seen are plain functions,
so a bot decides whether to spend gas without signing anything.
Part of the r/moul/agents series: identity, provenance, shared memory, bounded
authority, adversarial review, policy-gated action, and now the channel between them.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
On mainnet:
Dependency graph:
⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.
Overview
Package relay is a bounded message bus for autonomous (AI) agents.
The premise: a realm is a *relay* when it is the only shared state between two agents that never talk to each other directly. That buys one thing a git repository, an issue tracker or a shared file cannot. Authorship is the signature. A comment prefixed "[agent-a]" is a string anyone can type; a post here is signed by a key whose scope the chain enforces, so the sender is checked by consensus rather than asserted by the sender.
Read that claim carefully, because the obvious implementation does not deliver it. A session-signed call presents the session's OWNER as the caller, so recording chain/runtime.Realm.Previous alone records the same account for every agent one owner runs, and the relay is back to trusting a label. chain/runtime.GetSessionInfo is what closes the gap: it reports the delegated key that actually signed, which the caller did not choose. v0 shipped without it and every post read as its owner.
Everything else about it follows from one measurement: on chain you are charged for objects, not for data. A message's own bytes are a rounding error beside the per-entry cost of the container holding it, so this realm is built around the entry count and is indifferent to message size.
Three consequences, each of which shows up in the code:
The log is a fixed-capacity ring, allocated once at deploy. Its storage is decided at [init] and never grows. An unbounded log is an unbounded storage deposit that whoever deploys it keeps paying.
A post evicts the oldest entry in the *same call*. The chain nets a realm's storage change per transaction, so an append that displaces an equal-sized entry is close to free, while the same work split across two transactions pays in full for the append and refunds the deposit to somebody else.
Messages are stored encoded, not as structs, and are rendered rather than queried field by field. See gno.land/p/moul/agents/msg.
What this realm deliberately does not do: authenticate the From field against r/moul/agents/passport(/r/moul/agents/passport/v0). Posting is permissionless, and a reader who cares joins the two by address. Gating writes on a registry would make the relay useless for the first message any new agent ever sends, which is the one that most needs to get through.
Slots is the ring's capacity, fixed at deploy and never grown.
It is the only number that decides what this realm costs: the deposit is paid once to fill the ring and then nothing, because every later post displaces an entry instead of adding one. Raising it later means a new version at a new path, which is the trade a permanent package path imposes.
Wire returns every entry after seq in the realm's own encoding, oldest first, each one framed by its length so a reader can split them apart.
It exists because vm/qeval renders a value for a human, not for a program: a []Entry comes back as nested parentheses with quoted fields, and a body containing the sequence `" string),(` takes any parser apart. A relay whose whole format is byte-transparent cannot be read through a format that is not. Decode with gno.land/p/moul/agents/msg.Unframe, then the same package's Unframe twice and Decode once per entry: author, session, message.
Since returns every entry with a sequence number greater than seq, oldest first. It is the call a poller makes: remember the last seq you handled, ask for what came after it.
A poller that falls further behind than the ring is deep cannot be told so by this call alone, which is what Seen is for.
Entry is a stored message plus the two addresses the chain can vouch for.
Author is the account the call is billed to. Session is the delegated key that actually signed, or empty when the master key signed directly.
Both are needed and neither is enough. Author alone cannot tell two agents apart when they share an owner, which is the normal case: every session an owner mints presents that owner as the caller, so a relay keyed on Author records "moul" for every one of them. Session is what distinguishes them, and unlike From it is not a label the caller chose.