ruvnet/ruflo · error

Agent ${this.id} not initialized. Call initialize() first.

Error message

Agent ${this.id} not initialized. Call initialize() first.

What it means

Thrown by AgenticFlowAgent#ensureInitialized (v3/@claude-flow/integration/src/agentic-flow-agent.ts:763). Guard methods (executeTask, checkpointing, metric snapshots) call it before doing work, so any operation on an agent whose initialize() has not completed (or failed) fails fast with the agent id embedded in the message.

Source

Thrown at v3/@claude-flow/integration/src/agentic-flow-agent.ts:763

  protected async localExecuteTask(task: Task): Promise<unknown> {
    // Minimal processing delay for timing metrics
    await this.delay(1);

    // This is a basic implementation that should be overridden by subclasses
    // For now, just return the task input as output
    return {
      message: `Task ${task.id} processed by agent ${this.id}`,
      input: task.input,
      timestamp: Date.now(),
    };
  }

  /**
   * Ensure agent is initialized before operations
   */
  private ensureInitialized(): void {
    if (!this.initialized) {
      throw new Error(`Agent ${this.id} not initialized. Call initialize() first.`);
    }
  }

  /**
   * Estimate memory usage in MB (rough estimate)
   */
  private estimateMemoryUsage(): number {
    // Rough estimate: 1MB base + 100KB per task completed
    return 1 + (this.metrics!.tasksCompleted * 0.1);
  }

  /**
   * Generate a unique ID with prefix
   */
  private generateId(prefix: string): string {
    return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
  }

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Always `await agent.initialize()` before dispatching, and create agents via a factory that returns an initialized instance.
  2. On initialize() failure, either retry initialization or drop the agent from the pool — do not dispatch to it.
  3. In pools, gate acquisition on the agent being initialized (filter on a tracked flag).
  4. Add a unit test that asserts every public entry point fails with this exact message pre-initialize, so regressions surface early.

Example fix

// before
const agent = new AgenticFlowAgent(cfg);
agent.executeTask(task); // forgot await initialize()

// after
const agent = new AgenticFlowAgent(cfg);
await agent.initialize();
await agent.executeTask(task);
Defensive patterns

Strategy: validation

Validate before calling

await agent.initialize();
// only then:
await agent.executeTask(task);

Type guard

function isAgentReady(a: { initialized?: boolean }): boolean {
  return a.initialized === true;
}

Try / catch

try {
  await agent.executeTask(task);
} catch (e) {
  if (/not initialized\. Call initialize\(\) first/.test((e as Error).message)) {
    await agent.initialize();
    return agent.executeTask(task);
  }
  throw e;
}

Prevention

When it happens

Trigger: executeTask() immediately after construction without await agent.initialize(); calling during a concurrent initialize() that is still awaiting external resources; calling after initialize() rejected (e.g. adapter dependency down) without recovery.

Common situations: Missing await on initialize() in async setup code; batch-creating agents with Promise.all but dispatching before all resolves; reusing pooled agents where one failed to initialize and was never recycled.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/3836bcaaec4b48c2. Report an issue: GitHub.