Services.NamePool (fnord v0.8.82)

View Source

A service that manages a pool of AI agent names, batch-allocating them from the nomenclater for efficiency. Names can be checked out and optionally checked back in for reuse within the same session.

Each checked-out name is now associated with the caller's pid, and you can retrieve it via get_name_by_pid/1.

The pool allocates names in chunks sized to the configured workers setting to maximize API efficiency without overwhelming the connection pool.

Summary

Functions

Restores the association between a pid and a name. This is useful to re-associate a name after a process restart or similar event.

Checks a name back into the pool for potential reuse. This is optional - names that are never checked back in will simply be lost when the session ends.

Checks out a name from the pool. If the pool is empty or running low, automatically allocates a new chunk of names.

Returns a specification to start this module under a supervisor.

Returns {:ok, name} if the given pid has a checked‐out name, or {:error, :not_found} otherwise.

Returns pool statistics for debugging/monitoring

Resets the pool state (mainly for testing)

Starts the name pool service

Types

t()

@type t() :: %Services.NamePool{
  all_used: MapSet.t(String.t()),
  available: [String.t()],
  checked_out: MapSet.t(String.t()),
  chunk_size: pos_integer(),
  name_to_pid: %{optional(String.t()) => pid()},
  pid_to_name: %{optional(pid()) => String.t()}
}

Functions

associate_name(name, server \\ Services.NamePool)

Restores the association between a pid and a name. This is useful to re-associate a name after a process restart or similar event.

checkin_name(name, server \\ Services.NamePool)

@spec checkin_name(String.t(), atom() | pid()) :: :ok

Checks a name back into the pool for potential reuse. This is optional - names that are never checked back in will simply be lost when the session ends.

checkout_name(server \\ Services.NamePool)

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

Checks out a name from the pool. If the pool is empty or running low, automatically allocates a new chunk of names.

Returns {:ok, name} or {:error, reason}.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

default_name()

get_name_by_pid(pid, server \\ Services.NamePool)

@spec get_name_by_pid(pid(), atom() | pid()) ::
  {:ok, String.t()} | {:error, :not_found}

Returns {:ok, name} if the given pid has a checked‐out name, or {:error, :not_found} otherwise.

pool_stats(server \\ Services.NamePool)

Returns pool statistics for debugging/monitoring

reset(server \\ Services.NamePool)

Resets the pool state (mainly for testing)

start_link(opts \\ [])

Starts the name pool service