Faq Bot

View as Markdown

FAQBot

FAQBotAgent answers frequently asked questions from a provided knowledge base. It matches user questions to FAQs and optionally suggests related questions.

Basic Usage

1from signalwire_agents.prefabs import FAQBotAgent
2
3agent = FAQBotAgent(
4 faqs=[
5 {
6 "question": "What are your business hours?",
7 "answer": "We're open Monday through Friday, 9 AM to 5 PM."
8 },
9 {
10 "question": "Where are you located?",
11 "answer": "Our main office is at 123 Main Street, Downtown."
12 },
13 {
14 "question": "How do I contact support?",
15 "answer": "Email support@example.com or call 555-1234."
16 }
17 ]
18)
19
20if __name__ == "__main__":
21 agent.run()

FAQ Format

FieldTypeRequiredDescription
questionstringYesThe FAQ question
answerstringYesThe answer to provide
categorieslist[string]NoCategory tags for filtering

Constructor Parameters

1FAQBotAgent(
2 faqs=[...], # List of FAQ dictionaries (required)
3 suggest_related=True, # Suggest related questions
4 persona=None, # Custom personality description
5 name="faq_bot", # Agent name
6 route="/faq", # HTTP route
7 **kwargs # Additional AgentBase arguments
8)

With Categories

Use categories to organize FAQs:

1from signalwire_agents.prefabs import FAQBotAgent
2
3agent = FAQBotAgent(
4 faqs=[
5 {
6 "question": "How do I reset my password?",
7 "answer": "Click 'Forgot Password' on the login page.",
8 "categories": ["account", "security"]
9 },
10 {
11 "question": "How do I update my email?",
12 "answer": "Go to Settings > Account > Email.",
13 "categories": ["account", "settings"]
14 },
15 {
16 "question": "What payment methods do you accept?",
17 "answer": "We accept Visa, Mastercard, and PayPal.",
18 "categories": ["billing", "payments"]
19 }
20 ]
21)

Built-in Functions

FAQBot provides this SWAIG function automatically:

FunctionDescription
search_faqsSearch FAQs by query or category

Custom Persona

Customize the bot’s personality:

1agent = FAQBotAgent(
2 faqs=[...],
3 persona="You are a friendly and knowledgeable support agent for Acme Corp. "
4 "You speak in a warm, professional tone and always try to be helpful."
5)

Complete Example

1#!/usr/bin/env python3
2## product_faq_bot.py - FAQ bot for product questions
3from signalwire_agents.prefabs import FAQBotAgent
4
5
6agent = FAQBotAgent(
7 faqs=[
8 {
9 "question": "What is the warranty period?",
10 "answer": "All products come with a 2-year warranty.",
11 "categories": ["warranty", "products"]
12 },
13 {
14 "question": "How do I return a product?",
15 "answer": "Start a return within 30 days at returns.example.com.",
16 "categories": ["returns", "products"]
17 },
18 {
19 "question": "Do you ship internationally?",
20 "answer": "Yes, we ship to over 50 countries.",
21 "categories": ["shipping"]
22 }
23 ],
24 suggest_related=True,
25 persona="You are a helpful product specialist for TechGadgets Inc.",
26 name="product-faq"
27)
28
29## Add language
30agent.add_language("English", "en-US", "rime.spore")
31
32if __name__ == "__main__":
33 agent.run()

Best Practices

FAQ Content

  • Write questions as users would ask them
  • Keep answers concise but complete
  • Include variations of common questions
  • Update FAQs based on actual user queries

Categories

  • Use consistent category naming
  • Limit to 2-3 categories per FAQ
  • Use categories for related question suggestions

Scaling

  • For large FAQ sets, consider native_vector_search skill
  • FAQBot works best with 50 or fewer FAQs
  • Use categories to help matching