Skip to navigation

addGatherQuestion

View as MarkdownOpen in Claude

Add a question to this step’s gather_info configuration. setGatherInfo() must be called before this method.

Gather mode limits function access. While the model is asking gather questions, the platform deactivates all of the step’s other functions. During a gather question, the model can call:

  • gather_submit (the native answer-submission tool)
  • Whatever names you list in this question’s functions option
  • The platform’s built-in tools, such as get_visual_input when vision is enabled

next_step is removed until the gather completes, but change_context isn’t. If the step sets valid contexts with setValidContexts(), the model can switch contexts before every question is answered. To keep the model in the step until the gather completes, don’t set valid contexts on a gather step.

If a question needs to call out to a tool (e.g. validate an email, geocode a ZIP), list that tool name in this question’s functions. Functions listed here are active only for this question. Listing a function only makes it callable: the platform doesn’t run it for you, and it can’t block gather_submit. A validation tool works only when the model calls it and acts on what it returns.

Parameters

opts
objectRequired

Question configuration object with the following fields:

opts.key
stringRequired

Key name for storing the answer in global_data. Must be unique within this step’s gather questions.

opts.question
stringRequired

The question text to present to the caller.

opts.type
stringDefaults to string

JSON schema type for the answer parameter.

  • "string" — text value
  • "integer" — whole number value
  • "number" — numeric value including decimals
  • "boolean" — true or false value
opts.confirm
booleanDefaults to false

When true, the AI must confirm the answer with the caller before accepting it.

opts.prompt
string

Extra instruction text appended for this specific question.

opts.functions
string[]

Additional function names to make visible while asking this question.

Returns

Step — Self for method chaining. Throws an error if setGatherInfo() has not been called first.

Example

import { ContextBuilder } from '@signalwire/sdk';
const builder = new ContextBuilder();
const ctx = builder.addContext('default');
const intake = ctx.addStep('intake');
intake.setText('Collect patient information.');
intake.setGatherInfo({
outputKey: 'patient_info',
completionAction: 'next_step',
prompt: 'Be friendly and professional when collecting information.',
});
intake.addGatherQuestion({
key: 'full_name', question: 'What is your full name?', confirm: true,
});
intake.addGatherQuestion({
key: 'date_of_birth',
question: 'What is your date of birth?',
type: 'string',
prompt: 'Spell it back to confirm.',
});
intake.addGatherQuestion({
key: 'insurance_id',
question: 'What is your insurance ID number?',
functions: ['verify_insurance'],
});
ctx.addStep('review').setText('Review the collected information with the patient.');