Overview
Concrete tool for resolving agent names to host locations across the mesh and syncing with peers, provided by AI Maestro's `lib/agent-directory.ts`.
Description
The agent-directory module is a distributed name-to-host directory. lookupAgent resolves an agent name to an `AgentDirectoryEntry` with host info — or null if not found. syncWithPeers fetches agent lists from all known peer hosts and updates the local directory with remote entries. registerRemoteAgent adds a remote agent entry (never overwriting local entries).
Usage
- Call `lookupAgent` to find which host owns an agent (for routing or display).
- Call `syncWithPeers` to refresh the directory from peers.
- Call `registerRemoteAgent` when learning about agents from peer hosts.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/agent-directory.ts (L186-194 lookupAgent, L196-218 registerRemoteAgent, L272-330 syncWithPeers)
- Supporting: lib/hosts-config.ts (getPeerHosts)
Signature
export function lookupAgent(name: string): AgentDirectoryEntry | null
export function registerRemoteAgent(entry: Omit<AgentDirectoryEntry, 'source' | 'lastSeen'>): boolean
export async function syncWithPeers(timeout: number = 5000): Promise<{
synced: string[]
failed: string[]
newAgents: number
}>
interface AgentDirectoryEntry {
name: string
hostId: string
hostUrl: string
ampAddress?: string
ampRegistered?: boolean
source: 'local' | 'remote'
lastSeen: string
}
Import
import { lookupAgent, registerRemoteAgent, syncWithPeers } from '@/lib/agent-directory'
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| name |
string |
Yes (lookup) |
Agent name to look up
|
| entry |
AgentDirectoryEntry |
Yes (register) |
Remote agent entry
|
| timeout |
number |
No (sync) |
Per-peer timeout in ms (default 5000)
|
Outputs
| Name |
Type |
Description
|
| lookupAgent() returns |
null |
Entry with host info, or null
|
| registerRemoteAgent() returns |
boolean |
true if added (false if local entry exists)
|
| syncWithPeers() returns |
Promise<{synced, failed, newAgents}> |
Peer sync results
|
Usage Examples
import { lookupAgent, syncWithPeers } from '@/lib/agent-directory'
// Find which host owns an agent
const entry = lookupAgent('website')
if (entry) {
console.log(`${entry.name} is on ${entry.hostId} at ${entry.hostUrl}`)
}
// Refresh the directory from peers
const result = await syncWithPeers()
console.log(`Synced with ${result.synced.length} peers, found ${result.newAgents} new agents`)
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.