> For the complete documentation index, see [llms.txt](https://docs.myshell.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.myshell.ai/create/pro-config-mode/tools/knowledge-base-bot.md).

# Knowledge Base Agent

Use [Knowledge Base Agent](https://app.myshell.ai/bot/n6jmQn/309) to manage knowledge bases with domain-specific data or to handle different opinions.

### Guide

#### Get Started

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FcNROlQ7IZAAaAFHXIOu4%2Fkb-list-kbs.png?alt=media&amp;token=90f3baa6-d69f-4f4f-9ecf-0d6b33245dfd" alt=""><figcaption><p>List knowledge bases</p></figcaption></figure>

#### Create New Knowledge Base

A meaningful name is helpful for your bases. After creation, the agent will display your current knowledge bases including their names and tokens.&#x20;

The token (for example, `myshell_f5ac9afa_5c1f_4ef6_ae80_2120e2b2671e` in the picture below) will be used in the [LLM Widget](/create/pro-config-mode/api-reference/module/anywidget-module/llm-widget.md#config)' `knowledge_base_token` field.&#x20;

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FCXM0D0kbmZwziiUuv74b%2Fkb-create-base.png?alt=media&amp;token=9eca0d30-6245-4c0c-823a-e2eb301b0e67" alt=""><figcaption><p>Create Base</p></figcaption></figure>

#### List Source and Add Source

To modify sources of the new knowledge base, `List Source` button will guide to a detailed operation panel. Currently we support:

* Add Gitbook links as sources
* Upload files as sources
* Re-sync link sources
* Delete sources

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FptNG2gD5MzFp00sqC4pH%2Fkb-list-source.png?alt=media&amp;token=dac0e4db-dde1-4ec2-93ea-9cb98dd1a1b7" alt=""><figcaption><p>List Source</p></figcaption></figure>

#### Upload File as Source

You can upload text files or PDF files as sources. Text files include md, txt, csv and json.

{% hint style="info" %}
Other text file types can be converted to supported types. Widgets like [MS Word to Markdown](https://app.myshell.ai/widget/jQBbEv) might be helpful.
{% endhint %}

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FNM1h3I1Btxm647XKkpOn%2Fkb-add-text-source.png?alt=media&amp;token=71ad3964-1274-4ae1-ad42-38aaba92a7c5" alt=""><figcaption><p>Upload text file</p></figcaption></figure>

#### Add Gitbook Link as Source

Currently we only support Gitbook web pages as knowledge base sources. For Gitbook links, we will fetch the target page and all its subpages.

{% hint style="info" %}
If the page is updated, you can click `Re-Sync Source` button to update the source.
{% endhint %}

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2F0Z1ynfjJXFzveyAItmpi%2Fkb-add-gitbook-source.png?alt=media&amp;token=a66e0b5f-70e0-4083-b9bf-dba27c516367" alt=""><figcaption><p>Gitbook Link</p></figcaption></figure>

#### Refresh after Processing

After adding a source, the agent will tell you that it is being processed.

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FGYUDrca1F8B8CYjWxXXM%2Fkb-processing-source.png?alt=media&amp;token=80986dc3-086d-4998-ae7b-bb0dadd81ff1" alt=""><figcaption><p>Processing</p></figcaption></figure>

You can refresh to see if it's ready to use.

<figure><img src="https://2975681513-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDtmZwLatyyBFLUK6P6Pj%2Fuploads%2FtPiUI1uinuqj5yuOdR6B%2Fkb-refresh-status.png?alt=media&amp;token=c7dfd1ec-837e-4d1d-9884-47dd373060c7" alt=""><figcaption><p>Refresh</p></figcaption></figure>

#### Use in Widgets

When sources are ready, you can copy the knowledge base's token and configure the LLM widget. Note the `"knowledge_base_token"` field in the widget config.

```json
{
  "id": "llm_widget_template",
  "initial": "home_state",
  "states": {
    "home_state": {
      "inputs": {
        "input_message": {
          "type": "IM",
          "user_input": true
        }
      },
      "tasks": [
        {
          "name": "llm_widget_example_task",
          "module_type": "AnyWidgetModule",
          "module_config": {
            "widget_id": "1744214047475109888",
            "user_prompt": "{{input_message}}", // the text inputted into prompt widget, you can get it from user input or upper state
            "system_prompt": "Act as ...", // Optional field. You can input system prompt of agent.
            "top_p": 0.5, // Optional field. Default value is 0.5
            "temperature": 0.5, // Optional field. Default value is 0.5
            "frequency_penalty": 0, // Optional field. Default value is 0
            "presence_penalty": 0, // Optional field. Default value is 0
            "knowledge_base_token": "", // Your token here
            "output_name": "result"
          }
        }
      ],
      "render": {
        "text": "{{result}}", // it's a string produced by prompt widget.
        "buttons": [
          {
            "content": "Chat Again",
            "description": "",
            "on_click": "rerun"
          }
        ]
      },
      "transitions": {
        "rerun": "home_state",
        "CHAT": "home_state"
      }
    }
  }
}
```
