liveBook · Manning

Chat loop

As explained in Natural Language Processing in Action, Second Edition

A conversation loop is a cycle in dialogue transitions that revisits a previous conversational state or sequence.

A chat loop is a cycle in a conversation graph that returns to an earlier conversational state or sequence. Unlike a directed acyclic graph, a dialogue graph permits branches to reconnect and repeat. section 12.3.2

Loops let a chatbot revisit a thought or question while incorporating new user information. Used carefully, this recursion supports cooperative dialogue and can make responses appear more intelligent. section 12.3.2

When designing a looping dialogue:

  • Model states and transitions as a graph rather than assuming a one-way tree. section 12.3.2
  • Use repeated states to let users retry, reconsider, or continue after new information appears. section 12.3.2

Counting dialogue

A counting lesson can be represented as named states such as start, welcome, and question states, with user triggers selecting the next transition and handling correct or incorrect answers. section 12.3.2

Listing 12.1 Elementary counting lesson
- name: start
  convo_name: count by one
  convo_description: Teach counting to elementary school students
  nlp: keyword
  version: 3.1
  triggers:
    - {user_text: "__next__", target: welcome}
- name: welcome
  actions:
    - send_message: bot_text: Let's start by counting up by 1s.
    - send_message: bot_text: I will give you 3 numbers.
    - send_message: bot_text: Your answer is the next number in the list.
    - send_message:
        bot_text: For example, if I say "4, 5, 6" you should answer "7".
    - send_message: Now you try figure
  triggers:
    - {user_text: "OK", button_text: "OK", target: q1}
- name: q1
  actions:
    - send_message: bot_text: 11, 12, 13
  triggers:
    - {user_text: 14, target: correct-answer-q1}
    - {user_text: fourteen, target: correct-answer-q1}
    - {user_text: "__default__", target: wrong-answer-q1}
- name: wrong-answer-q1
  actions:
    - send_message: bot_text: Oops!
  triggers:
    - {user_text: "__next__", target: q1}
- name: correct-answer-q1
  actions:
    - send_message: bot_text: Exactly right!
  triggers:
    - {user_text: "__next__", target: q2}
- name: q2
  actions:
    - send_message: bot_text: 16, 17, 18
  triggers:
    - {user_text: 19, target: stop}
    - {user_text: nineteen, target: stop}
    - {user_text: "__default__", target: wrong-answer-q2}

Inspect a concrete dialog configuration showing named states, messages, triggers, and branching transitions. section 12.3.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines loops through graph structure and conversational recursion, but stops short of implementing loop-control logic.
Examples
Uses an elementary counting dialogue with named states, user triggers, and correct-or-incorrect answer branches.
What you can do after
Designs chatbot flows that revisit states and incorporate new information during dialogue.
How it connects
Connects conversation graphs with dialogue trees, directed acyclic graphs, decision trees, and recursion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.