InfoGatherer

View as MarkdownOpen in Claude

InfoGatherer is a pre-built agent that collects answers to a series of questions. It handles the conversation flow automatically, including optional confirmation of critical answers and dynamic question selection.

Basic Usage

1from signalwire.prefabs import InfoGathererAgent
2
3agent = 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": "reason", "question_text": "How can I help you today?"}
8 ]
9)
10
11if __name__ == "__main__":
12 agent.run()

Question Format

FieldTypeRequiredDescription
key_namestringYesIdentifier for storing the answer
question_textstringYesThe question to ask the user
confirmbooleanNoIf true, confirm answer before next

Constructor Parameters

1InfoGathererAgent(
2 questions=None, # List of question dictionaries
3 name="info_gatherer", # Agent name
4 route="/info_gatherer", # HTTP route
5 **kwargs # Additional AgentBase arguments
6)

Importing InfoGathererAgent

LanguageImport
Pythonfrom signalwire.prefabs import InfoGathererAgent
TypeScriptimport { InfoGathererAgent } from 'signalwire-agents'

Flow Diagram

Diagram showing the InfoGatherer flow from question presentation through answer collection and confirmation.
InfoGatherer conversation flow.

Built-in Functions

InfoGatherer provides these SWAIG functions automatically:

FunctionDescription
start_questionsBegin the question sequence
submit_answerSubmit answer and get next question

Dynamic Questions

Instead of static questions, use a callback to determine questions at runtime:

1from signalwire.prefabs import InfoGathererAgent
2
3def get_questions(query_params, body_params, headers):
4 """Dynamically determine questions based on request"""
5 question_set = query_params.get('type', 'default')
6
7 if question_set == 'support':
8 return [
9 {"key_name": "name", "question_text": "What is your name?"},
10 {"key_name": "issue", "question_text": "Describe your issue."},
11 {"key_name": "urgency", "question_text": "How urgent is this?"}
12 ]
13 else:
14 return [
15 {"key_name": "name", "question_text": "What is your name?"},
16 {"key_name": "message", "question_text": "How can I help?"}
17 ]
18
19# Create agent without static questions
20agent = InfoGathererAgent()
21
22# Set the callback for dynamic questions
23agent.set_question_callback(get_questions)
24
25if __name__ == "__main__":
26 agent.run()

Accessing Collected Data

The collected answers are stored in global_data:

1# In a SWAIG function or callback:
2global_data = raw_data.get("global_data", {})
3answers = global_data.get("answers", [])
4
5# answers is a list like:
6# [
7# {"key_name": "full_name", "answer": "John Doe"},
8# {"key_name": "email", "answer": "john@example.com"},
9# {"key_name": "reason", "answer": "Product inquiry"}
10# ]

Complete Example

1#!/usr/bin/env python3
2# appointment_scheduler.py - Info gatherer for scheduling appointments
3from signalwire.prefabs import InfoGathererAgent
4
5agent = InfoGathererAgent(
6 questions=[
7 {"key_name": "name", "question_text": "What is your name?"},
8 {"key_name": "phone", "question_text": "What is your phone number?", "confirm": True},
9 {"key_name": "date", "question_text": "What date would you like to schedule?"},
10 {"key_name": "time", "question_text": "What time works best for you?"},
11 {"key_name": "notes", "question_text": "Any special notes or requests?"}
12 ],
13 name="appointment-scheduler"
14)
15
16# Add custom language
17agent.add_language("English", "en-US", "rime.spore")
18
19# Customize prompt
20agent.prompt_add_section(
21 "Brand",
22 "You are scheduling appointments for Dr. Smith's office."
23)
24
25if __name__ == "__main__":
26 agent.run()

Implementation Notes

InfoGatherer uses replace_in_history() internally to keep the conversation history clean. Each question/answer exchange is replaced in the LLM history so that the conversation context stays focused and doesn’t grow excessively with repetitive tool call entries. This is transparent to the user — they experience a natural conversation flow.

Best Practices

Questions

  • Keep questions clear and specific
  • Use confirm=true for critical data (email, phone)
  • Limit to 5-7 questions max per session
  • Order from simple to complex

key_name Values

  • Use descriptive, unique identifiers
  • snake_case convention recommended
  • Match your backend/database field names

Dynamic Questions

  • Use callbacks for multi-purpose agents
  • Validate questions in callback
  • Handle errors gracefully