Skip to main content

threadLink

The threadLink adapter option appends a link to the first reply the agent posts in a new channel thread, so people can open the same conversation in your app's web UI. Follow-up messages in that thread get no link.

The link is posted to the thread only. It's stripped from the saved message. The agent never sees its own links in memory.

Usage example
Direct link to Usage example

src/mastra/agents/support-agent.ts
import { Agent } from '@mastra/core/agent'
import { createSlackAdapter } from '@chat-adapter/slack'

export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'You help people with their accounts.',
model: 'openai/gpt-6.1-sol',
channels: {
adapters: {
slack: {
adapter: createSlackAdapter(),
threadLink: ({ threadId }) =>
threadId ? `https://app.example.com/threads/${threadId}` : undefined,
},
},
},
})

Pass an object to change the link text:

threadLink: {
label: 'Open in app ↗',
link: ({ threadId }) => `https://app.example.com/threads/${threadId}`,
},

Options
Direct link to Options

label?:

string
Link text.

ChannelThreadLinkTarget
Direct link to ChannelThreadLinkTarget

requestContext:

RequestContext
The run's request context. Read your own ids from it, such as a project or tenant.

threadId?:

string
The run's memory thread id.

resourceId?:

string
The run's memory resource id.

Behavior
Direct link to Behavior

  • The link is added only on the run that created the thread.
  • With textDisplay: 'show', the link ends the first reply. It's posted before the first tool call, or at the end of the step if no tool runs.
  • With replyMode, the link ends the agent's first reply_in_thread post instead.
  • The URL is built once per run. The saved message is cleaned using the exact link that was posted, so builders that return a different URL each call are safe.