Working with Dialogflow CX via Python Series — Part 2— Flow Operations

Anjali Chimnani
Google Cloud - Community
3 min readFeb 4, 2024

We are back with another part of our Working with Dialogflow CX via Python Series. Dive into Dialogflow CX Flows with Python! In this series installment, we’ll cover Flow basics, operations, and automation. Building on Part 1’s Agent focus, we’ll enhance our Python framework to streamline Flow management.

Let’s get started!!

Dialogflow CX Flows are used to define conversational topics and the associated conversational paths. Think of them as blueprints for conversations. They outline how a user can interact with your agent. Each agent starts with a ‘Default Start Flow,’ the main entry point for interactions..

Imagine a Travel virtual agent. Users might want to book a flight or cancel one — two very different tasks! Dialogflow CX Flows handle these distinct needs. We’d create a ‘Book Flight’ flow and a ‘Cancel Flight’ flow, each tailored to gather the right information.

Dialogflow CX Agent with 2 Flows modeled for Travel use case

Each flow in turn has multiple pages that define the different stages or states which when combined together achieves the purpose of the flow. For our example flow Book Flight, we can model it with pages to gather and confirm user travel details i.e. source, destination, dates, etc. and then process and share the booking details to the user.

Dialogflow CX Flow — Book Flight

Similarly, we model the Cancel Flight flow with pages to gather the booking details i.e. booking id, user id, etc. and then process and confirm the cancellation.

Dialogflow CX Flow — Cancel Flight

Flows actively manage user interactions. They understand intent, gather necessary details, take action, and communicate seamlessly with the user. Think of a Dialogflow CX agent as a network of these flows, with the ‘Default Start Flow’ as the central hub.

We created an Agent in the Part 1 of this series named as cai_agent_library. We used the dialogflowcx_v3 (stable) Python libraries to perform the different operations. We will extend this framework created in the first part.

Let’s dive in!

Flows package in the DF CX library provides us with all the operations that can be performed on the Flows. We will use a few methods in our code that are most commonly used i.e. creating, training, validating, exporting and deleting a flow. For this purpose, create a file as flow_operations.py and add all the different operations

touch flow_operations.py

Lets extend the framework created in Part 1 to now operate on Flows.

In addition to creation of agent cai_agent_library in our Google Cloud Project (to be replaced in the code below at <>) in global location in English language in Asia/Calcutta time zone, we will now create 2 flows, based on our example Travel agent example — Book Flight and Cancel Flight. We will fetch the Default start flow object with its flow ID i.e. 00000000–0000–0000–0000–000000000000. This is the ID of the Default Start Flow in any agent.

vi dialogflow.py

This versatile Python framework now handles the Dialogflow CX lifecycle involving agents and flows: agent creation, flow design (like ‘Book Flight’, ‘Cancel Flight’), management, validation, export, and deletion.

Lets see how it appears in the Dialogflow CX console (after commenting our deletion code!!)

Agent cai-agent-library with 2 Flows and a Default Start Flow

Another milestone reached! We’ve empowered our framework with Flow mastery. Let’s see what other conversational AI challenges we can tackle next!

--

--