Skip to content

Voice Agent Testing

Shows how to run a voice agent test and retrieve experiment results.

This example assumes using HammingAI; is in scope and apiKey contains your HammingAI API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using var client = new HammingAIClient(apiKey);

var agentId =
    Environment.GetEnvironmentVariable("HAMMING_AGENT_ID") is { Length: > 0 } agentValue
        ? agentValue
        : throw new AssertInconclusiveException("HAMMING_AGENT_ID environment variable is not found.");

var datasetId =
    Environment.GetEnvironmentVariable("HAMMING_DATASET_ID") is { Length: > 0 } datasetValue
        ? datasetValue
        : throw new AssertInconclusiveException("HAMMING_DATASET_ID environment variable is not found.");

var toNumber =
    Environment.GetEnvironmentVariable("HAMMING_TO_NUMBER") is { Length: > 0 } numberValue
        ? numberValue
        : throw new AssertInconclusiveException("HAMMING_TO_NUMBER environment variable is not found.");

// Start a voice agent test run with the specified dataset scenarios.
var runResponse = await client.VoiceAgents.RunVoiceAgentAsync(
    agentId: agentId,
    toNumber: toNumber,
    datasetId: datasetId);

Console.WriteLine($"Voice Experiment ID: {runResponse.VoiceExperimentId}");

// Check the status of the voice experiment.
var statusResponse = await client.VoiceAgents.GetVoiceExperimentAsync(
    voiceExperimentId: runResponse.VoiceExperimentId!);

Console.WriteLine($"Status: {statusResponse.Status}");

// Retrieve call results once the experiment finishes.
var callsResponse = await client.VoiceAgents.GetVoiceExperimentCallsAsync(
    voiceExperimentId: runResponse.VoiceExperimentId!);

Console.WriteLine($"Calls: {callsResponse.Calls!.Count}");

foreach (var call in callsResponse.Calls)
{
    Console.WriteLine($"- Call {call.Id}: scoring={call.ScoringStatus}, duration={call.DurationMs}ms");
}