> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/serve/text/lawsearch.md).

# Regulation Search Assistant

Regulation search assistant example - build a knowledge base from government regulatory announcements and use different role instructions to design two reply styles for internal staff and the general

Take the **regulation search assistant** as an example. In the past, because of technical limitations, government agencies and enterprises could only look up information with keyword search, which has the following drawbacks:

1. Poor semantic understanding, so results are imprecise
2. Cannot ask multiple questions at once
3. Affected by spelling errors
4. Cannot combine answers to multiple questions

These drawbacks lead to a <mark style="color:red;">**poor user experience**</mark>. With the arrival of large language models and RAG, however, all of this has changed. The following table compares traditional keyword search with RAG search.

|                                                 | Traditional Keyword Search                                  | RAG Search                                                                                             |
| ----------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| Query understanding                             | Limited to exact matching and basic synonyms                | Understands context, intent, and nuance                                                                |
| Information retrieval                           | Based on keyword frequency and basic relevance algorithms   | Uses semantic similarity and context-aware retrieval                                                   |
| Result format                                   | List of potentially relevant documents                      | <p>List of potentially relevant documents<br>Synthesized answer with citations to source documents</p> |
| Handling complex queries                        | Usually requires multiple searches and manual consolidation | Can directly handle complex, multi-faceted questions                                                   |
| Ability to adapt to domain-specific terminology | Limited unless heavily customized                           | Can learn and adapt to an organization's specific terminology                                          |
| Ability to use unstructured data                | Very limited                                                | High; can extract insights from various document types                                                 |
| Continuous learning                             | Usually static unless updated manually                      | Can improve over time through usage and feedback                                                       |

Take a "government regulation search assistant" as an example. The regulatory announcements of the Ministry of the Interior's National Land Management Agency shown below were traditionally searched by keyword. We now want to use generative AI to make them more convenient to use, and this is how you can do it on MaiAgent.

[https://www.nlma.gov.tw/最新消息/法規公告.html](https://www.nlma.gov.tw/%E6%9C%80%E6%96%B0%E6%B6%88%E6%81%AF/%E6%B3%95%E8%A6%8F%E5%85%AC%E5%91%8A.html**)

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-d3b6f15cec1ea6a0c8a2d4aa9874594bb74759fd%2Fimage%20(2)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Create a "Regulation Search Assistant" on the MaiAgent Platform <a href="#create-regulation-search-assistant-on-maiagent" id="create-regulation-search-assistant-on-maiagent"></a>

The structure of the "Regulation Search Assistant" is as follows:

```mermaid
graph TD
  Regulation-Search-Assistant --> Role-Instruction
  Regulation-Search-Assistant --> Knowledge-Base
  Regulation-Search-Assistant --> FAQ
  Regulation-Search-Assistant --> Internal-Staff-Interface
  Regulation-Search-Assistant --> Public-Interface
```

Because generative AI can be risky for government agencies, the design calls for different reply styles for internal staff and for the general public.

```mermaid
graph LR
  Regulation-Search-Assistant --> Internal-Staff
  Regulation-Search-Assistant --> General-Public
  
  Internal-Needs["1. Understand the intent of internal staff
  2. Find relevant regulatory announcements
  3. Combine them and generate a reply
  4. Attach citation sources"]

  Public-Needs["1. Understand the intent of the public
  2. Find relevant regulatory announcements
  3. Let the public click the announcement URL to read it"]
  
  Internal-Staff --> Internal-Needs
  General-Public --> Public-Needs
  
  classDef left text-align:left;
  
  class Internal-Needs,Public-Needs, left
```

Access Points and Architecture

```mermaid
graph LR

 
  Internal-Staff --> Log-in-to-MaiAgent-console
  General-Public --> Use-via-public-URL
  
  Internal-Regulation-Search-Assistant["Regulation Search Assistant (Internal)"]
  
  Log-in-to-MaiAgent-console --> Internal-Regulation-Search-Assistant
  Use-via-public-URL --> Regulation-Search-Assistant
  
  Regulation-Search-Assistant --> Regulation-Knowledge-Base
  Internal-Regulation-Search-Assistant --> Regulation-Knowledge-Base
  
  Regulation-Data["regulation-data.xlsx"]
  Regulation-Data --> Regulation-Knowledge-Base
```

For the question `Is there an age limit for funding subsidies?`, the replies that internal staff and the general public should receive are expected to look like this:

Reply received by internal staff:

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-1309c550dfc6632826d309e5e131336e2c6f574e%2F%E6%88%AA%E5%9C%96%202024-11-17%20%E4%B8%8B%E5%8D%884.44.57.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Reply received by the general public:

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-941cc2fc83f9ece7faa9724161b4ded929d17525%2F%E6%88%AA%E5%9C%96%202024-11-17%20%E4%B8%8B%E5%8D%885.00.01.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

You only need to give different `role instructions` when creating the "AI Assistant" in MaiAgent to get this effect. The Agent role instructions for the `general public` and for `internal staff` are provided below.

Role instruction (general public version)

```
# Role
You are a regulation search assistant for the National Land Management Agency, Ministry of the Interior

# Output Format
Use the example format below to reply with the three most relevant regulations.

<example>
The question you raised is related to the following regulations:

1. <date> <category> <regulation type> [title](URL)
2. <date> <category> <regulation type> [title](URL)
3. <date> <category> <regulation type> [title](URL)
</example>

# Output Restrictions
- Reply in Traditional Chinese
- Give priority to the most recent data as reference
- Do not answer with information outside the knowledge base
- Answer based on the knowledge base data; if you cannot answer, use the text in the <example> below

<example>
Sorry, the knowledge base does not currently contain the regulation you asked about. Please contact us during our service hours

Service hours: Monday to Friday, 8:00~17:30
Contact numbers of each business unit: see [link](<https://www.nlma.gov.tw/%E6%9C%AC%E7%BD%B2%E6%9C%8D%E5%8B%99%E8%B3%87%E8%A8%8A.html>)
</example>
```

Role instruction (internal staff version)

```
# Role
You are a regulation search assistant for the National Land Management Agency, Ministry of the Interior

# Background
This year is 2024 in the Gregorian calendar, which is year 113 of the Republic of China calendar

# Output Format
Use the example format below to reply with the three most relevant regulations.

<example>
{reply based on the question and reference data}

Related regulations:
1. <date> <category> <regulation type> [title](URL)
2. <date> <category> <regulation type> [title](URL)
3. <date> <category> <regulation type> [title](URL)
</example>

# Output Restrictions
- Reply in Traditional Chinese
- Give priority to the most recent data as reference
- Do not answer with information outside the knowledge base
- Answer based on the knowledge base data; if you cannot answer, use the text in the <example> below

<example>
The knowledge base does not currently contain the regulation you asked about. Please add the regulation data
</example>
```

### Knowledge Base <a href="#knowledge-base" id="knowledge-base"></a>

Download past regulation documents from the [Regulation Search of the National Land Management Agency, Ministry of the Interior](https://www.nlma.gov.tw/ch/legislation/regsearch)

**regulation-search.xlsx**

| Regulations on Rewards for Reporting Violations of Land Use under National Land Plans                                       | National Land Planning Division | Regulatory Order | 2024-10-31 | Regulation content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/25-計畫組/39226-國土計畫土地違規使用檢舉獎勵辦法.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/25-%E8%A8%88%E7%95%AB%E7%B5%84/39226-%E5%9C%8B%E5%9C%9F%E8%A8%88%E7%95%AB%E5%9C%9F%E5%9C%B0%E9%81%95%E8%A6%8F%E4%BD%BF%E7%94%A8%E6%AA%A2%E8%88%89%E7%8D%8E%E5%8B%B5%E8%BE%A6%E6%B3%95.html)                                         |
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ---------------- | ---------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Regulations on Setting Up Parent-Child Restrooms in Public Places                                                           | Building Management Division    | Regulatory Order | 2024-10-30 | Regulation content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/30-建管組/28714-公共場所親子廁所盥洗室設置辦法.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/30-%E5%BB%BA%E7%AE%A1%E7%B5%84/28714-%E5%85%AC%E5%85%B1%E5%A0%B4%E6%89%80%E8%A6%AA%E5%AD%90%E5%BB%81%E6%89%80%E7%9B%A5%E6%B4%97%E5%AE%A4%E8%A8%AD%E7%BD%AE%E8%BE%A6%E6%B3%95.html)                                                   |
| Notice of proposed amendments to the "Regulations on Leasing of Social Housing Undertaken by the Ministry of the Interior." | Housing Development Division    | Draft Regulation | 2024-10-22 | Regulation content… | [https://www.nlma.gov.tw//政府資訊公開/主動公開資訊/中央法規/法規查詢/29-住宅組/39204-預告修正「內政部興辦社會住宅出租辦法」。.html](https://www.nlma.gov.tw/%E6%94%BF%E5%BA%9C%E8%B3%87%E8%A8%8A%E5%85%AC%E9%96%8B/%E4%B8%BB%E5%8B%95%E5%85%AC%E9%96%8B%E8%B3%87%E8%A8%8A/%E4%B8%AD%E5%A4%AE%E6%B3%95%E8%A6%8F/%E6%B3%95%E8%A6%8F%E6%9F%A5%E8%A9%A2/29-%E4%BD%8F%E5%AE%85%E7%B5%84/39204-%E9%A0%90%E5%91%8A%E4%BF%AE%E6%AD%A3%E3%80%8C%E5%85%A7%E6%94%BF%E9%83%A8%E8%88%88%E8%BE%A6%E7%A4%BE%E6%9C%83%E4%BD%8F%E5%AE%85%E5%87%BA%E7%A7%9F%E8%BE%A6%E6%B3%95%E3%80%8D%E3%80%82.html) |


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/serve/text/lawsearch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
