picoflow.io

Lesson 9: DOBStep — Prompt Templating


Dynamic Prompt

public getPrompt(): string {
  const template = `
    ${DemoPrompt.TravelRole}
    Please ask the DOB for {{UserName}}.
    Once you capture the DOB, call tool 'dob'.
    If you have doubt interpreting the DOB, ask user to re-enter the DOB.
    If user prefer to exit, call tool 'end_chat'.
  `;
  const name = this.flow.getStepStateAs<string>(NameStep, 'name');
  return Prompt.replace(template, { UserName: name });
}
Tip

Always fetch prior state explicitly; don’t rely on the LLM to “remember.”


Structured Capture

defineTool(): [{
  name: 'dob',
  schema: z.object({
    year: z.number(),
    month: z.number(),
    day: z.number(),
  }),
}];

Handler saves and advances:

protected async dob(tool: ToolCall): Promise<ToolResponseType> {
  this.saveState(tool.args);
  return AddressStep;
}
  • Schema blocks malformed dates.
  • No retries needed unless parsing fails (handled by the runtime).

Next: AddressStep — server-side validation and exit via EndStep.