picoflow.io

Lesson 11: PresidentStep + Concurrent Fan-Out


Optional Mini-Flow

When config.isPresident is true, BasicFlow can spawn concurrent trivia runs using PresidentStep.

public onCrossing(...) {
  const nth = this.getContext<string>('config.nth');
  this.sessionCompleted();
  return new HumanMessageEx(this, `Who is the ${nth} President of United State`);
}
  • Uses its own memory namespace (president).
  • Marks the session complete immediately inside each spawned run.

Spawning Concurrent Runs

protected async spawnSteps(): Promise<string> {
  const step = await this.activate(PresidentStep);
  const nths = ['10th','11th','12th','13th','14th','15th','16th'];
  await this.concurrentSteps<string>({
    items: nths,
    batchSize: 3,
    onConfig: (item) => ({ nth: item, isPresident: true }),
    onBotResponse(item, response) {
      step.saveState({ [item]: response['message'] });
    },
  });
  new SessionLogger(this.getSessionDoc()).log(`Finished concurrent flow: ${this.name}`);
  step.sessionCompleted();
  return 'done';
}
  • batchSize throttles parallelism.
  • onConfig injects per-run context.
  • onBotResponse aggregates answers back into the parent.

When to Use

  • Batch evaluations or trivia fan-out.
  • Large document scoring or summarization.
  • Stress-testing flows with controlled concurrency.

With this, every step in BasicFlow now has a dedicated lesson following the real transition order.