跳到主要内容

createNotificationInboxTool()

新增于: @mastra/core@1.39.0

createNotificationInboxTool() 会创建一个 Mastra Tool,使 Agent 能够检查和管理当前 thread 的通知收件箱记录。

将此 Tool 与持久通知 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。

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 会将其内容作为通知 Signal 投递,而不是以常规 Tool 输出返回完整内容。当 Agent 在 <notification-summary> Signal 后需要摘要背后的完整记录时,请使用此操作。