Skip to content

Commit 8b959be

Browse files
committed
feat(simulate): run audio simulations against a phone number with --to-phone-number
1 parent 1d3128f commit 8b959be

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

‎cmd/lk/simulate.go‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ var simulateAudioCommand = &cli.Command{
175175
Name: "packet-loss",
176176
Usage: "Drop packets from the simulated user's audio track",
177177
},
178+
&cli.StringFlag{
179+
Name: "to-phone-number",
180+
Usage: "Call this `NUMBER` over SIP and simulate against whoever answers, instead of dispatching an agent. Requires --from-phone-number and --scenarios.",
181+
},
182+
&cli.StringFlag{
183+
Name: "from-trunk",
184+
Usage: "Outbound SIP trunk `ID` to place --to-phone-number calls through. Without it, calls go out from a LiveKit phone number.",
185+
},
186+
&cli.StringFlag{
187+
Name: "from-phone-number",
188+
Usage: "Caller `NUMBER` for --to-phone-number calls: a LiveKit phone number the project owns, or a number on --from-trunk",
189+
},
178190
},
179191
}
180192

@@ -414,14 +426,19 @@ type simulateConfig struct {
414426
scenarioGroup *livekit.ScenarioGroup
415427
scenariosPath string // path to the --scenarios file (empty when generating from source)
416428
viewModeRunID string // non-empty when `view` opens a pre-existing run
417-
liveAgent bool // --agent-name: run against an already-running agent, don't spawn one
429+
liveAgent bool // --agent-name or --to-phone-number: run against an already-running agent, don't spawn one
418430
warnings []string // config-level warnings surfaced at setup (e.g. ignored flags)
419431

420432
// impairments on the simulated user's audio, set only in SIMULATION_MODE_AUDIO
421433
backgroundNoise bool
422434
lowQualityMicrophone bool
423435
packetLoss bool
424436

437+
// --to-phone-number: dial this number over SIP in place of dispatching agentName
438+
sipCallTo string
439+
sipTrunkID string
440+
sipNumber string
441+
425442
// TODO (steveyoon): add agent deployment support
426443
// agentDeployment string
427444
}
@@ -526,6 +543,19 @@ func runSimulate(ctx context.Context, cmd *cli.Command, simulationMode livekit.S
526543
samples := int32(cmd.Int("samples"))
527544
passRate := cmd.Float("pass-rate")
528545
liveAgentName := cmd.String("agent-name")
546+
var phoneNumber, fromTrunk, fromPhoneNumber string
547+
if simulationMode == livekit.SimulationMode_SIMULATION_MODE_AUDIO {
548+
phoneNumber = cmd.String("to-phone-number")
549+
fromTrunk = cmd.String("from-trunk")
550+
fromPhoneNumber = cmd.String("from-phone-number")
551+
}
552+
if fromTrunk != "" && phoneNumber == "" {
553+
return fmt.Errorf("--from-trunk requires --to-phone-number")
554+
}
555+
// every call needs a caller: the number simulations are placed from
556+
if phoneNumber != "" && fromPhoneNumber == "" {
557+
return fmt.Errorf("--to-phone-number requires --from-phone-number")
558+
}
529559

530560
// never auto-discovered: an explicit --scenarios file is the source of
531561
// truth, otherwise scenarios are generated from the agent's source
@@ -551,7 +581,13 @@ func runSimulate(ctx context.Context, cmd *cli.Command, simulationMode livekit.S
551581

552582
// --agent-name (even empty) means: run against an already-running agent,
553583
// don't spawn one. https://docs.livekit.io/agents/server/agent-dispatch/#automatic
554-
if cmd.IsSet("agent-name") {
584+
if phoneNumber != "" {
585+
// nothing is spawned, so there's no source to generate scenarios from.
586+
if scenariosPath == "" {
587+
return fmt.Errorf("--to-phone-number requires --scenarios (no source to generate scenarios from when calling a number)")
588+
}
589+
liveAgent = true
590+
} else if cmd.IsSet("agent-name") {
555591
// nothing is spawned, so there's no source to generate scenarios from.
556592
if scenariosPath == "" {
557593
return fmt.Errorf("--agent-name requires --scenarios (no source to generate scenarios from when running against a live agent)")
@@ -632,6 +668,9 @@ func runSimulate(ctx context.Context, cmd *cli.Command, simulationMode livekit.S
632668
simCfg.backgroundNoise = cmd.Bool("background-noise")
633669
simCfg.lowQualityMicrophone = cmd.Bool("low-quality-microphone")
634670
simCfg.packetLoss = cmd.Bool("packet-loss")
671+
simCfg.sipCallTo = phoneNumber
672+
simCfg.sipTrunkID = fromTrunk
673+
simCfg.sipNumber = fromPhoneNumber
635674
}
636675

637676
if !isInteractive() {
@@ -805,6 +844,9 @@ func createSimulationRun(ctx context.Context, c *simulateConfig) (string, *livek
805844
BackgroundNoise: c.backgroundNoise,
806845
LowQualityMicrophone: c.lowQualityMicrophone,
807846
PacketLoss: c.packetLoss,
847+
SipCallTo: c.sipCallTo,
848+
SipTrunkId: c.sipTrunkID,
849+
SipNumber: c.sipNumber,
808850
Ci: ciFromEnv(),
809851
}
810852
if c.concurrency > 0 {

0 commit comments

Comments
 (0)