AgentsPrefabs

InfoGathererAgent

View as MarkdownOpen in Claude

Collects answers to a series of questions in sequence, with optional confirmation for critical fields. Supports both static questions (defined at construction) and dynamic questions (determined at runtime via a callback).

1from signalwire.prefabs import InfoGathererAgent
questions
list[dict]

List of question dictionaries. If None, the agent operates in dynamic mode where questions are determined by a callback at request time. Each question dict has:

questions[].key_name
strRequired

Identifier for storing the answer (e.g., "email").

questions[].question_text
strRequired

The question to ask the user.

questions[].confirm
boolDefaults to False

If True, the agent confirms the answer with the user before proceeding. Use for critical data like email addresses and phone numbers.

name
strDefaults to info_gatherer

Agent name for identification and logging.

route
strDefaults to /info_gatherer

HTTP route for this agent.

Built-in Tools

ToolDescriptionParameters
start_questionsBegin the question sequence(none)
submit_answerSubmit an answer and advance to the next questionanswer (str)

Dynamic Questions

Instead of static questions, use set_question_callback() to determine questions at request time based on query parameters, headers, or request body:

1from signalwire.prefabs import InfoGathererAgent
2
3def get_questions(query_params, body_params, headers):
4 question_set = query_params.get("type", "default")
5 if question_set == "support":
6 return [
7 {"key_name": "name", "question_text": "What is your name?"},
8 {"key_name": "issue", "question_text": "Describe your issue."}
9 ]
10 return [
11 {"key_name": "name", "question_text": "What is your name?"},
12 {"key_name": "message", "question_text": "How can I help?"}
13 ]
14
15agent = InfoGathererAgent() # No static questions
16agent.set_question_callback(get_questions)
17
18if __name__ == "__main__":
19 agent.run()

set_question_callback

callback
Callable[[dict, dict, dict], list[dict]]Required

A function receiving (query_params, body_params, headers) that returns a list of question dictionaries in the same format as the questions constructor parameter.

Accessing Collected Data

Answers are stored in global_data and available in SWAIG function handlers:

1from signalwire import AgentBase
2from signalwire.core.function_result import FunctionResult
3
4agent = AgentBase(name="assistant", route="/assistant")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(description="Process collected answers")
8def process_answers(args, raw_data=None):
9 # Inside a tool handler
10 global_data = raw_data.get("global_data", {})
11 answers = global_data.get("answers", [])
12 # [{"key_name": "name", "answer": "John Doe"}, ...]
13 return FunctionResult(f"Processed {len(answers)} answers.")
14
15agent.serve()

Example

1from signalwire.prefabs import InfoGathererAgent
2
3agent = InfoGathererAgent(
4 questions=[
5 {"key_name": "name", "question_text": "What is your name?"},
6 {"key_name": "phone", "question_text": "What is your phone number?", "confirm": True},
7 {"key_name": "date", "question_text": "What date would you like to schedule?"},
8 {"key_name": "time", "question_text": "What time works best for you?"}
9 ],
10 name="appointment-scheduler"
11)
12
13agent.add_language("English", "en-US", "rime.spore")
14agent.prompt_add_section("Brand", "You are scheduling appointments for Dr. Smith's office.")
15
16if __name__ == "__main__":
17 agent.run()