What you’ll build

  • A Mastra agent with tools/actions
  • The same agent connected to CometChat (Agent ID + Deployment URL)
  • A customized chat experience using Chat Builder
  • An export to React UI Kit code or Chat Widget for integration

Prerequisites

  • A CometChat account and an app: Create App
  • A Mastra agent (ID + public Deployment URL) — follow Mastra’s quickstart:
    Mastra Quickstart

Step 1

Create your CometChat app

1

Create or open an app

Sign in at app.cometchat.com. Create a new app or open an existing one.
2

Copy credentials

Note your App ID, Region, and Auth Key (needed if you export the Chat Widget later).

Step 2

Connect your Mastra Agent

Navigate to AI Agent → Get Started and then AI Agents → Add Agent.
1

Choose provider

Select Mastra.
2

Basic details

Provide:
  • Name and optional Icon
  • (Optional) Greeting and Introductory Message
  • (Optional) Suggested messages
3

Mastra configuration

Paste the following from your Mastra deployment:
  • Mastra Agent ID
  • Deployment URL (public URL that CometChat can reach)
4

Save & enable

Click Save, then ensure the agent’s toggle is ON in AI Agents list.
Tip: If you update your Mastra agent later (prompts, tools, routing), you won’t need to re-connect it in CometChat—just keep the Agent ID and Deployment URL the same.

Step 3 (Optional)

Define Frontend Actions (Optional)

1

Add an action

Go to AI Agent → Actions and click Add to create a frontend action your agent can call (e.g., “Open Product,” “Start Demo,” “Book Slot”).
2

Define fields

Include:
  • Display Name — Shown to users (e.g., “Open Product Page”).
  • Execution Text — How the agent describes running it (e.g., “Opening product details for the user.”).
  • Name — A unique, code‑friendly key (e.g., open_product).
  • Description — What the tool does and when to use it.
  • Parameters — JSON Schema describing inputs (the agent will fill these).
3

Validate inputs (schema)

Example parameters JSON:
{
  "type": "object",
  "required": ["productId"],
  "properties": {
    "productId": {
      "type": "string",
      "description": "The internal product ID to open"
    },
    "utm": {
      "type": "string",
      "description": "Optional tracking code"
    }
  }
}
4

Handle in your UI

At runtime, listen for tool calls and execute them client‑side (e.g., route changes, modals, highlights).

Step 4

Customize in Chat Builder

1

Open variant

From AI Agents click the variant (or Get Started) to enter Chat Builder.
2

Customize & Deploy

Select Customize and Deploy.
3

Adjust settings

Theme, layout, features; ensure the Mastra agent is attached.
4

Preview

Use live preview to validate responses & any tool triggers.

Step 5

Export & Integrate

Choose how you’ll ship the experience (Widget or React UI Kit export).
The Mastra agent from Step 2 is included automatically in exported variants—no extra code needed for basic conversations.
1

Decide delivery mode

Pick Chat Widget (fastest) or export React UI Kit for code-level customization.
2

Widget path

Open Chat Builder → Get Embedded Code → copy script + credentials.
3

React UI Kit path

Export the variant as code (UI Kit) if you need deep theming or custom logic.
4

Verify agent inclusion

Preview: the Mastra agent should appear without extra config.

Step 6

Deploy & Secure (Reference)


Test your setup

1

Enable the agent

In AI Agents, ensure your Mastra agent shows Enabled.
2

Preview in Chat Builder

Open Chat Builder and start a preview session.
3

Validate conversation

Send a message; confirm the agent responds.
4

Test actions

Trigger a Frontend Action and verify your UI handles the tool call.

Troubleshooting


Next steps