Agentix.Addressing (Agentix v0.5.2)

Copy Markdown View Source

How a conversation id resolves to its running agent.

Two modes, chosen with config :agentix, :addressing:

  • :local (default) — a node-local Registry. An agent is reachable only from the node running it.
  • :global — Erlang's :global name registry, so a conversation resolves the same way from every node in the cluster.

Which one you need

:local is correct for a single node and wrong for more than one, in a way that does not announce itself. A conversation is meant to have exactly one agent, because that agent is the single writer of its durable log. Under :local on two nodes, each node's ensure_started/2 finds nothing locally and starts its own, so two agents interleave writes to the same conversation. Cancelling has the mirror problem: the cancel resolves nothing on the calling node and returns :ok having done nothing at all.

Under :global the name is cluster-wide, so the second node's start loses with {:error, {:already_started, pid}} — which Agentix.Conversation already handles — and every entry verb reaches the one live agent wherever it runs.

What :global costs

Registration is a cluster-wide synchronous operation, so starting a conversation is slower and gets slower as nodes are added. It suits workloads where conversations are coarse (a chat session, an extraction run) rather than one per request.

A netsplit is the case :global does not solve. Both sides register their own agent, both write, and on heal :global resolves the duplicate name by killing one — after both have written. If that matters, the durable log is the place to settle it, not the registry.

Summary

Types

The addressing mode in effect.

Functions

The configured mode.

The via tuple a conversation's agent is registered and addressed under.

The pid running conversation_id, or :error when none is registered.

Types

mode()

@type mode() :: :local | :global

The addressing mode in effect.

Functions

mode()

@spec mode() :: mode()

The configured mode.

via(conversation_id)

@spec via(String.t()) :: {:via, module(), term()}

The via tuple a conversation's agent is registered and addressed under.

whereis(conversation_id)

@spec whereis(String.t()) :: {:ok, pid()} | :error

The pid running conversation_id, or :error when none is registered.