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';
}
batchSizethrottles parallelism.onConfiginjects per-run context.onBotResponseaggregates answers back into the parent.
Triggering It Over HTTP
To force the concurrent path from outside the UI, hit the flow runner directly:
curl -X POST http://localhost:8000/ai/run \
-H "Content-Type: application/json" \
-H "CHAT_SESSION_ID: <uuid>" \
-d '{
"flowName": "BasicFlow",
"config": { "_concurrent": true }
}'
_concurrent: truetellsBasicFlowto activate thePresidentStepfan‑out.- Add a
CHAT_SESSION_IDheader to keep runs isolated if you are issuing multiple requests.
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.