Skip to content

feat(slack-agent): gate thread follow-ups behind a relevance classifier - #557

Open
JeremyFunk wants to merge 1 commit into
mainfrom
feat/slack-agent-relevance-gate
Open

feat(slack-agent): gate thread follow-ups behind a relevance classifier#557
JeremyFunk wants to merge 1 commit into
mainfrom
feat/slack-agent-relevance-gate

Conversation

@JeremyFunk

@JeremyFunk JeremyFunk commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Problem

Thread follow-up promotion (agent/lib/thread-follow-up.ts) only answers a mechanical question — is the bot part of this thread. Once it is, every human reply in the thread dispatched a full agent turn: in an incident thread where two engineers are talking to each other, the bot answered each of their messages. Cost amplifier, and a bot that butts into conversations never addressed to it.

Change

A confirmed follow-up now also passes a semantic gate (agent/lib/follow-up-relevance.ts): one classifier call — recent thread tail + the new reply in, a single RESPOND/PASS word out — asking whether the reply is actually directed at the bot or expects it to act. Orders of magnitude cheaper than the agent turn it gates.

  • Real @mentions and DMs skip the gate. An explicit address answers the question itself.
  • A PASS is silent by design: it runs before the :eyes: ack and typing indicator, so a message the bot stays out of gets no reaction at all, and drops via the same throw-to-un-dispatch escape hatch as the disengagement drop. The bot stays engaged — the next reply that is for it gets answered. The only trace is a structured follow_up_not_relevant log (ids only, never message text).
  • It fails open, same asymmetry as confirmThreadFollowUp: classifier error, timeout (10s), or an unparseable verdict all answer the follow-up. A wrong drop loses a user's message with nothing on screen to explain it; a wrong answer costs one turn. The prompt's tiebreak leans the same way.
  • Gate model is separately configurable (OPENROUTER_GATE_MODEL) since the job wants a small, fast model; unset, it follows OPENROUTER_MODEL rather than silently using a third one.

Runs on the dispatch path (post-200, inside eve's waitUntil), so it spends nothing from Slack's ~3s webhook budget.

Trade-off

Every un-mentioned reply in an engaged thread now costs one tiny classifier call. That is the mechanism working; set OPENROUTER_GATE_MODEL to something small to make it cheaper.

Testing

  • bun test in apps/slack-agent: 281 pass (12 new — verdict parsing, prompt contents, fail-open on error/unparseable, deps-injected classifier)
  • tsc clean

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Thread follow-up promotion only checked engagement — is the bot part of
this thread — so once it was, every human reply there dispatched a full
agent turn, including people talking to each other.

A confirmed follow-up now also passes a semantic gate: one small
RESPOND/PASS classifier call asking whether the reply is actually
directed at the bot. A PASS drops the turn silently, before the 👀
ack and typing indicator, and the bot stays engaged for the next message
that is for it. Real @mentions and DMs skip the gate — an explicit
address answers the question itself.

The gate fails open (classifier error, timeout, or unparseable verdict
all answer the follow-up), same asymmetry as the engagement check: a
wrong drop loses a user's message invisibly, a wrong answer costs one
turn. Model is configurable via OPENROUTER_GATE_MODEL, following
OPENROUTER_MODEL when unset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant