Test CLI
A comprehensive command-line tool for testing SignalWire AI Agents SWAIG functions and SWML generation locally with complete environment simulation and real API execution.
Overview
The swaig-test
CLI tool provides a complete testing environment for:
- SWAIG Functions: Both webhook and DataMap functions with automatic type detection
- SWML Generation: Static and dynamic agent SWML document testing with realistic fake data
- Mock Requests: Complete FastAPI Request simulation for dynamic agent testing
The tool automatically detects function types, provides appropriate execution environments, and simulates the SignalWire platform locally while making real HTTP requests for DataMap functions.
Key Features
--exec
Syntax: Modern CLI-style function arguments- Auto-Detection: Automatically detects webhook vs DataMap functions - no manual flags needed
- Complete DataMap Simulation: Full processing including URL templates, responses, and fallbacks
- SWML Testing: Generate and test SWML documents with realistic fake call data
- Dynamic Agent Support: Test request-dependent SWML generation with mock request objects
- Real HTTP Execution: DataMap functions make actual HTTP requests to real APIs
- Comprehensive Simulation: Generate realistic post_data with all SignalWire metadata
- Advanced Template Engine: Supports all DataMap variable syntax (
${args.param}
,${response.field}
,${array[0].property}
) - Flexible CLI Syntax: Support both
--exec
and JSON argument styles - Override System: Precise control over test data with dot notation paths
- Mock Request Objects: Complete FastAPI Request simulation for dynamic agents
- Verbose Debugging: Detailed execution tracing for both function types
- Flexible Data Modes: Choose between minimal, comprehensive, or custom post_data
- Serverless Environment Simulation: Complete platform simulation for Lambda, CGI, Cloud Functions, and Azure Functions with environment variable management
- Multi-agent support: Target specific agents with
--route
and--agent-class
selection - Automatic log suppression: Logs are suppressed by default (use
--verbose
to enable logs) - Enhanced parameter display: Shows all JSON Schema constraints including enum values, min/max, patterns
Quick Start
Agent Discovery
The tool can automatically discover agents in Python files:
# Discover all agents in a file (auto-runs when no other args provided)
swaig-test examples/joke_skill_demo.py
# Explicitly list available agents
swaig-test matti_and_sigmond/dual_agent_app.py --list-agents
# List agents with details
swaig-test matti_and_sigmond/dual_agent_app.py --list-agents --verbose
Example Output:
Available agents in matti_and_sigmond/dual_agent_app.py:
MattiAgent
Type: Ready instance
Name: Matti
Route: /matti-agent
Description: Advanced agent with custom tools and weather integration
SigmondAgent
Type: Ready instance
Name: Sigmond
Route: /sigmond-agent
Description: Advanced conversational agent with data access
To use a specific agent with this tool:
swaig-test matti_and_sigmond/dual_agent_app.py [tool_name] [args] --agent-class <AgentClassName>
swaig-test matti_and_sigmond/dual_agent_app.py [tool_name] [args] --route <route_path>
Examples:
swaig-test matti_and_sigmond/dual_agent_app.py --list-tools --agent-class MattiAgent
swaig-test matti_and_sigmond/dual_agent_app.py --dump-swml --agent-class SigmondAgent
swaig-test matti_and_sigmond/dual_agent_app.py --list-tools --route /matti-agent
swaig-test matti_and_sigmond/dual_agent_app.py --dump-swml --route /sigmond-agent
List Available Functions
# List functions in single-agent file (auto-selected)
swaig-test examples/joke_skill_demo.py --list-tools
# List functions for specific agent in multi-agent file
swaig-test matti_and_sigmond/dual_agent_app.py --agent-class MattiAgent --list-tools
# List functions using route selection
swaig-test matti_and_sigmond/dual_agent_app.py --route /matti-agent --list-tools
# Detailed function listing with schemas
swaig-test examples/joke_skill_demo.py --list-tools --verbose
Example Output:
Available SWAIG functions:
get_joke - Get a random joke from API Ninjas (DataMap function - serverless)
Parameters:
type (string [options: jokes, dadjokes]) (required): Type of joke to get
Config: {"data_map": {...}, "parameters": {...}}
calculate - Perform mathematical calculations and return the result (LOCAL webhook)
Parameters:
expression (string) (required): Mathematical expression to evaluate
precision (integer [min: 0, max: 10]): Number of decimal places (default: 2)
Test SWML Generation
# Basic SWML generation with fake call data
swaig-test examples/my_agent.py --dump-swml
# Raw SWML JSON output for piping
swaig-test examples/my_agent.py --dump-swml --raw | jq '.'
# Verbose SWML testing with detailed fake data
swaig-test examples/my_agent.py --dump-swml --verbose
# Custom call types and scenarios
swaig-test examples/my_agent.py --dump-swml --call-type sip --call-direction outbound
# Test SWML in serverless environments
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml
swaig-test examples/my_agent.py --simulate-serverless cgi --cgi-host example.com --dump-swml
Logging and output control
By default, swaig-test
suppresses agent logs to keep output clean. Use these options to control logging:
# Default behavior - logs are suppressed
swaig-test examples/my_agent.py --exec my_function --param value
# Enable logs with --verbose flag
swaig-test examples/my_agent.py --verbose --exec my_function --param value
# Clean SWML output (logs always suppressed)
swaig-test examples/my_agent.py --dump-swml --raw
The tool automatically:
- Suppresses logs by default for cleaner output
- Shows logs when
--verbose
is specified - Always suppresses output when using
--dump-swml
to ensure valid JSON
Serverless Environment Simulation
The CLI tool provides comprehensive serverless platform simulation, allowing you to test your agents in Lambda, CGI, Cloud Functions, and Azure Functions environments locally without deployment.
Quick Start with Serverless Simulation
# Test agent in Lambda environment
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml
# Test function execution in Lambda context
swaig-test examples/my_agent.py --simulate-serverless lambda --exec my_function --param value
# Test with custom Lambda configuration
swaig-test examples/my_agent.py --simulate-serverless lambda --aws-function-name my-func --aws-region us-west-2 --exec my_function
# Test CGI environment with custom host
swaig-test examples/my_agent.py --simulate-serverless cgi --cgi-host example.com --dump-swml
# Test with environment variables
swaig-test examples/my_agent.py --simulate-serverless lambda --env DEBUG=1 --env TEST_MODE=cli --exec my_function
Supported Serverless Platforms
Platform | Simulation Flag | Key Features |
---|---|---|
AWS Lambda | --simulate-serverless lambda | Function URLs, API Gateway, environment detection |
CGI | --simulate-serverless cgi | HTTP host, script paths, HTTPS simulation |
Google Cloud Functions | --simulate-serverless cloud_function | Function URLs, project configuration |
Azure Functions | --simulate-serverless azure_function | Function URLs, environment settings |
Platform-Specific Configuration
AWS Lambda Simulation
# Default Lambda simulation with auto-generated URLs
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml
# Custom Lambda function configuration
swaig-test examples/my_agent.py --simulate-serverless lambda \
--aws-function-name my-custom-function \
--aws-function-url https://abc123.lambda-url.us-west-2.on.aws/ \
--aws-region us-west-2 \
--dump-swml
# API Gateway configuration
swaig-test examples/my_agent.py --simulate-serverless lambda \
--aws-api-gateway-id abc123def \
--aws-region us-east-1 \
--aws-stage prod \
--exec my_function --param value
# Test function execution in Lambda context
swaig-test examples/my_agent.py --simulate-serverless lambda \
--exec get_weather --location "San Francisco" \
--full-request
Lambda Environment Variables Set:
AWS_LAMBDA_FUNCTION_NAME
AWS_LAMBDA_FUNCTION_URL
(if using Function URLs)AWS_API_GATEWAY_ID
(if using API Gateway)AWS_REGION
_HANDLER
CGI Simulation
# Basic CGI simulation
swaig-test examples/my_agent.py --simulate-serverless cgi --cgi-host example.com --dump-swml
# Custom CGI configuration
swaig-test examples/my_agent.py --simulate-serverless cgi \
--cgi-host my-server.com \
--cgi-script-name /cgi-bin/my-agent.cgi \
--cgi-https \
--cgi-path-info /custom/path \
--exec my_function --param value
# Test CGI with specific environment
swaig-test examples/my_agent.py --simulate-serverless cgi \
--cgi-host production.example.com \
--cgi-https \
--env REMOTE_USER=admin \
--dump-swml
CGI Environment Variables Set:
GATEWAY_INTERFACE=CGI/1.1
HTTP_HOST
(from --cgi-host)SCRIPT_NAME
(from --cgi-script-name)HTTPS=on
(if --cgi-https)PATH_INFO
(from --cgi-path-info)
Google Cloud Functions Simulation
# Basic Cloud Function simulation
swaig-test examples/my_agent.py --simulate-serverless cloud_function --dump-swml
# Custom GCP configuration
swaig-test examples/my_agent.py --simulate-serverless cloud_function \
--gcp-project my-project \
--gcp-function-url https://my-function-abc123.cloudfunctions.net \
--gcp-region us-central1 \
--gcp-service my-service \
--exec my_function --param value
Cloud Function Environment Variables Set:
GOOGLE_CLOUD_PROJECT
FUNCTION_URL
(if provided)GOOGLE_CLOUD_REGION
K_SERVICE
(Knative service name)
Azure Functions Simulation
# Basic Azure Functions simulation
swaig-test examples/my_agent.py --simulate-serverless azure_function --dump-swml
# Custom Azure configuration
swaig-test examples/my_agent.py --simulate-serverless azure_function \
--azure-env production \
--azure-function-url https://my-function.azurewebsites.net \
--exec my_function --param value
Azure Functions Environment Variables Set:
AZURE_FUNCTIONS_ENVIRONMENT
WEBSITE_SITE_NAME
- Custom function URL (if provided)
Environment Variable Management
Manual Environment Variables
# Set custom environment variables
swaig-test examples/my_agent.py --simulate-serverless lambda \
--env API_KEY=secret123 \
--env DEBUG=true \
--env TIMEOUT=30 \
--exec my_function
# Multiple environment variables
swaig-test examples/my_agent.py --simulate-serverless cgi \
--env DB_HOST=localhost \
--env DB_PORT=5432 \
--env LOG_LEVEL=info \
--cgi-host example.com \
--dump-swml
Environment Files
Create environment files for reusable configurations:
# Create environment file
cat > lambda.env << EOF
AWS_LAMBDA_FUNCTION_NAME=my-production-function
AWS_REGION=us-west-2
API_KEY=prod_key_123
DEBUG=false
TIMEOUT=60
EOF
# Use environment file
swaig-test examples/my_agent.py --simulate-serverless lambda \
--env-file lambda.env \
--exec my_function --param value
# Override specific variables from file
swaig-test examples/my_agent.py --simulate-serverless lambda \
--env-file lambda.env \
--env DEBUG=true \
--env AWS_REGION=us-east-1 \
--dump-swml
Webhook URL Generation
The serverless simulation automatically generates appropriate webhook URLs for each platform:
Platform-Specific URLs
Platform | Example Webhook URL |
---|---|
Lambda (Function URL) | https://abc123.lambda-url.us-east-1.on.aws/swaig/ |
Lambda (API Gateway) | https://api123.execute-api.us-east-1.amazonaws.com/prod/swaig/ |
CGI | https://example.com/cgi-bin/agent.cgi/swaig/ |
Cloud Functions | https://my-function-abc123.cloudfunctions.net/swaig/ |
Azure Functions | https://my-function.azurewebsites.net/swaig/ |
URL Generation Examples
# Lambda Function URL
swaig-test examples/my_agent.py --simulate-serverless lambda \
--aws-function-url https://custom123.lambda-url.us-west-2.on.aws/ \
--dump-swml --format-json | jq '.sections.main[1].ai.SWAIG.defaults.web_hook_url'
# CGI with custom host
swaig-test examples/my_agent.py --simulate-serverless cgi \
--cgi-host my-production-server.com \
--cgi-https \
--dump-swml --format-json | jq '.sections.main[1].ai.SWAIG.defaults.web_hook_url'
# Cloud Functions with custom URL
swaig-test examples/my_agent.py --simulate-serverless cloud_function \
--gcp-function-url https://my-custom-function.cloudfunctions.net \
--dump-swml --format-json | jq '.sections.main[1].ai.SWAIG.defaults.web_hook_url'
Function Execution in Serverless Context
Test function execution with platform-specific request/response formats:
Lambda Function Execution
# Test function in Lambda context
swaig-test examples/my_agent.py --simulate-serverless lambda \
--exec get_weather --location "Miami" \
--full-request
# Example output shows Lambda event format
swaig-test examples/my_agent.py --simulate-serverless lambda \
--exec calculate --expression "2+2" \
--full-request --format-json
Lambda Response Format:
{
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"result\": 4, \"expression\": \"2+2\"}"
}
CGI Function Execution
# Test function in CGI context
swaig-test examples/my_agent.py --simulate-serverless cgi \
--cgi-host example.com \
--exec my_function --param value
Advanced Serverless Features
Environment Presets
The tool includes built-in environment presets for each platform:
# Use default Lambda preset
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml
# Override preset values
swaig-test examples/my_agent.py --simulate-serverless lambda \
--aws-function-name custom-name \
--env CUSTOM_VAR=value \
--dump-swml
Environment Conflict Resolution
The tool automatically clears conflicting environment variables between platforms:
# Switching platforms clears previous environment
export AWS_LAMBDA_FUNCTION_NAME=old-function
# This will clear AWS variables and set GCP variables
swaig-test examples/my_agent.py --simulate-serverless cloud_function \
--gcp-project new-project \
--dump-swml
Testing Multiple Platforms
# Test the same agent across multiple platforms
for platform in lambda cgi cloud_function azure_function; do
echo "Testing $platform..."
swaig-test examples/my_agent.py --simulate-serverless $platform \
--exec my_function --param value
done
# Compare SWML generation across platforms
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml > lambda.swml
swaig-test examples/my_agent.py --simulate-serverless cgi --cgi-host example.com --dump-swml > cgi.swml
diff lambda.swml cgi.swml
Debugging Serverless Simulation
Verbose Mode
# See detailed environment setup
swaig-test examples/my_agent.py --simulate-serverless lambda \
--verbose \
--dump-swml
# Debug function execution
swaig-test examples/my_agent.py --simulate-serverless lambda \
--verbose \
--exec my_function --param value \
--full-request
Environment Inspection
# Show environment variables being set
swaig-test examples/my_agent.py --simulate-serverless lambda \
--env DEBUG=1 \
--exec get_status # Use a function that returns environment info
Format Options
# Pretty-print JSON output
swaig-test examples/my_agent.py --simulate-serverless lambda \
--dump-swml --format-json
# Raw JSON for piping
swaig-test examples/my_agent.py --simulate-serverless lambda \
--dump-swml --format-json | jq '.sections.main[1].ai.SWAIG.functions[0]'
Serverless Best Practices
Development Workflow
- Start with local testing: Test your agent normally first
- Test each platform: Use serverless simulation for target platforms
- Verify webhook URLs: Check that URLs are generated correctly for your platform
- Test environment variables: Ensure your agent works with platform-specific variables
- Test function execution: Verify functions work in serverless context
Platform-Specific Testing
# Lambda development workflow
swaig-test examples/my_agent.py --list-tools # First test locally
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml # Check SWML
swaig-test examples/my_agent.py --simulate-serverless lambda --exec my_function --param value # Test functions
# Production-like testing
swaig-test examples/my_agent.py --simulate-serverless lambda \
--env-file production.env \
--aws-function-name prod-my-agent \
--aws-region us-east-1 \
--exec critical_function --input "test"
Environment Management
# Development environment
cat > dev.env << EOF
DEBUG=true
LOG_LEVEL=debug
API_TIMEOUT=10
EOF
# Production environment
cat > prod.env << EOF
DEBUG=false
LOG_LEVEL=info
API_TIMEOUT=30
EOF
# Test both environments
swaig-test examples/my_agent.py --simulate-serverless lambda --env-file dev.env --exec my_function
swaig-test examples/my_agent.py --simulate-serverless lambda --env-file prod.env --exec my_function