# 查 Agent 做過什麼

你想確認 Agent 昨天到底做了哪些事。AsterMesh 每一次寫入都有稽核紀錄，Agent 做的會記是哪一把權杖、哪個 tool；也可以在網站側欄的「稽核紀錄」自己看（見[稽核紀錄](/docs/security/audit-log)）。

需要的授權項目：`audit:read`。

## 你對 Agent 說

> 昨天 Agent 經 MCP 做了哪些事？列給我看，核可之後才執行的標出來。

## Agent 的呼叫

### audit_log_search

查昨天的紀錄。日期是台灣時間，`from`、`to` 都包含當天。

參數：

```json
{
  "from": "2026-11-15",
  "to": "2026-11-15",
  "limit": 100
}
```

回傳（只列了幾筆、幾個欄位）：

```json
{
  "ok": true,
  "data": {
    "items": [
      {
        "occurred_at": "2026-11-15T16:05:12+08:00",
        "actor": { "type": "AGENT", "token_name": "記帳助理", "issued_by": { "email": "a@example.com" } },
        "channel": "MCP",
        "action": "payment.recorded",
        "category": "PAYMENT",
        "target": { "type": "BILL", "label": "BL-000117" },
        "tool": "payment_record",
        "approval_number": "AP-000040",
        "approved_by": { "email": "c@example.com" }
      },
      {
        "occurred_at": "2026-11-15T10:20:44+08:00",
        "actor": { "type": "AGENT", "token_name": "記帳助理", "issued_by": { "email": "a@example.com" } },
        "channel": "MCP",
        "action": "email.bill_email_queued",
        "category": "MESSAGING",
        "target": { "type": "BILL", "label": "BL-000116" },
        "tool": "bill_send",
        "approval_number": null,
        "approved_by": null
      },
      {
        "occurred_at": "2026-11-15T09:12:30+08:00",
        "actor": { "type": "USER", "email": "c@example.com", "role_name": "出納", "role_version": 2 },
        "channel": "WEB",
        "action": "payment.recorded",
        "category": "PAYMENT",
        "target": { "type": "BILL", "label": "BL-000115" },
        "tool": null,
        "approval_number": null,
        "approved_by": null
      }
    ],
    "next_cursor": null
  }
}
```

Agent 從結果裡挑 `channel` 是 `MCP` 的。紀錄超過一頁時，用 `next_cursor` 接著查。

## 結果

Agent 會列出：昨天經 MCP 做了 2 件事，

- 16:05 用「記帳助理」（a@example.com 發）記錄 BL-000117 的付款，是核可單 AP-000040 由 c@example.com 核可之後執行的。
- 10:20 用「記帳助理」寄出 BL-000116 的請款信。

09:12 那一筆是 c@example.com 自己在網站上做的，不是 Agent。

其他的查法：

- 只看某一把權杖：`actor_ids` 帶權杖的 id；只看系統做的：帶 `SYSTEM`。
- 只看某一類：`categories`，例如 `["PAYMENT", "REFUND"]`。
- 只看某一張請款單：`target` 帶 `{"type": "BILL", "id": "<請款單的 id>"}`，連它的付款、退款、發票、寄信紀錄一起列出。

紀錄裡的買方 Email、地址，權杖沒有「看買方個資」時是遮蔽過的。稽核紀錄只能查，不能改或刪。
