Build an agent from scratch using best practices (Advanced concepts)

This tutorial is a continuation of the Build an agent from scratch using best practices tutorial. In the previous tutorial, we used the foundational features of Dialogflow to build an agent that provides the following services to users:

  • Tells the store hours.
  • Schedules an appointment using the Google Calendar API.

Although the agent now has the ability to tell the store hours and schedule an appointment, the agent can complete user requests only if users follow the happy path, the optimal conversation where an agent successfully communicates with a user to complete a task without any error.

Figure 1. The agent's happy path for scheduling an appointment.

When we examine our current happy path for scheduling an appointment (see Figure 1), we can come up with a number of scenarios that can divert the conversation from the happy path. Before deploying the agent in the real world, we must investigate all possible events that can prevent the agent from successfully completing user requests. However, in this tutorial, we prioritize the following two highly probable scenarios:

  • The agent incorrectly hears the time and date and schedules an appointment on the wrong time slot.
  • The user selects a time slot that's not available on the calendar.

To handle these situations, we introduce the following capabilities to the scheduling service:

  • Confirmation: Before scheduling an appointment, the agent asks the user to confirm the time and date information.
  • Suggestion: If the user selects an unavailable time slot, the agent then suggests a time slot that's available on the calendar.

Dialogflow's powerful feature called contexts allows us to implement these new capabilities. In the next section, we'll review the mechanisms and usages of contexts.

Figure 2. The new capabilities of the agent: confirmation and suggestion.