# Reusing intents with context

{% hint style="info" %}
Context is used to reuse intents across several bot dialogs. To learn more about the concept of context, go to [this page](/understanding-users/using-context.md).
{% endhint %}

When the intent 'who are you' is recognised our train traveling assistant introduces himself and asks if the user would like to order a ticket.

![](/files/-MFgECmyjkB53wuHngcw)

In a totally different part of the conversation, at the end of the `Book train ticket` conversation flow the chatbot asks for a booking confirmation.

![](/files/-MFgECmz2tQm2G6Xs8Kc)

Both bot questions expect a user intent answer of **yes** or **no**. To support reuse of intents we can define a bot dialog intent linked to a certain context. The user will only be redirected to the linked bot dialog if the intent is recognized and the user is in a specific context.

* Add the `yes` and `no` intents and train them with expressions
* In the bot dialog `Confirm booking` go to the NLP tab.
* Add an **output context** `confirm_booking`. Press enter to create the output context.
* When a user reaches this bot dialog the output context is added to the user session context.

{% hint style="info" %}
For each user message the lifespan of a context is decreased by one. A user can have multiple contexts with different lifespan values.
{% endhint %}

![](/files/-MFgECn-bt875L4i5G9V)

* Add the `Confirmed Booking` **bot dialog** with **required context** `confirm_booking` and **intent** `yes` in the NLP tab. When the `yes` intent is returned by the NLP model and the user has the context `confirm_booking`, he will be redirected to this bot dialog.&#x20;

{% hint style="info" %}
When multiple intent and input context combinations are found, the user's context with the highest lifespan value is taken.
{% endhint %}

![](/files/-MFgECn0dke1Us8Lco41)

* Add the `Cancel booking` **bot dialog** with the **required context** `confirm_booking` and **intent** `no`
* Add **output context** `who_are_you` in the **bot dialog** `Who are you`.

![](/files/-MFgECn1aROrS2whRPKw)

* Add the `Yes book ticket` **bot dialog** with **required context** `who_are_you` and **intent** `yes`.
* Add the `No book ticket` **bot dialog** with **required context** `who_are_you` and **intent** `no`

## Test the flow in the emulator

* Click on the Emulator tab to test your flow. Let us ask our traveling assistent who he is.

![](/files/-MFgECn2qnF_1XRfEeLT)

* Go to the **debug mode** and select the first message in the messages list `who are you` to view the received information after sending this user message.

![](/files/-MFgECn3afYPLjojRWnF)

* The **context** `who_are_you` has been added to the user session with an initial **lifespan** value of `1` as you can see in the context section.                                                        &#x20;
* The user is redirected to the bot dialog&#x20;
* The NLP result section shows that the who are you intent has been recognised as top scoring intent.
* In the **Message Data** section we see the message being sent by the bot as answer

![](/files/-MFgECn4ljsBeOtm8kKa)

* In the **User Session** section we see the context list of the user with name and lifespan

![](/files/-MFgECn5k2bopPLqELSO)

The [next tutorial](/tutorials/tutorial-conditional-flow-navigation.md) teaches us how to redirect the user to a specific bot dialog depending on the conditions on the values in session variables.


---

# 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://docs-convai.wavy.global/tutorials/tutorial-using-context-for-intent-reuse.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.
