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 exampleDirect 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}`,
},
OptionsDirect link to Options
threadLink?:
((target: ChannelThreadLinkTarget) => string | undefined) | { link: (target: ChannelThreadLinkTarget) => string | undefined; label?: string }
Builds the URL for the run's thread. Return
undefined to post no link. Pass an object to set the link text.label?:
string
Link text.
ChannelThreadLinkTargetDirect 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.
BehaviorDirect 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 firstreply_in_threadpost 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.