picoflow.io

Lesson 8: NameStep + InContext Sub-Agent


Prompt + Tools

public getPrompt(): string {
  return `
    ${DemoPrompt.TravelRole}
    Please collect name from customer.
    Once you capture the name, immediately call tool 'user_name'.
    Pay attention to the tool respond if the name is validated or not.
    If user prefer to exit, call tool 'end_chat'.
  `;
}

defineTool(): [{ name: 'user_name', schema: z.object({ name: z.string() }) }];
getTool(): ['user_name', 'end_chat'];

Handler: Context + Sub-Agent + Validation

protected async user_name(tool: ToolCall): Promise<ToolResponseType> {
  this.saveState({ name: tool.args?.name });
  const runData = this.flow.getContext<object>('myRunData');
  this.saveState(runData);

  const answer = await this.runStep(InContextStep);
  this.saveState({ inContext: answer });

  if (tool.args?.name === 'John Doe') {
    return { step: NameStep, tool: 'Cannot accept John Doe, please choose a different name.' };
  }
  return DOBStep;
}
  • Merges request-time context into state.
  • Calls InContextStep as a stack-style sub-agent; result is captured synchronously.
  • Rejects banned name by retrying the same step with an error tool message.

InContextStep Quick Facts

  • Separate memory: .useMemory('separate')
  • Model override: .useModel('gpt-5', { reasoning: { effort: 'high' } })
  • Structured schema for teen sci‑fi movie pitch
  • onCrossing injects a preamble human message

Next: DOBStep — prompt templating from captured name.