# Context

<figure><img src="/files/52f7qhOIe6xc9o9g2e8J" alt=""><figcaption></figcaption></figure>

Context makes it possible to reuse the same intent in several blocks, an important feature in bot building!&#x20;

<details>

<summary>Example</summary>

Let's learn how to use context with this short example:

So, we've built a bot that can help users place a food order. At one point in the conversation, the bot will ask the user if they'd like a free dessert. The user can reply with 'yes' or 'no'. A bit later in the conversation, the bot will ask the user if they're ready to place their order. Again, the user can reply with 'yes' or 'no'.&#x20;

We need context so that the 'yes' or 'no' lead to different flows depending on where they are said in the conversation.

</details>

## Add context to your flow

To use context in an intent:

1. Make sure that you [created intents](/navigation/natural-language-processing-nlp/intents.md#add-a-new-intent) and linked them to [blocks](/buildabot/flow-logic/dialog-state.md). In this example, we'll use **general\_yes** and **general\_no** intents.

<figure><img src="/files/bKadiJeaumdDBT03QLQe" alt=""><figcaption><p>Two blocks, one for each possible user response</p></figcaption></figure>

2. Open the block containing the question. &#x20;
3. Go to the **NLP** section.&#x20;
4. Under **Give output context and livespan**, create an **output context.** For this example, we will call it **book\_ticket** with a **lifespan** of &#x31;**.**

{% hint style="info" %}
The **lifespan** designates how many times a context can be set throughout the whole conversation. For instance: If the bot offers free dessert twice in one conversation, we should put the **lifespan** at 2 because the user can say *yes* or *no* twice to this question. In this example, we'll only offer free dessert once, so we'll keep the **lifespan** at 1.
{% endhint %}

<figure><img src="/files/zGN1uhtHcZG4squM2Pbx" alt=""><figcaption><p>Add an output context and lifespan to a block.</p></figcaption></figure>

5. Click **Save**.
6. Open your [intent block](/buildabot/flow-logic/dialog-state.md#intent). For instance, open the **general\_yes** intent block.
7. Navigate to the **NLP** tab.
8. Under **Required context**, look for the context that you just created. In this example it will be **book\_ticket**.

<figure><img src="/files/NH8zX5a99T9cY1odFmZ2" alt=""><figcaption><p>Add a required context to an intent block.</p></figcaption></figure>

9. Click **Save**.

<details>

<summary>Tips on visualizing context in the canvas</summary>

From your bot [canvas](/navigation/bot-builder/flows.md), visualizing context at first sight can be not so straightforward.

* **Hover to see context**

By hovering over the input context next to the intent title, you can instantly view the required context that you just configured. This gives you a clear picture of the context requirements for your intent, enabling you to make any necessary adjustments.

<img src="/files/5dUObc09AJfL7nGXT9KD" alt="" data-size="original">

* **Use parent connections**

To improve visualization, you can set the **Ask a question** block as a [parent](/navigation/bot-builder/flows/canvas-functionalities.md#parent-child-connections) to the intent block. This creates a clear visual connection that improves readability.

<img src="/files/h3PsYzfIbg3Y7FTSIiWJ" alt="" data-size="original">

</details>

10. Follow the same process for other places in the conversation where those intents are used. That way, you can be sure that the bot provides the right answer!

<figure><img src="/files/orQjIH1H51WKlArCBHYV" alt=""><figcaption><p>Use the same intents at different places in the conversation using context.</p></figcaption></figure>

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


---

# 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.chatlayer.ai/nlp/natural-language-processing-nlp/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.
