Skip to content

feat(discord): add multibot-mentions mode for allow_user_messages#464

Merged
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/multibot-mentions
Apr 19, 2026
Merged

feat(discord): add multibot-mentions mode for allow_user_messages#464
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/multibot-mentions

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented Apr 19, 2026

Summary

Closes #463

Add a third mode for allow_user_messages that combines the best of involved and mentions:

  • Single-bot threads: natural conversation, no @mention needed (same as involved)
  • Multi-bot threads: requires @mention so only the addressed bot responds (same as mentions)
[discord]
allow_user_messages = "multibot-mentions"

Changes

src/config.rs

  • Add MultibotMentions variant to AllowUsers enum
  • Accept "multibot-mentions" or "multibot_mentions" in config deserialization

src/discord.rs

  • Refactor bot_participated_in_thread() to return (involved, other_bot_present) tuple
    • Reuses the existing message fetch (up to 200 messages) — zero additional API calls
    • Checks m.author.bot && m.author.id != bot_id to detect other bots
    • For Involved mode with a cache hit, skips the fetch entirely (no regression)
  • Add multibot_threads positive-only cache (same pattern as participated_threads)
    • Once a thread is detected as multi-bot, the result is cached — subsequent messages skip the fetch
    • Both caches hit → return (true, true), zero API call
    • Same eviction strategy (session TTL + capacity cap)
  • Add MultibotMentions branch in the gating logic:
    • Not in thread → return (same as other modes)
    • Not involved → return
    • Other bot present → return (require @mention)

src/main.rs

  • Initialize multibot_threads cache in Handler construction

docs/discord.md

  • Add multibot-mentions to the allow_user_messages config table
  • Add "Recommended: multibot-mentions mode" section under Multi-Bot Setup

Design decisions

Positive-only caching for other_bot_present: Like participation, a thread becoming multi-bot is irreversible — bot messages don't disappear. So we use the same positive-only cache pattern: once detected, cached for the session TTL. This avoids per-message API calls in active multi-bot threads.

Detection uses m.author.bot: Checks any bot author, not just trusted_bot_ids. This is intentional — even untrusted bots in a thread indicate a multi-bot scenario where @mention gating is desirable.

First message in new thread: No other bot messages exist yet → behaves as involved. Correct, since it is not yet a multi-bot thread.

@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 19, 2026 12:36
@github-actions github-actions bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 19, 2026
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

@chaodu-agent chaodu-agent force-pushed the feat/multibot-mentions branch 2 times, most recently from ec38117 to df56295 Compare April 19, 2026 12:44
Copy link
Copy Markdown
Collaborator

@thepagent thepagent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean feature, well-designed middle ground between involved and mentions.

One nit: the PR description says "No caching of other_bot_present" but the code correctly caches it in multibot_threads. The code is right (bot posting is irreversible), the description just needs updating to match.

Everything else checks out:

  • Config deserialization with -/_ normalization ✅
  • Positive-only cache with TTL + eviction ✅
  • Involved mode: no regression (bot_owns_thread still short-circuits) ✅
  • MultibotMentions + bot_owns_thread: correctly fetches to check for other bots ✅
  • Detection uses m.author.bot (any bot, not just trusted) ✅
  • Docs updated ✅

@chaodu-agent chaodu-agent force-pushed the feat/multibot-mentions branch 2 times, most recently from a901950 to 7bcea5f Compare April 19, 2026 12:47
Add a third mode for allow_user_messages that behaves like 'involved'
in single-bot threads but falls back to 'mentions' when other bots
have also posted in the thread. This prevents all bots from responding
to every message in multi-bot threads while keeping natural conversation
flow in single-bot threads.

- Add MultibotMentions variant to AllowUsers enum
- Refactor bot_participated_in_thread to return (involved, other_bot_present)
- Add multibot-mentions gating logic in message handler
- Update docs/discord.md with new mode and recommended usage

Closes openabdev#463
@chaodu-agent chaodu-agent force-pushed the feat/multibot-mentions branch from 7bcea5f to 502b517 Compare April 19, 2026 12:50
@thepagent thepagent merged commit 9cbc3d6 into openabdev:main Apr 19, 2026
9 checks passed
chaodu-agent added a commit to chaodu-agent/openab that referenced this pull request Apr 19, 2026
Instead of fetching thread history to detect other bots on every
unmentioned message, detect multi-bot threads eagerly from msg.author:
when a bot message arrives in a thread, cache multibot_threads
immediately — zero API calls needed.

This eliminates per-message fetches in MultibotMentions mode for
single-bot threads (which would never find other bots but fetched
every time to check).

- Add early detection before gating: msg.author.bot → cache multibot
- Simplify bot_participated_in_thread: cached_involved → return
  immediately with cached_multibot, no MultibotMentions special-casing

Builds on openabdev#464
brettchien added a commit to brettchien/openab that referenced this pull request Apr 19, 2026
The openab binary added the `MultibotMentions` variant to `AllowUsers`
in openabdev#464, but the Helm chart's validation block was not updated. Any
user who follows docs/discord.md § Multi-Bot Setup and sets
`allowUserMessages: "multibot-mentions"` is blocked by a template fail
before the pod ever starts.

Fix:
- Add `"multibot-mentions"` to the `has ... (list ...)` check for both
  Discord and Slack in `charts/openab/templates/configmap.yaml`.
- Update the trailing documentation comment describing the mode.
- Document the new option (and its semantics) in `charts/openab/values.yaml`.
- Add helm-unittest cases covering renders + invalid-value rejection for
  `allowUserMessages` (the test file previously only covered
  `allowBotMessages`).

Verified:

    $ helm template openab ./charts/openab \
        --set agents.kiro.discord.allowUserMessages=multibot-mentions \
        ... | grep allow_user_messages
        allow_user_messages = "multibot-mentions"

    $ helm unittest charts/openab
    Charts:      1 passed, 1 total
    Test Suites: 2 passed, 2 total
    Tests:       18 passed, 18 total

Fixes openabdev#471
Refs openabdev#464

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(discord): add multibot-mentions mode for allow_user_messages

2 participants