# 2.4. Multi-turn Dialogue

All examples in the previous session are single-turn dialogues, where users get to interact with the system only once. Let us design a multi-turn dialogue:

{% code lineNumbers="true" %}

```python
transitions = {
    'state': 'start',
    '`Hello. How are you?`': {
        '[{good, fantastic}]': {
            '`Glad to hear that you are doing well :)`': {
                '[{how, and}, {you, going}]': {
                    '`I feel superb. Thank you!`': 'end'
                }
            }
        },
        'error': {
            '`Got it; thanks for sharing.`': 'end'
        },
    }
}
```

{% endcode %}

* `#5`: after the system says "*Glad to ...*", it matches the input with those conditions.
* `#6`: if the condition in `#5` is true, the system responds with "*I feel superb ..."*.

{% tabs %}
{% tab title="Output" %}

```
S: Hello. How are you?
U: Good!
S: Glad to hear that you are doing well :)
U: How are you doing?
S: I feel superb. Thank you!
```

{% endtab %}

{% tab title="Error" %}

```
S: Hello. How are you?
U: Fantastic
S: Glad to hear that you are doing well :)
U: Thank you!
Traceback (most recent call last):
...
```

{% endtab %}
{% endtabs %}

The condition in `#6` does not come with the default action indicated by an error transition. Let us create an error transition for it:

{% code lineNumbers="true" %}

```python
def multiturn_dialogue() -> DialogueFlow:
    transitions = {
        'state': 'start',
        '`Hello. How are you?`': {
            '[{good, fantastic}]': {
                '`Glad to hear that you are doing well :)`': {
                    '[{how, and}, {you, going}]': {
                        '`I feel superb. Thank you!`': 'end'
                    },
                    'error': {
                        '`You are the best!`': 'end'
                    }
                }
            },
            'error': {
                '`Got it; thanks for sharing.`': 'end'
            },
        }
    }

    df = DialogueFlow('start', end_state='end')
    df.load_transitions(transitions)
    return df


if __name__ == '__main__':
    multiturn_dialogue().run()
```

{% endcode %}

* `#10`: prompts the error statement for any other inputs.

{% tabs %}
{% tab title="Output" %}

```
S: Hello. How are you?
U: Fantastic!
S: Glad to hear that you are doing well :)
U: Thank you!
S: You are the best!
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emory.gitbook.io/conversational-ai/2.-dialogue-graph/2.4.-multi-turn-dialogue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
