Skip to content

feat(slack): fetch thread context via conversations.replies#6008

Closed
tonywcs wants to merge 1 commit into
NousResearch:mainfrom
tonywcs:feat/slack-thread-context
Closed

feat(slack): fetch thread context via conversations.replies#6008
tonywcs wants to merge 1 commit into
NousResearch:mainfrom
tonywcs:feat/slack-thread-context

Conversation

@tonywcs

@tonywcs tonywcs commented Apr 8, 2026

Copy link
Copy Markdown

Summary

When a user messages in a Slack thread, the agent currently has no visibility into prior thread messages — each thread reply starts with zero context. This PR fixes that by fetching thread history from the Slack API.

Changes

  • _fetch_thread_context() — new method that calls conversations.replies to retrieve up to 20 prior messages in a thread, formatted as [sender]: message lines
  • Thread context injection — when a message arrives in a thread (thread_ts != ts), prior messages are fetched and prepended to the user's message as context
  • Dedup tracking_thread_history_fetched set prevents redundant API calls for the same thread
  • Active thread tracking — bot responds to follow-up messages in threads it has already participated in, without requiring a new @mention each time

How it works

  1. User sends a message in a Slack thread
  2. Adapter detects thread_ts != ts (this is a thread reply)
  3. On first message in that thread, calls conversations.replies to get prior messages
  4. Formats them as context block and prepends to the message text
  5. Subsequent messages in the same thread skip the fetch (already in session history)

What's NOT affected

  • Top-level channel messages — no change
  • DMs — no change
  • DM thread seeding (existing feature) — unchanged

Testing

All 64 existing Slack tests pass. Tested manually in production Slack workspace.

When a user messages in a Slack thread, the agent now fetches prior
thread messages via the Slack API (conversations.replies) and injects
them as context. This gives the agent visibility into the full thread
conversation, even on first interaction or after a gateway restart.

Changes:
- Add _fetch_thread_context() method that calls conversations.replies
  to retrieve up to 20 prior messages in a thread
- Inject thread context into the message text before processing
- Track fetched threads to avoid redundant API calls
- Only triggers for thread replies (thread_ts != ts), not channel msgs

Also includes the existing active thread tracking so the bot responds
to follow-up messages in threads it has already participated in,
without requiring a new @mention each time.
@teknium1

teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #6809 as part of a consolidated Slack adapter improvement. Your contribution was superseded by #6162's more mature implementation. Your authorship is preserved in git history. Thank you @tonywcs for your work on this!

@teknium1 teknium1 closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants