Skip to main content

Node - #multi_turn_interact#

Overview

  • Only "#single_turn_interact#" and "#multi_turn_interact#" are the "only two" nodes that can interact with the user, and the InfoItems defined in these two types of nodes will be extracted from the user input.
  • After entering the "#multi_turn_interact#" node, the system will stay at the node and perform multiple rounds of interaction until encountering subsequent "exit_intent"; Of course, it can also be triggered at this time (returning to the "#multi_turn_interact#" node after the trigger execution is completed), or topic switching of the "#single_turn_interact#" node with the "topic" InfoItem modifier; At this time, the AI ​​will respond to the user's questions or requests based on global response script, static and/or dynamic reference information, or the knowledge of the LLM itself; For static and/or dynamic reference information, user input in historical dialogue records will be used together as a semantic matching target for information retrieval, which will have the effect of conducting multiple rounds of knowledge questions and answers on a certain topic
  • Furthermore, in each round of interaction of the node, AI will:
    • extract the latest value of the InfoItem defined in the "extract_info" attribute
    • execute the script or function defined in the "execute_function" (Python ChatTree) or "execute_script" (Xmind ChatTree) attribute to perform related processing
    • use the content of the "{_multi_turn_interact_dynamic_prompt_}" system InfoItem as a prompt word to accurately and dynamically control the dialogue requirements of this round
    • exit the node's interaction loop if the user intent defined in the "exit_intent" attribute is met, or the value of "{_multi_turn_interact_exit_reason_}" is dynamically set in the "execute_function" (Python ChatTree) or "execute_script" (Xmind ChatTree) attribute will also exit the interaction loop of the node
  • For Xmind ChatTree, the first line of the node content must be "#multi_turn_interact#", and then the content starting from the second line is the following attributes (each attribute is composed of two parts starting with "@" and separated by "=", the first is the attribute name, and the second is the attribute content), such as:
    #multi_turn_interact#
    @... = ...
    @... = ...
    @... =
    ...
    ...
    ...
    @... = ...|...|...
  • For Python ChatTree, the first parameter of chattree.create_node() must be "#multi_turn_interact#", and the second parameter dict contains the following keys (i.e. attributes). If there is no special explanation, the value (i.e. attribute content) type is str, such as:
    multi_turn_node = chattree.create_node("#multi_turn_interact#", {
    "...": "...",
    "...": ["...","..."],
    "...": "...\n...\n",
    "...": [{"...":"...","...":"...","...":"..."}, ...],
    })
  • Different from the "#single_turn_interact#" node, this node cannot be followed by the "#user_intent#" node, and it cannot be executed repeatedly through the "#actvity#ask_again" method
  • The "hospital_registration" and "first_aid_qa" ChatTree examples in "ChatTree Examples" have this node

"notify_not_found_reference_information" attribute

(The Xmind ChatTree is in the form of "@notify_not_found_reference_information =...")

  • In the current multiple rounds of interaction, if the user's latest question cannot find relevant content to answer from the system's preset static and/or dynamic reference information, you can set a default reply that is directly output to the user, such as "Sorry, there is currently no answer to your question in my knowledge base."
  • Note that the "prompt word" mode with "<" and ">" at both ends cannot be used here (see "Text Output")
  • The "first_aid_qa" ChatTree example in "ChatTree Examples" has this attribute

"extract_info" attribute

(Xmind ChatTree is in the form of "@extract_info =...")

  • For Xmind ChatTree, the attribute content is a number of InfoItems. Multiple InfoItems have multiple lines. Each (each line) InfoItem is divided into the following three sections:
    • The first piece is the InfoItem {...}, for details, see "InfoItem"
    • The second piece is the InfoItem constraint (...), enclosed in parentheses at both ends. For details, see "InfoItem", optional
    • The third piece is a number of values [...|...|...] separated by "|" that are modifier of the InfoItem. Both ends are enclosed in square brackets. For details, please see "Node - #single_turn_interact#" for instructions on modifier of InfoItems (but it can only be "explicit", "implicit", "repeat", "incremental" and "json") A single line such as: {...} or {...}(...) or {...}(...)[...|...|...]
  • For Python ChatTree, the attribute content is a list, each element of the list is a dict, and the dict has the following keys:
    • "infoitem": name of a single InfoItem, str type, for details, see "InfoItem"
    • "infoitem_constraint": that is, constraints on InfoItems. For details, see "InfoItems". This key is optional.
    • "infoitem_modifier": See the description of "infoitem_modifier" in "Node - #single_turn_interact#" (but it can only be "explicit", "implicit", "repeat", "incremental", and "json"); this key is optional
    • "infoitem_options": the value is a list whose elements are str. For details, see "InfoItem". This key is optional; this key is only supported by python ChatTree.
    • "infoitem_options_modifier": the value is a list whose elements are str. For details, see "InfoItem". This key is optional; this key is only supported by python ChatTree.
  • For these InfoItems:
    • Each time this node completes a round of interaction, the system will extract the latest values ​​of these InfoItems from the current dialogue record.
    • Can be initialized before "#multi_turn_interact#" (through nodes such as "#activity#execute_script")
  • The "hospital_registration" ChatTree example in "ChatTree Examples" has this attribute

"execute_function" (Python ChatTree) or "execute_script" (Xmind ChatTree) attribute

(The Xmind ChatTree is in the form of "@execute_script = ...")

  • For Xmind ChatTree, the attribute content is a multi-line Python script (in the script, InfoItems can be accessed or assigned based on ctx), such as:
    ...
    ...ctx['{...}']...
    ...
  • For Python ChatTree, the attribute content is a dict, where key is "execute_function" and value is a Python function name or lambda expression (function definition or lambda must have a ctx parameter and can access or assign values ​​to InfoItems based on ctx), such as:
    def xxxx_func(ctx):
    ...
    ...ctx['{...}']...
    ...
    multi_turn_node = chattree.create_node("#multi_turn_interact#", {
    ...
    "execute_function": xxxx_func,
    ...
    })
    multi_turn_node = chattree.create_node("#multi_turn_interact#", {
    ...
    "execute_function": lambda ctx : ...ctx["{...}"]...,
    ...
    })
  • After each round of interaction of this node and extraction of the above InfoItems, the system will execute the above script or function
  • If you want to exit the interaction loop of this node, you can assign the exit reason to the system InfoItem {_multi_turn_interact_exit_reason_} in a script or function; after exiting, the "#condition#script" node subsequent to the "#multi_turn_interact#" node can execute different branches based on {_multi_turn_interact_exit_reason_}
  • In each round of interaction of this node, the system InfoItem {_multi_turn_interact_dynamic_prompt_} can be assigned at any time to directly and dynamically control the specific dialogue content and dialogue requirements of each round.
  • For more information, see "Python Script/Function"
  • The "hospital_registration" ChatTree example in "ChatTree Examples" has this attribute

"exit_intent" attribute

(The Xmind ChatTree is in the form of "@exit_intent = ...")

  • For Xmind ChatTree, the attribute content is the description of the exit intents. Multiple ones are separated by "|", and the one with higher priority is placed first.
  • For Python ChatTree, the attribute content is a list. Each element in the list is a str, which represents a natural language description of exit intent. The one with higher priority is placed first.
  • After each round of interaction, this node will judge the above-mentioned exit intent (that is, the user intent as a condition for exiting multi-round interaction, see "intent"). When satisfied, {_multi_turn_interact_exit_reason_} will be assigned a corresponding description, and the next step will exit the interaction loop; similarly, the "#condition#script" node subsequent to the "#multi_turn_interact#" node can be based on {_multi_turn_interact_exit_reason_} to execute different branches