rohitg00/ai-engineering-from-scratch · error · Error

Coordinator: agents must not be empty

Error message

Coordinator: agents must not be empty

What it means

Constructor guard on Coordinator: the caller passed an explicit empty agents array. The default Planner/Coder/Reviewer trio is only substituted when agents is undefined, so an empty array means the rotation has nobody to schedule and every run would deadlock.

Solutions

  1. Pass undefined (omit the argument) to get the default Planner/Coder/Reviewer roster
  2. Supply at least one Agent instance when constructing explicitly
  3. Filter out null/undefined agents before constructing instead of passing an empty array
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/10-multi-agent-software-team/code/ts/src/coordinator.ts:17 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/c2339498e25f201b. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/10-multi-agent-software-team/code/ts/src/coordinator.ts:17

import { Agent, CoderAgent, PlannerAgent, ReviewerAgent } from "./agent.js";
import type { Message, Role, RunResult, WorkspaceFile } from "./types.js";
import { SharedWorkspace } from "./workspace.js";

export class Coordinator {
  private readonly agents: Agent[];
  private readonly workspace = new SharedWorkspace();
  private rotationIndex = 0;

  constructor(agents?: Agent[]) {
    const resolved = agents ?? [
      new PlannerAgent(),
      new CoderAgent(),
      new ReviewerAgent(),
    ];
    if (resolved.length === 0) {
      throw new Error("Coordinator: agents must not be empty");
    }
    this.agents = resolved;
  }

  private routeTo(agent: Agent, msg: Message): boolean {
    return msg.to === "broadcast" || msg.to === agent.role;
  }

  rotation(): Role[] {
    const start = this.rotationIndex % this.agents.length;
    return this.agents
      .map((a, i) => this.agents[(start + i) % this.agents.length]!.role);
  }

  run(initialMessage: Message, maxTurns = 12): RunResult {
    let pending: Message | null = initialMessage;
    this.workspace.appendMessage(initialMessage);
    let turn = 0;

View on GitHub (pinned to 39ea8a1c6d)