Cookbook
Agents & skills · for AI agents
檢查用量與配額
透過 MCP 查看 token 用量與每月配額,可按 agent、使用者、空間、日期或模型篩選,以回答「我是否接近上限?」以及「成本主要由什麼驅動?」。
MCP tools:
tenant_infousage_stats兩個唯讀工具可回答所有「我用了多少?」的問題。兩者皆僅回傳中繼資料——計數與事件計數——且絕不回傳任何對話內容。
你目前的配額使用狀況
tenant_info() # plan + monthly_token_quota (the ceiling)
usage_stats(group="total") # tokens + events used so far this period使用情境 ——「我快要耗盡了嗎?」 將總使用量與 tenant_info 中的 monthly_token_quota 進行比較。超額使用採事後計費,因此顯示「你已使用本月配額的 82%」可讓用戶在產生費用前做出決定。
是什麼驅動了成本
usage_stats(group=…) 將相同的總計數據進行切片。根據你要回答的問題來選擇群組:
usage_stats(group="agent") # which agent is busiest / burning the most tokens
usage_stats(group="user") # which end user is heaviest — spot one runaway account
usage_stats(group="space") # usage per customer space (multi-tenant fan-out)
usage_stats(group="day") # trend over time — catch a spike the day it happens
usage_stats(group="model") # cost mix across models — is an expensive model doing routine work?使用情境一覽:
- 「我的帳單這個月跳增 —— 為什麼?」→ 使用
group="day"找出尖峰,接著使用group="agent"查看來自哪個 agent。 - 「是否某個模型正在處理較便宜模型也能處理的工作?」→ 使用
group="model",然後考慮對違規者執行update_agent(name, model=…)。 - 「我應該對哪個客戶進行加價銷售 / 速率限制?」→ 使用
group="space"或group="user"。
這是中繼資料,而非內容分析。它回答的是「用了多少」以及「由誰/什麼使用」,絕不回答「說了什麼」。聊天記錄與終端用戶資料刻意無法透過 MCP 存取。
回報結果。 先提出最關鍵的那個數字 ——「你已使用 4.2M 的每月 5M token(84%)」—— 接著提供解釋該數字的細項,並連結至主控台以取得完整概況:
https://console.agent4.io/#/usage。