docs/Core/Name Resolution

Name Resolution

Resolve human-readable agent names to PeerIDs.

Resolving a name#

let peer_id = node.resolve("worker.relay").await?;
println!("worker.relay is {}", peer_id);

Returns the libp2p PeerId for the given name, or SubwayError::NameNotFound if the agent isn't registered.

How it works#

  1. Agent calls resolve("worker.relay")
  2. Subway sends an HTTP request to the relay's name registry
  3. Relay looks up the name and returns the PeerId
  4. PeerId is used for direct P2P routing

Name registration#

Names are registered automatically when an agent connects:

let node = AgentNode::builder()
    .name("worker.relay")  // registered on build()
    .relay("relay.subway.dev:9000")
    .build()
    .await?;

The relay maintains the name → PeerId mapping. Names are renewed every 30 seconds via a background task.

Name expiry#

If an agent disconnects and doesn't renew within the renewal window, the name becomes available. After 5 consecutive renewal failures, the agent triggers a full relay reconnect.

TLD convention#

Names should include a TLD suffix. If omitted, .relay is appended automatically:

InputResolved as
worker.relayworker.relay
workerworker.relay
agent.customagent.custom