What is a state machine?

Autogenerated YouTube transcript

[00:00]. All right. So in this set of slides I’m

going to explain what a state machine is and as I start the first thing that I would like to point out is if you go to the Dialogflow CX documentation page you will notice that the first thing it starts with is it says Dialogflow CX provides a new way of designing agents taking a state machine approach to agent design. So what is the state machine it’s a concept from computer science and

[00:30] if you go to let’s say if you go to

. Wikipedia you can see that unfortunately this is a very complex explanation and I would not call it the most simple explanation for the state machine there’s no need for you to get for you for the definition to get this complex although a good thing is that the state machine definition does talk about this vending machine and I think that that’s probably the simplest

[01:00] definition that you can have for a state

machine So the vending machine is a good example of a state machine because it goes from state to state depending on how much money you have added into it. So depending on the state that is the balance that you have in your the in the coins that you have added to the vending machine you can actually choose different products and depending on the state that

[01:30] is the balance

you will get a different amount of money back from the machine if let’s say the product that you pay the product that you selected is less than the amount that you paid. So I’m going to take a simple example here let’s say that you start with zero balance. Okay that is one state that is the state the vending machine is in the state of zero balance and you add 25 cents or a quarter right at that point the balance has now

[02:00] become

25 cents that is the new state the new state is where the balance in the vending machine is 25 cents you add one more quarter and now the state has become 50 cents that is the balance of the amount in the vending machine is now 50 cents. And then you add another quarter it gets to 75 cents and so on now let’s make it a bit more

[02:30] useful and interesting let’s say that

you have exactly three products in your vending machine okay. And those are Snickers bar which costs exactly 25 cents you can have a Twix which is exactly 50 cents or a KitKat which costs exactly 75 cents so you start with the zero balance. And then you insert a quarter into the vending machine now at that point because you only have a balance of

[03:00] 25 cents

. The only product that you can buy is the Snickers bar if you were to select any of the other products as you might know the vending machine will usually complain that you don’t have enough balance to buy any other product at least any other products in this list And then let’s say you add one more 25 cents now you can select either Snickers or Twix and if you were to select Snickers and you asked for the refund you will get 25 cents

[03:30] back on the other hand if you select

Twix that means your balance has now come down to zero which means that you don’t get any money back if you are to ask for a refund it will just say that it’s empty balance or something like that. And finally if you were to add one more quarter at that point you can select any of these three items So you can either go for the Snickers or the Twix or the KitKat and in fact you can even go for one Snickers. And then one Twix and the

[04:00] vending machine

should still be able to handle that because the sum of these two is only 20 75 cents which you do have in that balance. So that’s the basic example of a vending machine and I think that understanding this is sufficient for you to understand how the agents are constructed in Dialogflow CX I don’t think from what I’ve seen till now I don’t think that you need to complicate this

[04:30] any further than just understanding a

basic state machine like the vending machine example that I have shown here.

Transcript auto-formatted using ATF

Free: Dialogflow ES Crash course for non-programmers

I recently changed the name of my website from Mining Business Data to BotFlo. To help spread the word, and to hopefully get people to bookmark my website, I am making a set of my training courses free for a few weeks. 

Learn more
"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth