跳到正文
Mastra Blog·· 24 分鐘前AI 評分58

Mastra 為 Slack 智能體推出生成式 UI 卡片

Introducing Generative UI in Slack for Mastra Agents

AI 導讀

Mastra 為 Slack 中的智能體加入生成式 UI 卡片功能,智能體可按回覆內容選擇卡片元素並將卡片發佈到對話串。啟用 generativeUI 後,智能體會透過 render_card 工具生成 Slack 原生卡片,可使用重點欄位、表格、圖表、圖片及連結按鈕。

正文

Your agents can now use generative UI cards in Slack. Turn on generativeUI and the agent gets a render_card tool that posts rich, native cards to the thread.

Agents in Slack usually reply using long blocks of plain text or markdown, making it difficult to see how numbers compare or change over time. With generative UI, the agent decides how to present the data, using fields for key facts, tables for rows of data, charts for metrics or trends, images, and link buttons that open related pages.

A Deploy Agent in Slack answers with a deploy summary, a bar chart of build times, and a table of shipped commits, followed by the setup code and connecting Slack with Mastra Connect.

You've always been able to post UI cards in Slack by predefining them in code, but before generative UI, each card's structure was fixed in advance. Now, with generative UI, the agent creates the card on the fly, choosing the most suitable UI element for each response.

To render Slack-native UI elements, agents call the render_card tool, passing in an object that meets the json-render spec. Mastra can then post responses to the thread using Slack's Block Kit elements.

Get started

Install @json-render/chat:

npm install @json-render/chat

note

Requires @mastra/core@1.83.0 or later, added in PR #29820.

This example uses Mastra Connect to manage the Slack connection on Mastra platform. Add @json-render/chat to bundler.dynamicPackages and set generativeUI: true on the Slack provider:

import { Mastra } from "@mastra/core/mastra";
import { channels } from "@mastra/connect";
import { deployAgent } from "./agents/deploy-agent";
 
export const mastra = new Mastra({
  agents: { deployAgent },
  bundler: {
    dynamicPackages: ["@json-render/chat"]
  },
  channels: await channels({
    providers: {
      slack: {
        providerOptions: { generativeUI: true }
      }
    }
  })
});

Optionally, name the components you want the agent to use in the agent's instructions:

import { Agent } from "@mastra/core/agent";
import { Memory } from "@mastra/memory";
 
export const deployAgent = new Agent({
  id: "deploy-agent",
  name: "Deploy Agent",
  instructions: `You report on deploys for the mastra-website project.
  Answer every deploy question with one render_card card that includes:
 
  - a title and subtitle
  - fields for the key facts
  - a table
  - a chart
  - an image
  - link buttons
`,
  model: "mastra/anthropic/claude-opus-5.5",
  memory: new Memory()
});

For more information and full configuration options, see:

Generative UI is still experimental — the API may change between releases.

來源:Mastra Blog · mastra.ai