Skip to content

Commit 20c7360

Browse files
committed
Agent should have context about the Slack thread it's responding to (vibe-kanban 2d08c3ef)
When responding to a Slack message in a thread, the agent currently only sees the current message - it doesn't have access to the full conversation thread history. **Problem:** User asked a question, agent responded with analysis, then user asked to create a ticket about "this" - but the agent didn't know what "this" referred to because it couldn't see the earlier messages in the thread. **Example:** https://elementalprep.slack.com/archives/C0AM1EVLSH5/p1773924310782589?thread_ts=1773924094.381349&cid=C0AM1EVLSH5 **Expected behavior:** When the agent is invoked in a Slack thread, it should fetch and include the thread history as context so it can understand references to earlier messages. **Implementation ideas:** - Use Slack MCP `conversations_replies` tool to fetch thread history when `thread_ts` is present - Include thread context in the agent's system prompt or initial context
1 parent d389465 commit 20c7360

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/platforms/slack.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,24 @@ export class SlackAdapter {
163163
// Strip bot mention from text before sending to Claude
164164
const cleanText = msg.text.replace(new RegExp(`<@${this.botUserId}>\\s*`, 'g'), '').trim();
165165

166+
// Build message with Slack context
167+
const threadTs = msg.thread_ts || msg.ts;
168+
const isInThread = !!msg.thread_ts;
169+
170+
const contextBlock = `<slack_context>
171+
Channel: ${channel}
172+
Thread: ${threadTs}${isInThread ? `
173+
Note: You are replying to a message in an existing thread. If the user references earlier messages or context you don't have, use the Slack MCP conversations_replies tool to fetch thread history.` : ''}
174+
</slack_context>
175+
176+
${cleanText}`;
177+
166178
// Get Claude's response
167-
console.log(`[slack] ${key}: Sending to Claude (${cleanText.length} chars)`);
168-
const response = await this.agent.chat(cleanText);
179+
console.log(`[slack] ${key}: Sending to Claude (${contextBlock.length} chars)`);
180+
const response = await this.agent.chat(contextBlock);
169181
console.log(`[slack] ${key}: Claude responded (${response.length} chars)`);
170182

171-
// Reply in thread (use thread_ts if it's a threaded reply, otherwise use msg.ts)
172-
const threadTs = msg.thread_ts || msg.ts;
183+
// Reply in thread
173184
console.log(`[slack] ${key}: Posting reply to thread ${threadTs}`);
174185
await this.slackApi.chatPostMessage(channel, response, threadTs);
175186

0 commit comments

Comments
 (0)