Skip to main content

Testing Strategy

Follow this approach to ensure your functions work reliably:
1

Unit Test

Test your API endpoint independently
2

Integration Test

Test function definition with sample parameters
3

Conversation Test

Test with live agent conversations
4

Production Monitor

Monitor function calls in production

Unit Testing Your API

Test your API endpoint before integrating:

Using curl

Using Postman

  1. Create a new request
  2. Set method and URL
  3. Add headers
  4. Add request body
  5. Send and verify response

Expected Response

Ensure your API returns:
  • Consistent JSON structure
  • Appropriate status codes
  • Clear error messages
  • Fast response time (< 2s)

Testing Function Definitions

Validate JSON Schema

Use online validators:

Test with Sample Parameters


Conversation Testing

Create Test Scenarios

Scenario 1: Happy Path
Scenario 2: Missing Information
Scenario 3: Error Handling

Test Checklist

  • ✓ Function triggers at the right time
  • ✓ Parameters are extracted correctly
  • ✓ API call succeeds
  • ✓ Response is interpreted correctly
  • ✓ Agent continues conversation naturally
  • ✓ Errors are handled gracefully

Debugging

Enable Logging

Log all function calls:

Common Issues

Function Not Triggering

Symptoms:
  • Agent doesn’t call the function when expected
Debug Steps:
  1. Check function description is clear
  2. Add more trigger examples
  3. Make conditions more explicit
  4. Test with direct requests

Wrong Parameters Extracted

Symptoms:
  • Function called with incorrect parameter values
Debug Steps:
  1. Improve parameter descriptions
  2. Add format examples
  3. Use enums to constrain values
  4. Add validation in prompt

API Call Fails

Symptoms:
  • Function triggers but API returns error
Debug Steps:
  1. Test API endpoint with curl
  2. Check authentication headers
  3. Verify parameter format
  4. Review API logs

Monitoring Production

Track Function Calls

Monitor these metrics:
  • Function call frequency
  • Success rate
  • Average response time
  • Error rate by type

Set Up Alerts

Alert on:
  • High error rate (> 5%)
  • Slow response time (> 5s)
  • Authentication failures
  • Unexpected errors

Review Logs

Regularly review:
  • Function call logs
  • API error logs
  • Agent conversation logs
  • User feedback

Testing Tools

ngrok for Local Testing

Mock APIs

Use mock APIs for testing:

Best Practices

Start Simple

Begin with simple functions:
  1. Single parameter
  2. Simple GET request
  3. Clear success/failure states

Iterate Based on Data

  1. Deploy with logging
  2. Monitor for issues
  3. Adjust based on patterns
  4. Refine descriptions and parameters

Document Everything

  • Function purpose and triggers
  • Parameter formats and examples
  • Expected responses
  • Error scenarios
  • Testing procedures

Next Steps

Examples

View more function examples

API Integration

Complete API integration guide