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

from signalwire.prefabs import InfoGathererAgent
agent = InfoGathererAgent(
questions=[
{"key_name": "full_name", "question_text": "What is your full name?"},
{"key_name": "email", "question_text": "What is your email address?", "confirm": True},
{"key_name": "reason", "question_text": "How can I help you today?"}
]
)
if __name__ == "__main__":
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

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

Importing InfoGathererAgent

LanguageImport
Pythonfrom signalwire.prefabs import InfoGathererAgent
TypeScriptimport { InfoGathererAgent } from '@signalwire/sdk'

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:

from signalwire.prefabs import InfoGathererAgent
def get_questions(query_params, body_params, headers):
"""Dynamically determine questions based on request"""
question_set = query_params.get('type', 'default')
if question_set == 'support':
return [
{"key_name": "name", "question_text": "What is your name?"},
{"key_name": "issue", "question_text": "Describe your issue."},
{"key_name": "urgency", "question_text": "How urgent is this?"}
]
else:
return [
{"key_name": "name", "question_text": "What is your name?"},
{"key_name": "message", "question_text": "How can I help?"}
]
# Create agent without static questions
agent = InfoGathererAgent()
# Set the callback for dynamic questions
agent.set_question_callback(get_questions)
if __name__ == "__main__":
agent.run()

Accessing Collected Data

The collected answers are stored in global_data:

# In a SWAIG function or callback:
global_data = raw_data.get("global_data", {})
answers = global_data.get("answers", [])
# answers is a list like:
# [
# {"key_name": "full_name", "answer": "John Doe"},
# {"key_name": "email", "answer": "john@example.com"},
# {"key_name": "reason", "answer": "Product inquiry"}
# ]

Complete Example

#!/usr/bin/env python3
# appointment_scheduler.py - Info gatherer for scheduling appointments
from signalwire.prefabs import InfoGathererAgent
agent = InfoGathererAgent(
questions=[
{"key_name": "name", "question_text": "What is your name?"},
{"key_name": "phone", "question_text": "What is your phone number?", "confirm": True},
{"key_name": "date", "question_text": "What date would you like to schedule?"},
{"key_name": "time", "question_text": "What time works best for you?"},
{"key_name": "notes", "question_text": "Any special notes or requests?"}
],
name="appointment-scheduler"
)
# Add custom language
agent.add_language("English", "en-US", "rime.spore")
# Customize prompt
agent.prompt_add_section(
"Brand",
"You are scheduling appointments for Dr. Smith's office."
)
if __name__ == "__main__":
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