Survey

View as MarkdownOpen in Claude

Survey

SurveyAgent conducts automated surveys with different question types (rating, multiple choice, yes/no, open-ended), validation, and response logging.

Basic Usage

1from signalwire_agents.prefabs import SurveyAgent
2
3agent = SurveyAgent(
4 survey_name="Customer Satisfaction Survey",
5 questions=[
6 {
7 "id": "satisfaction",
8 "text": "How satisfied were you with our service?",
9 "type": "rating",
10 "scale": 5
11 },
12 {
13 "id": "recommend",
14 "text": "Would you recommend us to others?",
15 "type": "yes_no"
16 },
17 {
18 "id": "comments",
19 "text": "Any additional comments?",
20 "type": "open_ended",
21 "required": False
22 }
23 ]
24)
25
26if __name__ == "__main__":
27 agent.run()

Question Types

TypeFieldsExample
ratingscale (1-10)“Rate 1-5, where 5 is best”
multiple_choiceoptions (list)“Choose: Poor, Fair, Good, Excellent”
yes_no(none)“Would you recommend us?”
open_ended(none)“Any comments?”

Question Format

FieldTypeRequiredDescription
idstringYesUnique identifier for the question
textstringYesThe question to ask
typestringYesrating, multiple_choice, yes_no, open_ended
optionslist[string]*Required for multiple_choice
scaleintegerNoFor rating (default: 5)
requiredbooleanNoIs answer required (default: true)

Constructor Parameters

1SurveyAgent(
2 survey_name="...", # Name of the survey (required)
3 questions=[...], # List of question dictionaries (required)
4 introduction=None, # Custom intro message
5 conclusion=None, # Custom conclusion message
6 brand_name=None, # Company/brand name
7 max_retries=2, # Retries for invalid answers
8 name="survey", # Agent name
9 route="/survey", # HTTP route
10 **kwargs # Additional AgentBase arguments
11)

Built-in Functions

SurveyAgent provides these SWAIG functions automatically:

FunctionDescription
validate_responseCheck if response is valid for question type
log_responseRecord a validated response

Survey Flow

Survey Flow.
Survey Flow

Complete Example

1#!/usr/bin/env python3
2## product_survey.py - Product feedback survey agent
3from signalwire_agents.prefabs import SurveyAgent
4
5
6agent = SurveyAgent(
7 survey_name="Product Feedback Survey",
8 brand_name="TechGadgets Inc.",
9 introduction="Thank you for purchasing our product. We'd love your feedback!",
10 conclusion="Thank you for completing our survey. Your input helps us improve.",
11 questions=[
12 {
13 "id": "overall_rating",
14 "text": "How would you rate the product overall?",
15 "type": "rating",
16 "scale": 5,
17 "required": True
18 },
19 {
20 "id": "quality",
21 "text": "How would you rate the build quality?",
22 "type": "multiple_choice",
23 "options": ["Poor", "Fair", "Good", "Excellent"],
24 "required": True
25 },
26 {
27 "id": "purchase_again",
28 "text": "Would you purchase from us again?",
29 "type": "yes_no",
30 "required": True
31 },
32 {
33 "id": "improvements",
34 "text": "What could we improve?",
35 "type": "open_ended",
36 "required": False
37 }
38 ],
39 max_retries=2
40)
41
42if __name__ == "__main__":
43 agent.add_language("English", "en-US", "rime.spore")
44 agent.run()

Best Practices

Question Design

  • Keep surveys short (5-7 questions max)
  • Start with easy questions
  • Put open-ended questions at the end
  • Make non-essential questions optional

Question Types

  • Use rating for satisfaction metrics (NPS, CSAT)
  • Use multiple_choice for specific options
  • Use yes_no for simple binary questions
  • Use open_ended sparingly - harder to analyze

Validation

  • Set appropriate max_retries (2-3)
  • Use clear scale descriptions
  • List all options for multiple choice