Testing

View as Markdown

Testing

Test your agent thoroughly before production. Use local testing, swaig-test CLI, and test calls.

Testing Stages

1. Local Testing

  • Run agent locally
  • Test with swaig-test CLI
  • Verify SWML output

2. Tunnel Testing

  • Expose via ngrok
  • Make real calls
  • Test end-to-end

3. Production Testing

  • Deploy to production server
  • Test with real phone
  • Monitor call logs

swaig-test CLI

Test agents without making calls:

$## List available functions
$swaig-test my_agent.py --list-tools
$
$## View SWML output
$swaig-test my_agent.py --dump-swml
$
$## Execute a function
$swaig-test my_agent.py --exec get_weather --city Seattle
$
$## Raw JSON output
$swaig-test my_agent.py --dump-swml --raw

Local Server Testing

Run your agent locally:

$## Start the agent
$python my_agent.py
$
$## In another terminal, test the endpoint
$curl -X POST http://localhost:3000/ \
> -H "Content-Type: application/json" \
> -d '{"call_id": "test-123"}'

Using ngrok

Expose local server for real calls:

$## Terminal 1: Run agent
$python my_agent.py
$
$## Terminal 2: Start ngrok
$ngrok http 3000

Copy the ngrok HTTPS URL and configure in SignalWire.

Test Call Checklist

Basic Functionality

  • Call connects successfully
  • Agent greeting plays
  • Speech recognition works
  • Agent responds appropriately

Function Calls

  • Functions execute correctly
  • Results returned to AI
  • AI summarizes results properly

Edge Cases

  • Silence handling
  • Interruption handling
  • Long responses
  • Multiple function calls

Error Handling

  • Invalid input handled
  • Function errors handled gracefully
  • Timeout behavior correct

Viewing Logs

In SignalWire dashboard:

  1. Go to Logs
  2. Find your test call
  3. View details:
    • Call duration
    • SWML executed
    • Function calls
    • Errors

Debugging with Logs

Add logging to your agent:

1import logging
2
3logging.basicConfig(level=logging.DEBUG)
4
5
6class MyAgent(AgentBase):
7 def __init__(self):
8 super().__init__(name="my-agent")
9 self.log.info("Agent initialized")
10
11 def my_handler(self, args, raw_data):
12 self.log.debug(f"Function called with args: {args}")
13 self.log.debug(f"Raw data: {raw_data}")
14
15 result = "Some result"
16 self.log.info(f"Returning: {result}")
17
18 return SwaigFunctionResult(result)

Testing Transfers

Test call transfers carefully:

1def test_transfer(self, args, raw_data):
2 # Use a test number you control
3 test_number = "+15551234567"
4
5 return (
6 SwaigFunctionResult("Transferring now")
7 .connect(test_number, final=True)
8 )

Testing SMS

Test SMS sending:

1def test_sms(self, args, raw_data):
2 # Send to your own phone for testing
3 return (
4 SwaigFunctionResult("Sent test SMS")
5 .send_sms(
6 to_number="+15551234567", # Your test phone
7 from_number="+15559876543", # Your SignalWire number
8 body="Test message from agent"
9 )
10 )

Load Testing

For production readiness:

  • Test concurrent call handling
  • Monitor server resources
  • Check response times under load
  • Verify function execution at scale
  • Test database/API connection pooling

Common Test Scenarios

ScenarioWhat to Test
Happy pathNormal conversation flow
No speechSilence and timeout handling
Background noiseSpeech recognition accuracy
Rapid speechInterruption handling
Invalid requestsError handling
Function errorsGraceful degradation
Long callsMemory and stability

Automated Testing

Create test scripts:

1import requests
2
3
4def test_swml_endpoint():
5 """Test that SWML endpoint returns valid response"""
6 response = requests.post(
7 "http://localhost:3000/",
8 json={"call_id": "test-123"},
9 headers={"Content-Type": "application/json"}
10 )
11
12 assert response.status_code == 200
13 data = response.json()
14 assert "version" in data
15 assert data["version"] == "1.0.0"
16
17
18def test_function_execution():
19 """Test that functions execute correctly"""
20 response = requests.post(
21 "http://localhost:3000/swaig",
22 json={
23 "function": "get_weather",
24 "argument": {"parsed": [{"city": "Seattle"}]},
25 "call_id": "test-123"
26 }
27 )
28
29 assert response.status_code == 200