跳至主要內容

createNotificationInboxTool()

新增於: @mastra/core@1.39.0

createNotificationInboxTool() 會建立 Mastra Tool,讓 Agent 檢查及管理目前 thread 的通知收件匣記錄。

請將此 Tool 搭配 durable notification signal 使用。若要傳送通知記錄,請參閱 Agent.sendNotificationSignal()

使用範例
「使用範例」的直接連結

以下範例會將收件匣 Tool 加入 Agent。

src/mastra/agents/support-agent.ts
import { Agent } from '@mastra/core/agent'
import { createNotificationInboxTool } from '@mastra/core/notifications'

const notificationsStorage = await storage.getStore('notifications')

export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'Help the user triage updates.',
model: 'openai/gpt-5.6-sol',
tools: {
notificationInbox: createNotificationInboxTool({ storage: notificationsStorage }),
},
})

參數
「參數」的直接連結

options:

object
Tool 設定。
object

storage:

NotificationsStorage
storage.getStore('notifications') 傳回的通知 Storage domain。

Tool 輸入
「Tool 輸入」的直接連結

產生的 Tool id 為 notification-inbox,並接受以下輸入欄位。

action:

'list' | 'read' | 'markSeen' | 'dismiss' | 'archive' | 'search'
要執行的收件匣動作。

threadId?:

string
要檢查的 thread ID。有目前 Agent thread 時,預設使用該 thread。

id?:

string
通知 ID。markSeendismissarchive 必填,read 選填。

status?:

'pending' | 'delivered' | 'seen' | 'dismissed' | 'archived' | 'discarded'
用於 list、read 或 search 動作的狀態篩選條件。

priority?:

'low' | 'medium' | 'high' | 'urgent'
用於 list、read 或 search 動作的優先順序篩選條件。

source?:

string
用於 list、read 或 search 動作的來源篩選條件。

query?:

string
搜尋查詢。actionsearch 時必填。

limit?:

number
要傳回的通知數量上限。必須是正整數。

動作
「動作」的直接連結

動作說明
list傳回符合條件的通知。
read以 signal 形式傳遞可讀取的通知內容,並將已傳遞的記錄標示為已讀。
markSeen將一則通知標示為已讀。
dismiss將一則通知標示為已忽略。
archive將一則通知標示為已封存。
search依查詢與選填篩選條件搜尋通知。

read 找到待處理或已傳遞的通知時,Tool 會以 notification signal 形式傳遞內容,而不是以一般 Tool 輸出傳回完整內容。Agent 在 <notification-summary> signal 後需要摘要背後的完整記錄時,請使用此動作。