Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Host Routing

From Leeroopedia
Knowledge Sources
Domains Agent_Messaging, Routing
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for resolving agent identifiers, checking host identity, and looking up hosts in the mesh, provided by AI Maestro's `lib/messageQueue.ts` and `lib/hosts-config.ts`.

Description

The routing layer resolves who a message goes to and whether that destination is on this host or a peer:

  • resolveAgentIdentifier: resolves an agent name, alias, or qualified name to a `ResolvedAgent` (agent ID + name) via the agent registry.
  • isSelf: checks if a host ID refers to this machine — the only place self-detection happens. Checks hostname, IPs, and legacy 'local' value.
  • getHostById: looks up a host by ID from the hosts config file.
  • getHosts: returns all configured hosts.
  • getSelfHost: returns this machine's `Host` object, falling back to a default.

Usage

  • Call `resolveAgentIdentifier` when routing a message to a recipient.
  • Call `isSelf` to decide whether a message is local or needs federation relay.
  • Call `getHostById` / `getHosts` when displaying the mesh or routing to a peer.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/messageQueue.ts (L874 resolveAgentIdentifier), lib/hosts-config.ts (L139-141 getSelfHostId, L228 isSelf, L504-510 getHosts, L511 getHostById, L595-599 getSelfHost)

Signature

export function resolveAgentIdentifier(identifier: string): ResolvedAgent | null

export function isSelf(hostId: string): boolean

export function getHostById(hostId: string): Host | undefined

export function getHosts(): Host[]

export function getSelfHost(): Host

export function getSelfHostId(): string

interface ResolvedAgent {
  id: string
  name: string
}

interface Host {
  id: string
  name: string
  url: string
  enabled: boolean
  kind?: string
}

Import

import { resolveAgentIdentifier } from '@/lib/messageQueue'
import { isSelf, getHostById, getHosts, getSelfHost, getSelfHostId } from '@/lib/hosts-config'

I/O Contract

Inputs

Name Type Required Description
identifier string Yes (resolve) Agent name, alias, or qualified name
hostId string Yes (isSelf/getHostById) Host ID to check/look up

Outputs

Name Type Description
resolveAgentIdentifier() returns null Agent ID + name, or null if not found
isSelf() returns boolean true if host is this machine
getHostById() returns undefined Host object
getHosts() returns Host[] All configured hosts
getSelfHost() returns Host This machine's host (default if not configured)
getSelfHostId() returns string Lowercase hostname without .local

Usage Examples

import { resolveAgentIdentifier } from '@/lib/messageQueue'
import { isSelf, getHostById } from '@/lib/hosts-config'

// 1. Resolve the recipient
const resolved = resolveAgentIdentifier('website')
if (!resolved) throw new Error('Agent not found')

// 2. Is the recipient on this host?
if (isSelf(recipientHostId)) {
  // Local delivery
  await deliver({ recipientAgentId: resolved.id, ... })
} else {
  // Federation relay to peer host
  const peerHost = getHostById(recipientHostId)
  await relayToPeer(peerHost, envelope)
}

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment