InfoGathererAgent

View as MarkdownOpen in Claude

Sequentially asks a caller a list of questions and stores each answer in global_data. Supports static mode (questions provided at construction) and dynamic mode (questions resolved per request via a callback).

1import { InfoGathererAgent } from '@signalwire/sdk';
2
3const agent = new InfoGathererAgent({ /* InfoGathererConfig */ });

InfoGathererConfig

questions
InfoGathererQuestion[]

Questions to ask (static mode). Each InfoGathererQuestion has:

  • key_name (string, required) — key used to store the caller’s answer.
  • question_text (string, required) — the question to ask.
  • confirm (boolean) — when true, the agent insists the caller confirms the answer before moving on.

Omit this field to run the agent in dynamic mode (see questionCallback / setQuestionCallback()).

questionCallback
InfoGathererQuestionCallback

Convenience alternative to calling setQuestionCallback() after construction. Consulted only when questions is not provided. Signature:

1(queryParams, bodyParams, headers) => InfoGathererQuestion[] | Promise<InfoGathererQuestion[]>

If the callback throws or is not registered in dynamic mode, the agent falls back to a built-in two-question list (name + “how can I help”).

name
stringDefaults to "info_gatherer"

Agent display name.

route
stringDefaults to "/info_gatherer"

HTTP route for the agent.

agentOptions
Partial<AgentOptions>

Additional AgentBase options forwarded to the constructor.

Methods

setQuestionCallback

1setQuestionCallback(callback: InfoGathererQuestionCallback): this

Register (or replace) the callback that resolves questions per request. Only used in dynamic mode (when questions was not supplied at construction).

Built-in Tools

ToolDescription
start_questionsBegin the question sequence with the first question.
submit_answerSubmit the caller’s answer to the current question and advance.

Example — static mode

1import { InfoGathererAgent } from '@signalwire/sdk';
2
3const agent = new InfoGathererAgent({
4 questions: [
5 { key_name: 'full_name', question_text: 'What is your full name?' },
6 { key_name: 'email', question_text: 'What is your email address?', confirm: true },
7 { key_name: 'issue', question_text: 'How can we help you today?' },
8 ],
9 name: 'intake-agent',
10});
11
12agent.serve();

Example — dynamic mode

1import { InfoGathererAgent, type InfoGathererQuestion } from '@signalwire/sdk';
2
3const agent = new InfoGathererAgent({
4 questionCallback: async (queryParams) => {
5 const tenant = queryParams['tenant'] ?? 'default';
6 const rows = await db.loadQuestions(tenant);
7 return rows.map<InfoGathererQuestion>((r) => ({
8 key_name: r.key,
9 question_text: r.prompt,
10 confirm: r.requiresConfirmation,
11 }));
12 },
13});
14
15agent.serve();

createInfoGathererAgent

1import { createInfoGathererAgent } from '@signalwire/sdk';
2
3const agent = createInfoGathererAgent({
4 questions: [
5 { key_name: 'name', question_text: 'What is your name?' },
6 { key_name: 'issue', question_text: 'Describe your issue' },
7 ],
8});