SWAIG (SignalWire AI Gateway) is a serverless function framework within SignalWire's conversational AI stack that allows developers to build AI agents capable of automating complex conversations, executing functions, using tools, and interacting with external APIs, databases, or business logic in a seamless and low-latency manner.
SWAIG bridges the gap between conversational AI and real-world business systems by providing: - Function-based AI execution during live conversations - Tool integration with CRMs, CDPs, e-commerce backends, support ticketing systems - RAG database connectivity for enhanced knowledge retrieval - Real-time call orchestration and dynamic workflow modification - Context management across channels and sessions
SWAIG operates on two core strategies that share a common foundation: defining functions with desired arguments that the AI can call when appropriate during conversations.
The AI agent sends structured function calls to an external server where additional logic is processed.
How it works: 1. AI determines a function should be called based on conversation context 2. Function name and collected arguments are sent to a webhook endpoint 3. External CGI script processes the request and can perform any server-side logic 4. Server responds with appropriate data or SWML instructions 5. Response can include telephony commands, prompt updates, or conversation modifications
Use cases: - Complex business logic requiring custom code - Integration with proprietary systems - Real-time data processing and analysis - Multi-step workflows requiring server state
Instead of external CGI, developers define JSON-based execution templates that process function calls locally without requiring a hosted backend.
How it works: 1. Function signature includes JSON template definition 2. Parser enters JSON structure when function is called 3. Common paradigms like pattern matching, REST API calls, and data fetching are handled 4. Variable expansion and result looping occur within the template 5. Templated JSON response is returned without external hosting
Advantages: - Completely serverless deployment - Reduced latency (no external network calls) - Simplified architecture for common integration patterns - Built-in support for popular API patterns
Use cases: - Classic third-party API integration (Slack, Salesforce, etc.) - Simple data retrieval and formatting - Pattern matching and conditional responses - Rapid prototyping and development
Developers can define functions that AI agents call during live conversations: - External REST API triggers: Connect to any web service - CRM system interactions: Salesforce, HubSpot, custom CRMs - Database record retrieval: Customer data, product catalogs, order history - Calculation engines: Pricing, availability, complex business rules
SWAIG allows AI agents to modify call logic dynamically: - Call transfers: Route to human agents or other systems - Media playback: Play messages, videos, or hold music - IVR transitions: Switch between AI and traditional menu systems - Context switching: Change conversation focus based on user needs
Because SWAIG functions execute directly from conversation logic: - No middleware latency: Direct integration with telephony stack - Parallel processing: Multiple functions can execute simultaneously - Optimized networking: Minimal network hops for external calls - Efficient caching: Frequently accessed data stored locally
SWAIG maintains sophisticated conversation state: - Cross-session context: Remember previous interactions - Multi-channel continuity: Maintain context across voice, video, text - Conversation history: Full transcript and decision tracking - User preferences: Personalized responses and behavior
Multiple conversation contexts within a single agent: - Role-based contexts: Sales, support, technical assistance - Specialized system prompts: Different instructions per context - Security permissions: Context-specific access controls - Tool availability: Different functions per conversation type
# SWAIG function for customer lookup
customer_lookup:
function: get_customer_info
purpose: Retrieve customer account details
argument:
customer_id:
type: string
description: Customer account identifier
data_map:
expressions:
- pattern: ".*"
url: "https://api.crm.com/customers/${customer_id}"
headers:
Authorization: "Bearer ${api_token}"
output:
customer_name: "${response.data.name}"
account_status: "${response.data.status}"
last_order: "${response.data.orders[0].date}"
SWAIG works seamlessly with SignalWire's DataSphere RAG stack: - Document loading: Any format documents indexed for search - Semantic search: Find relevant information during conversations - Response incorporation: Blend retrieved data with AI responses - Real-time updates: Fresh data available immediately