/** * InfoGathererAgent - Prefab agent for collecting answers to a series of * questions. * * Ported from the Python SDK `signalwire.prefabs.info_gatherer.InfoGathererAgent`. * Supports both static (questions provided at init) and dynamic (questions * determined by a callback function per request) configuration modes. */ import { AgentBase } from '../AgentBase.js'; import type { AgentOptions } from '../types.js'; /** A single question in the information-gathering flow. */ export interface InfoGathererQuestion { /** Identifier used as the key when storing the caller's answer. */ key_name: string; /** The question text to ask the caller. */ question_text: string; /** When true, the agent insists the caller confirms before submitting. */ confirm?: boolean; } /** * Callback invoked on each incoming SWML request to produce the list of * questions for that request. Mirrors Python's `set_question_callback`. * @returns a list of questions (may be async). */ export type InfoGathererQuestionCallback = (queryParams: Record, bodyParams: Record, headers: Record) => InfoGathererQuestion[] | Promise; /** Configuration for the InfoGathererAgent. */ export interface InfoGathererConfig { /** * Optional list of questions to ask. When omitted, the agent runs in * dynamic mode and resolves questions via the callback registered with * `setQuestionCallback()` (or via `questionCallback` below). */ questions?: InfoGathererQuestion[]; /** * Convenience alternative to calling `setQuestionCallback()` after * construction. Only consulted when `questions` is not provided. */ questionCallback?: InfoGathererQuestionCallback; /** Agent display name (defaults to `"info_gatherer"`). */ name?: string; /** HTTP route for this agent (defaults to `"/info_gatherer"`). */ route?: string; /** Additional AgentBase options forwarded to super(). */ agentOptions?: Partial; } /** * Prefab agent that gathers caller information one question at a time. * * Supports two modes: * * - **Static** — provide `questions` at construction; the same questions are * asked on every call. * - **Dynamic** — leave `questions` unset and register a callback via * `questionCallback` (or `setQuestionCallback()`); the callback decides which * questions to ask per incoming call based on query params, body, or headers. * * @example Static questions * ```ts * import { InfoGathererAgent } from '@signalwire/sdk'; * * const agent = new InfoGathererAgent({ * questions: [ * { key_name: 'name', question_text: 'What is your name?' }, * { key_name: 'email', question_text: 'What is your email address?', confirm: true }, * { key_name: 'issue', question_text: 'How can we help?' }, * ], * }); * * await agent.serve({ port: 3000 }); * ``` * * @example Dynamic questions per request * ```ts * const agent = new InfoGathererAgent({ * questionCallback: async (query) => { * if (query.intake === 'medical') { * return [ * { key_name: 'dob', question_text: 'Date of birth?' }, * { key_name: 'insurance_id', question_text: 'Insurance member ID?' }, * ]; * } * return [{ key_name: 'message', question_text: 'How can I help?' }]; * }, * }); * ``` */ export declare class InfoGathererAgent extends AgentBase { private staticQuestions; private questionCallback; /** * Create an InfoGathererAgent. * @param config - Either `questions` (static mode) or leave omitted and use * `questionCallback` / `setQuestionCallback()` (dynamic mode). */ constructor(config?: InfoGathererConfig); /** * Register a callback for dynamic question configuration. The callback is * invoked on each incoming SWML request with the query params, body, and * headers, and must return the list of questions to ask on that call. * Mirrors Python `set_question_callback`. */ setQuestionCallback(callback: InfoGathererQuestionCallback): this; private static validateQuestions; private buildPrompt; /** * Generate the instruction text for asking a question. Mirrors Python's * `_generate_question_instruction`. */ private generateQuestionInstruction; /** * Handle dynamic configuration using the registered callback. Returns the * per-request global_data payload which AgentBase merges into the SWML * response. Mirrors Python's `on_swml_request` return-dict contract. */ onSwmlRequest(rawData: Record): Promise | void>; private extractRecord; /** Register the `start_questions` and `submit_answer` SWAIG tools. */ protected defineTools(): void; } /** * Factory function that creates and returns a new InfoGathererAgent. * @param config - Configuration for the info gatherer agent. * @returns A configured InfoGathererAgent instance. */ export declare function createInfoGathererAgent(config?: InfoGathererConfig): InfoGathererAgent; export default InfoGathererAgent;