# Using Buttons in an AI Workflow to Trigger the Knowledge Base

<figure><img src="/files/KAXjxUzdcuudpqw0cmYH" alt=""><figcaption></figcaption></figure>

In this tutorial, you will learn how to use buttons in an AI flow such that the button's title text passes through as values for the next block to be triggered. We will achieve this by assigning the button's text as a value corresponding to its title and a key that corresponds to the \`lastUserText\` attribute. This attribute is then used to trigger a knowledge base lookup using the [Ask Knowledge Base](/ai-chatbots-and-automation/actions-explained/ask-knowledge-base.md) action in the subsequent block.

#### 1. Set Up Your AI Agent Flows <a href="#id-1-set-up-your-chatbot-flows" id="id-1-set-up-your-chatbot-flows"></a>

Ensure you have uploaded a Knowledge Base (URLs, text files, Sitemap) in the [Knowledge Base section](/ai-chatbots-and-automation/knowledge-base/knowledge-base-overview.md).\
Design the initial block where the user will interact with buttons. Each button will represent a query or option that will trigger a specific response. You can include these buttons in your Welcome Block, where you can offer some FAQ examples.

#### 2. Capture Button Text and Assign to lastUserText <a href="#id-2-capture-button-text-and-assign-to-lastusertext" id="id-2-capture-button-text-and-assign-to-lastusertext"></a>

**Make sure that each button is connected to a block first** by choosing the button type: **go to block** >> choose the respective block.&#x20;

Then click on the ‘**Attributes**’ section below and insert a) the ‘**lastUserText**’ as the **Key** and b) the **button's title** as the **Value**. This way, the AI Agent captures the button's text and assigns it to the \`**lastUserText**\` attribute.

<figure><img src="/files/YjXIK6RWS39CLrG6jkSR" alt=""><figcaption></figcaption></figure>

#### 3. Configure the Knowledge Base Lookup Block <a href="#id-3-configure-the-knowledge-base-lookup-block" id="id-3-configure-the-knowledge-base-lookup-block"></a>

Create a new block that will handle the knowledge base lookup based on the \`lastUserText\` value. Use the [Ask Knowledge Base](/ai-chatbots-and-automation/actions-explained/ask-knowledge-base.md) action to query the knowledge base. Then add the text reply with the classic ‘kb\_reply’ that will allow the agent to stamp the answer.

<figure><img src="/files/slvUDN2T6PFdX8Q2i6Qb" alt=""><figcaption></figcaption></figure>

#### 4. Test the AI Agent Flow <a href="#id-4-test-the-chatbot-flow" id="id-4-test-the-chatbot-flow"></a>

Test the complete flow by interacting with the [buttons](/ai-chatbots-and-automation/actions-explained/reply-action.md#buttons) and ensuring the appropriate knowledge base lookup and response is triggered.

#### Summary <a href="#summary" id="summary"></a>

By following this tutorial, you have successfully created an AI Agent flow where button interactions trigger specific [Blocks](/ai-chatbots-and-automation/visual-builder-101/how-to-create-a-block.md) based on the button's title text. This text is passed through using the \`lastUserText\` attribute and is utilized to query a knowledge base, providing users with relevant information based on their selections. This approach enhances user interaction by providing dynamic and contextually relevant responses.

<figure><img src="/files/DCp3kBqbsWmbEi3CKdEU" alt=""><figcaption></figcaption></figure>

Do not hesitate to get in touch and share your feedback with us at <info@tiledesk.com> 🧡


---

# 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://guide.tiledesk.com/ai-chatbots-and-automation/knowledge-base/using-buttons-in-an-ai-workflow-to-trigger-the-knowledge-base.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.
