Stateful bots

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

What do we mean by stateful?

"I love stateless systems!"

"don't what have drawbacks?"

"don't they have drawbacks?"

Building Chatbots in Python

State machines

  • Browsing
  • Providing address, billing info
  • Order complete
Building Chatbots in Python

Implementing a state machine

INIT = 0
CHOOSE_COFFEE = 1
ORDERED = 2

Example rules:

policy_rules = {
    (INIT, "order"): (CHOOSE_COFFEE, "ok, Columbian or Kenyan?"),
    (CHOOSE_COFFEE, "specify_coffee"): 
    (ORDERED, "perfect, the beans are on their way!"),
}
Building Chatbots in Python

Using the state machine

state = INIT
def respond(state, message):
   (new_state, response) = policy_rules[(state,
                                   interpret(message))]
   return new_state, response

def send_message(state, message):
    new_state, response = respond(state, message)
    return new_state

state = send_message(state, message)
Building Chatbots in Python

Let's practice!

Building Chatbots in Python

Preparing Video For Download...