Coordinator
The Coordinator class — manage multi-agent workflows with handoffs, trust, and budgets.
Usage
import { Coordinator } from '@ahzan-agentforge/core';
const coordinator = new Coordinator({
agents: { researcher, writer, reviewer },
maxHandoffs: 10,
handoffTimeout: 60_000,
trustModel: {
allowedHandoffs: {
researcher: ['writer'],
writer: ['reviewer'],
reviewer: ['writer'], // Can send back for revisions
},
},
});
const result = await coordinator.run('researcher', {
task: 'Research and write a report',
});CoordinationConfig
interface CoordinationConfig {
agents: Map<string, Agent> | Record<string, Agent>;
workspace?: WorkspaceStore;
maxHandoffs?: number;
maxDepthPerAgent?: number;
handoffTimeout?: number; // ms
trustModel?: TrustConfig;
hooks?: CoordinationHooks;
budget?: CoordinationBudgetConfig;
}CoordinationResult
interface CoordinationResult {
coordId: string;
status: 'completed' | 'failed';
output: string;
handoffs: HandoffRecord[];
workspace?: Record<string, unknown>;
budget?: CoordinationBudgetSnapshot;
trace?: string;
}Cycle Detection
The Coordinator builds a directed graph of handoffs and detects cycles. If agent A hands off to B, B to C, and C tries to hand back to A, the Coordinator detects and prevents the cycle.
Per-Agent Depth Limits
Use maxDepthPerAgent to limit how many times a single agent can be called:
const coordinator = new Coordinator({
agents: { writer, reviewer },
maxDepthPerAgent: 3, // Each agent called max 3 times
});