Write agentic apps once, run with any LLM provider ✨

Customer Support Bot

Build an autonomous customer support agent that can handle queries, look up information, and take actions using AISuite's automatic function calling.

24/7 Intelligent Support

Autonomous agent that resolves customer issues with function calling

Key Features

  • Automatic Function Execution: Bot autonomously calls functions to resolve issues
  • Multi-Turn Conversations: Uses max_turns for complex issue resolution
  • Knowledge Base Integration: Searches documentation and FAQs
  • Escalation Management: Creates tickets for complex issues

Implementation

support_bot.py
import aisuite as ai
from typing import Dict, List, Any
import json
from datetime import datetime

class CustomerSupportBot:
    """Intelligent support agent with function calling"""
    
    def __init__(self):
        self.client = ai.Client()
        self.model = "openai:gpt-4"
        
    def lookup_order(self, order_id: str) -> Dict:
        """Look up order status - example function"""
        # In production, this would query a real database
        return {
            "order_id": order_id,
            "status": "shipped",
            "tracking": "UPS123456",
            "expected_delivery": "2024-01-20"
        }
    
    def search_knowledge_base(self, query: str) -> List[str]:
        """Search internal knowledge base"""
        # Simulated KB search
        return [
            "Return policy: 30 days from purchase",
            "Free shipping on orders over $50",
            "Customer service hours: 9 AM - 6 PM EST"
        ]
    
    def create_ticket(self, issue: str, priority: str) -> str:
        """Create support ticket for complex issues"""
        ticket_id = f"TKT-{datetime.now().strftime('%Y%m%d%H%M')}"
        return f"Created ticket {ticket_id} with priority: {priority}"
    
    def handle_customer_query(self, query: str) -> str:
        """Main conversation handler with max_turns for autonomous resolution"""
        
        # Define available functions for the bot
        functions = [
            self.lookup_order,
            self.search_knowledge_base,
            self.create_ticket
        ]
        
        # Initial system prompt
        messages = [
            {
                "role": "system",
                "content": """You are a helpful customer support agent.
                Use the available functions to help customers with their queries.
                Be friendly, professional, and try to resolve issues quickly.
                If you cannot resolve an issue, create a support ticket."""
            },
            {
                "role": "user",
                "content": query
            }
        ]
        
        # Let AISuite handle the function calling loop automatically
        response = self.client.chat.completions.create(
            model=self.model,
            messages=messages,
            functions=functions,
            max_turns=5  # Allow up to 5 turns to resolve the issue
        )
        
        # Return the final response
        return response.choices[0].message.content

# Example usage
bot = CustomerSupportBot()

# Customer queries
queries = [
    "What's the status of my order #12345?",
    "I need to return a product I bought last week",
    "My package never arrived and it's been 2 weeks",
]

for query in queries:
    print(f"\n👤 Customer: {query}")
    response = bot.handle_customer_query(query)
    print(f"🤖 Support Bot: {response}")
    print("-" * 50)

✨ AISuite Magic

  • ▸Automatic Function Conversion: Python functions automatically become tools
  • ▸Execution Loop: max_turns handles the entire conversation flow
  • ▸No JSON Schema: Functions are introspected automatically

Bot Capabilities

📦 Order Management

  • • Track shipments
  • • Check order status
  • • Process returns
  • • Update delivery info

💳 Account Services

  • • Password resets
  • • Billing inquiries
  • • Subscription management
  • • Profile updates

Extend It

💬 Add Live Chat UI

Integrate with chat widgets for real-time customer interactions

📊 Analytics Dashboard

Track resolution rates, common issues, and bot performance