> 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/maiagent-user-guide-en/application/km/billing-assistant.md).

# Billing & Expense Assistant

Enterprise finance teams often face challenges such as numerous receipts, time-consuming manual data entry, and error-prone processes when handling daily expense reimbursements. Traditional OCR tools can only perform simple text recognition without understanding business context, making them unable to automatically map department codes or expense categories, still requiring significant manual intervention for corrections. Now, you can leverage MaiAgent's intelligent vision technology to build a dedicated "Billing Expense Assistant", achieving intelligent automation from receipt recognition to ERP form filling!

## Use Case: Build an AI Assistant for Automatic Enterprise Bill Recognition

Suppose you are a financial accountant at a company. At the end of every month, you need to process a large volume of reimbursement receipts from various branch offices, including water bills, electricity bills, and telecommunications bills. In the past, you might have spent hours looking at paper receipts, manually entering invoice numbers, dates, and amounts one by one into the ERP system.

Traditional OCR tools can only "read text" but cannot understand business rules. For example, when a receipt shows "Zuoying District, Kaohsiung City", traditional tools cannot automatically determine that this belongs to the "Kaohsiung Branch" with department code "K"; nor can they lock the payment date to the "30th of each month" according to company policy, forcing you to manually verify and correct data entry by entry — not only inefficient but also prone to errors caused by fatigue.

Now, with MaiAgent's intelligent vision and reasoning technology, you simply upload a bill image to the AI assistant, and the system not only accurately extracts invoice numbers and amounts but also directly executes your company's internal business logic!

## Workflow

### 1. Create a Billing Expense AI Assistant <a href="#id-1.-jian-li-cai-wu-zi-liao-fen-xi-ai-zhu-li" id="id-1.-jian-li-cai-wu-zi-liao-fen-xi-ai-zhu-li"></a>

Enter the AI assistant name and select the language model.

Recommended model: Gemini 2.5 Pro

Note: Since this application involves complex image text recognition and logical reasoning (such as address-to-department code mapping), it is strongly recommended to use a Pro-level or higher model to ensure recognition accuracy.

Select Agent mode.

### **2. Operational Logic Configuration**

To enable the assistant to not only "read text" but also "understand" business rules, define the following field processing logic in the System Prompt. The following uses a water bill from "Taiwan Water Corporation" as an example:

```
------------------------------------------------------------
|  Taiwan Water Corporation                               |
|  Taiwan Water Corporation                                |
|  May, ROC Year 114 Direct Debit (Agency Collection)     |
|  Water Bill Payment Receipt                              |
|                                                          |
|  Carrier Type Number: /BB0001                            |
|  Period: 11405                                           |
|  Electronic Invoice Certificate: TP88776655              |
|                                [     QR Code     ]       |
|                                [     回回回      ]       |
|  Water Usage Address:                                    |
|  No. 7, Sec. 5, Xinyi Rd., Xinyi Dist.,                |
|  Taipei City 110 (Taipei 101 Tower)                      |
|                                                          |
|----------------------------------------------------------|
|  Customer Name: Test Taipei Headquarters                 |
|                                                          |
|  Current Billing Water Usage Period                      |
|                               Water Usage Item Details   |
|  114/03/05 - 114/05/04        Basic Fee           100元  |
|                               Water Usage Fee      950元  |
|  Current Payment Start Date   -------------------------  |
|  114/05/21                    Sales Tax             50元  |
|                                                          |
|  Next Payment Start Date      Pre-tax Subtotal           |
|  114/07/21                    (Trap F)          1,050元  |
|                                                          |
|  Current Meter Reading Date   Agency Collection Subtotal |
|  114/05/04                    Disposal Fee         300元  |
|                               Water Source                |
|                               Conservation Fee     100元  |
|----------------------------------------------------------|
|                                                          |
|  Total Amount Due (Total)                                |
|  $ 1,500 元                                              |
|                                                          |
|  Payment Deadline: 114/05/30  Account Number: 998877665544|
------------------------------------------------------------
```

**A. Basic Information Extraction**

The assistant needs to identify the following key raw data from the image:

* Invoice Number: Accurately extract the invoice number from the receipt.
* Amount Information: Extract the "total amount" and "pre-tax amount".
* Date Information: Extract the relevant date range from the bill.

**B. Business Logic Mapping**

This is the core advantage that distinguishes MaiAgent from traditional OCR. The assistant can automatically determine attribution based on content:

1. Address-to-Department Mapping:
   * Rule: If the recognized address contains "Kaohsiung", the "expenditure department" is automatically classified as "Kaohsiung Branch".
   * Code Conversion: Following the above, if the department is Kaohsiung Branch, the "department code" is automatically filled in as "K".
2. Payee and Category:
   * Rule: If the payee is identified as "Taiwan Water Corporation", the "expense item" is automatically classified as "Water Bill".
3. Payment Date Automation:
   * Rule: Regardless of the bill date, the "payment date" field is uniformly fixed to the 30th of each month.
4. Summary Format Standardization:
   * Rule: Combine the extracted dates and information into a fixed format string.
   * Example format: `YY/MM/DD-YY/MM/DD` + `Region` + `Expense Item` (e.g., "114/08/20-114/10/18 Kaohsiung Water Bill").
5. Amount Calculation and Verification:
   * Rule: The system can automatically calculate or verify amount logic, for example: `Amount` = `Total Amount` - `Pre-tax Amount` (depending on ERP field definitions).

Refer to the following role instructions:

```
# Role (Role Setting)
You are an enterprise-level "Intelligent Financial Accounting Assistant". Your core capabilities are visual recognition (OCR) combined with complex business logic reasoning.
Your task is to accurately extract data from various types of bills and convert unstructured information into standard ERP format based on the predefined [Business Configuration].

# Business Configuration (Business Rule Configuration)
**Perform reasoning and field mapping according to the following rule table:**

## 1. Department Mapping Rules (Department Logic)
* **Rule**: Read the "address" or "consumption location" keywords on the bill.
    * Contains "Taipei" -> Expenditure Department: "Taipei Headquarters" | Department Code: "T"
    * Contains "Kaohsiung" -> Expenditure Department: "Kaohsiung Branch" | Department Code: "K"
    * Other -> Expenditure Department: "To Be Confirmed" | Department Code: "UNK"

## 2. Expense Category Rules (Expense Category Logic)
* **Rule**: Read the "company name", "header", or "transaction details" on the bill.
    * Contains "Water" (自來水) -> Expense Item: "Water Bill"
    * Contains "Electric" (電力), "Taipower" (台電) -> Expense Item: "Electricity Bill"
    * Contains "Chunghwa Telecom" (中華電信) -> Expense Item: "Telecommunications Bill"

## 3. Date and Summary Rules (Date & Summary Logic)
* **Payment Date**: Uniformly set to the "current or next month 30th" of the receipt month (format YYYY-MM-DD).
* **Summary Format**: Must be combined into a standard string -> `[Date Range]-[Region][Expense Item]`
    * *Example*: `114/06/20-114/08/18 Kaohsiung Water Bill`

## 4. Amount Calculation Rules (Calculation Logic)
* **Pre-tax Amount**: Must be obtained through calculation, formula = `[Total Amount] - [Sales Tax/Tax Amount]`.
    * *Note*: Do not directly read the "subtotal" in the middle of the receipt. Use the "total amount" minus tax to avoid missing agency collection fees.

---

# Workflow (Execution Flow)

## Phase 1: Visual Recognition and Logical Reasoning
1.  **Analyze Image**: Scan for invoice number, date range, address, transaction counterpart, total amount, and tax amount.
    * *Invoice Number Format Check*: Must match `^[A-Z]{2}\d{8}$`.
2.  **Execute Mapping**: Determine department, category, and codes based on [Business Configuration].
3.  **Output Confirmation Table**: Output results in a Markdown table for user review.

**Phase 1 Output Example (strictly follow this format):**
Reply directly: "Please confirm the following bill information:"
| Field Name | Recognition and Conversion Result | Logic Source |
| :--- | :--- | :--- |
| **A. Expenditure Department** | [e.g., Kaohsiung Branch] | [Based on address: Kaohsiung...] |
| **B. Expense Item** | [e.g., Water Bill] | [Based on counterpart: Water Corporation] |
| **C. Summary** | [Date range + Region + Item] | [Format combination] |
| **D. Invoice Number** | [Two letters + eight digits] | [OCR Recognition] |
| **E. Amount (Tax)** | [Tax amount] | [OCR Recognition] |
| **F. Pre-tax Amount** | [Calculated value] | [Total - Tax] |
| **G. Payment Date** | [YYYY-MM-DD] | [Fixed rule: 30th] |
| **H. Department Code** | [e.g., K] | [Mapping code] |
| **I. Total Amount** | [Total amount] | [OCR Recognition] |

## Phase 2: Data Entry (Action)
When the user replies "Confirm" or "No problem":
1.  Call the MCP tool `add_invoice_record` to write the data.
2.  After successful tool execution, output in standard JSON format and provide a Google Sheet link.

---

# Attention (Notes)
* If the image is blurry, mark it as "Unable to recognize" and ask the user.
* Prioritize the visual "Total Amount" text; ignore intermediate subtotals.
```

**C. Advanced Configuration: Connect to Google Sheet for Automatic Filing**

{% hint style="info" %}
[How to connect MCP tools?](https://docs.maiagent.ai/tech/remote-mcp/remote-mcp)
{% endhint %}

### 3. Deploy the AI Assistant <a href="#id-1.-jian-li-cai-wu-zi-liao-fen-xi-ai-zhu-li" id="id-1.-jian-li-cai-wu-zi-liao-fen-xi-ai-zhu-li"></a>

When you need to process billing expenses, simply send the bill or payment receipt to the AI assistant. The system automatically identifies the content, converts the extracted data according to internal company regulations (e.g., automatically mapping department codes, calculating pre-tax amounts), and then directly writes the data into the ERP system or Google Sheet, achieving one-click automation from receipt recognition to accounting entry.

**Automatic Bill Content Detection**

**Automatic Bill Content Entry into Google Sheet**

**Automatic Conversion to ERP Format JSON**

```
{
  "expenditure_department": "台北總公司",
  "cost_item": "水費",
  "summary": "114/03/05-114/05/04台北水費",
  "invoice_number": "TP88776655",
  "tax_amount": 50,
  "pre_tax_amount": 1450,
  "payment_date": "2025-05-30",
  "department_code": "T"
}
```

### 4. Technical Advantages of the Intelligent Billing Assistant

#### 🚀 Powerful Vision Language Model (VLM)

* **Semantic Understanding and Dynamic Reasoning:** The model does not rely on fixed template coordinates but extracts information by understanding the contextual semantics of the receipt. Additionally, business rules can be flexibly expanded through the System Prompt without redeveloping the program.

> *Application Examples:*
>
> * Automatic Classification: Recognizes the "Taiwan Water Corporation" logo and automatically classifies the category as "Water Bill".
> * Logic Completion: Recognizes a "Kaohsiung address" and automatically infers and fills in department code "K".
> * Rule Expansion: If you need to add judgment logic for "Taipei Branch" in the future, you only need to adjust the prompt to take effect.

* **Strong Environmental Adaptability:** Equipped with noise-resistant visual recognition capabilities, even if photos taken by the user's phone have shadows, wrinkles, glare, or slight blurring, the VLM can still accurately restore values and text based on context, significantly reducing the need for re-shooting or manual re-entry.

#### **🛠️ Precise Tool Invocation and Logic Execution (Tool Use & Integration)**

* Automated Report Writing: Through the Google Sheets writing tool, the assistant can write parsed information directly into designated cloud spreadsheet fields.

> Replacing the traditional tedious process of "manually reading receipts and keying in data", truly achieving "snap the receipt, report is done".

* **Structured Format and Seamless ERP Integration**: Enforced output format specifications ensure data can directly correspond to enterprise internal system (ERP) requirements.

> *Application Examples:*
>
> * Date Unification: Whether the invoice shows `2024/01/01` or `ROC Year 113, January 1`, it is automatically converted to standard `YYYY-MM-DD` format before writing.
> * System Integration: Supports direct output in standard JSON format for direct use by enterprise ERP APIs.

* **Logic Compliance Validation:** The assistant doesn't just pass data — it can also invoke calculation tools for numerical and compliance checks.

> *Application Example:* Automatically validates `Total - Tax = Pre-tax Amount`, or locks specific payment dates (e.g., the 30th of each month) according to company regulations, ensuring every piece of data entering the system complies with financial logic and security standards.

With the MaiAgent Intelligent Billing Assistant, finance teams can not only eliminate tedious receipt data entry work but also ensure that the attribution and codes for every expense are 100% accurate, truly achieving unmanned automated processing from "receipts" to "reports"!

**Experience the Billing Expense Assistant now — make your financial processes not just digitized, but intelligent!**


---

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-en/application/km/billing-assistant.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
