Contents

SiriScenario

An ordered, multiturn interaction run in one Siri session.

Declaration

struct SiriScenario

Overview

A scenario is a conversation made of a sequence of turns. Each turn is something a person says, and Siri handles the turns in one session in the order you write them. A turn carries its own expectations about what Siri does, and the scenario carries expectations about the whole conversation.

A turn’s expectations apply only to that turn. A scenario’s expectations apply to all of its turns together. Put an expectation on the scenario when it spans turns, such as an intent that finishes only after the person answers a question. Using a Calls structure’s expectation on the scenario with Calls.Ordering.disallowed fails if the call runs in any turn, or if Siri asks the person to confirm it in any turn. Use Calls.Ordering.unordered when each call happens in at least one turn, in any order.

A scenario conforms to Codable, so you can encode a set of scenarios as JSON to review alongside your project.

The following example shows a two-turn scenario with expectations that apply to the whole conversation:

let quizExampleIntents = IntentDefinitions(bundleIdentifier: "com.example.QuizExample")
let startQuizIntent = quizExampleIntents.intents["StartQuizIntent"]
let createQuizReminderIntent = quizExampleIntents.intents["CreateQuizReminderIntent"]

let scenario = SiriScenario {
    // In turn one, the person names the app but not the topic, so Siri
    // asks for one.
    UserTurn("Start a quiz in QuizExample")

    // The second turn answers with a topic.
    UserTurn("Science")
} expectation: {
    Calls {
        // The topic label comes from the parameter on the intent.
        startQuizIntent
            .expect(topic: .equals("Science"))
    }

    // Fails if Siri runs or asks the person to confirm the intent in any turn.
    Calls(.disallowed) {
        createQuizReminderIntent
    }
}

To run a scenario through Siri, pass it to a SiriScenarioLoader to make it part of the dataset for an evaluation that runs with SiriService.

Topics

Creating a scenario

Creating a scenario with expectations

Inspecting a scenario

Encoding a scenario

See Also

Scenarios