> For the complete documentation index, see [llms.txt](https://docs-convai.wavy.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-convai.wavy.global/understanding-users/using-context.md).

# Context

{% hint style="info" %}
Context is used to reuse intents across several bot dialogs. To learn more about how to use context in Chatlayer.ai, follow [this tutorial](/tutorials/tutorial-using-context-for-intent-reuse.md).
{% endhint %}

## Usage example

Consider the following dialog tree

* Bot dialog `ask confirmation of pizza order`
  * Bot dialog `confirm order` - Intent: positive (yes)
  * Bot dialog `change order` - Intent: negative (no)
* Bot dialog `another joke?`
  * Bot dialog `second joke` - Intent: positive (yes)
  * Bot dialog `no more jokes` - Intent: negative (no)

We have two separate conversation in this tree. The first one orders a pizza and ends in asking the user to confirm the order. The second conversation tells a user jokes and asks if he or she would like to hear another one.

When in the `ask confirmation of pizza order` bot dialog, you want the user to be able to answer with something like *yes, confirm* or *that looks good*. On the other hand when you are in the`another joke?` bot dialog, you also want the user to be able to answer with *yeah sure* or *looks good* or a similarly positive expression.

To achieve that behaviour, we need to reuse the *Yes* intent for both bot dialogs. However, we need to give the bot a hand in determining where the user wants to go by saying that intent at that point in the flow. In Chatlayer.ai, you can guide the bot using **context**.

* Set the output context of the `ask confirmation of pizza order` bot dialog to **confirmingpizza.** The default value of the lifespan will be 1, you can leave that for now. *\*\**
* Next, in the bot dialog `confirm order`, specify that **confirmingpizza** needs to be the input context.

![](/files/-MFgE5WyqvOGuIuWp3VL)

Similarly, you can specify the output context of the `another joke?` bot dialog to **joking** and require **joking** as a required context for the bot dialog `second joke`

Now, when the 'yes' intent is recognized, the bot will check which context is active. Depending on the context, a user will be routed to either the `confirm order` bot dialog (**confirmingpizza** context was active) or to the `second joke` bot dialog (**joking** context was active)

We can repeat this configuration for the 'no' intent. In the end, we would get a configuration like this

* Bot dialog `ask confirmation of pizza orde`- Output context: **confirmingpizza**
  * Bot dialog `confirm order` - Required context: **confirmingpizza,** Intent: positive
  * Bot dialog `change order` - Required context: **confirmingpizza**, Intent: negative
* Bot dialog `another joke?` - Output context: **joking**
  * Bot dialog `second joke` - Required context: **joking**, Intent: positive
  * Bot dialog `no more jokes` - Required context: **joking**, Intent: negative

Of course, we don't want the user to be limited to this context for the rest of the conversation. After saying yes to the initial question, every other yes expression can be an answer to a different question.

To configure this you can define the **lifespan** of the output context. Each time the user enters a dialog state with an output configured this context is added to his session with an initial lifespan value as defined in the bot dialog settings. For each user message the lifespan of a context is decreased by one. When the value is 0 the context is removed from the session.

![](/files/-MFgE5X0eI3wCGT_MU1b)

All of this means that: a user is redirected to a dialog state when

1. The NLP model result has a top scoring intent with a value higher than the NLP intent recognition threshold value, and
2. This intent is linked to a bot dialog and the optional context linked to this bot dialog is available in the user session

{% hint style="info" %}
A user can have multiple contexts when navigating between different conversation flows. When multiple intent and input context combinations are found, the user's context with the highest lifespan value is taken.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs-convai.wavy.global/understanding-users/using-context.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.
