Interaction Loop#

This section explains how to create an interaction loop in Colang 2.0.

Usage#

In various LLM-based application, there is a need for the LLM to keep interacting with the user in a continuous interaction loop. The example below shows how a simple interaction loop can be implemented using the while construct and how the bot can be proactive when the user is silent.

 1flow main
 2  activate catching start of undefined flows
 3  activate polling llm request response 1.0
 4  activate tracking bot talking state
 5  activate generating user intent for unhandled user utterance
 6
 7  while True
 8    when unhandled user intent
 9      $response = """Response to what user said."""
10      bot say $response
11    orwhen user was silent 12.0
12      bot inform about service
13    orwhen user expressed greeting
14      bot say "Hi there!"
15    orwhen user expressed goodbye
16      bot inform "That was fun. Goodbye"
17
18flow user expressed greeting
19  user said "hi"
20    or user said "hello"
21
22flow user expressed goodbye
23  user said "goodbye"
24    or user said "I am done"
25    or user said "I have to go"
26
27flow bot inform about service
28  bot say "You can ask me anything!"
29    or bot say "Just ask me something!"

The main flow above activates the generating user intent for unhandled user utterance flow from the avatars module which uses the LLM to generate the canonical form for a user message (a.k.a., the user intent). Also, when the LLM generates an intent that is not handled by the Colang script, the unhandled user intent flow is triggered (line 8).

Line 11 in the example above shows how to use the pre-defined user was silent event to model time-driven interaction.

This example also uses the when / orwhen syntax, which is a mechanism for branching a flow on multiple paths. When a flow reaches a branching point, it will start monitoring all the branches and continue the interaction as soon as a branch is matched.

Testing#

$ nemoguardrails chat --config=<directory_with_colang_script_and_yaml_config>

> hi

Hi there!

<< pause for 12 seconds >>

You can ask me anything!