The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(discord): add free_response_auto_thread opt-in
Xunjin ZHENG774e0707312a
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex d86af01fcd1..4c80450f446 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -1463,6 +1463,9 @@ DEFAULT_CONFIG = {"free_response_channels": "", # comma-separated channel IDs answered without mention"allowed_channels": "", # if set, ONLY respond in these channel IDs (whitelist)"auto_thread": True, # auto-create threads on @mention in channels (like Slack)+ # Free-response channels reply inline by default; true also gives each top-level+ # message in them its own thread (still mention-free). Env: DISCORD_FREE_RESPONSE_AUTO_THREAD.+ "free_response_auto_thread": False,"thread_require_mention": False, # require @mention in threads too (multi-bot threads)# Bot authors must type @thisbot to trigger a reply; Discord reply pings alone do not count.# Set False only for trusted legacy relays. Humans are unaffected.diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex 52bfff7188d..d502b98628e 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -5948,7 +5948,15 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):auto_threaded_channel = Noneif not is_thread and not isinstance(message.channel, discord.DMChannel):no_thread_channels = self._get_no_thread_channels()- skip_thread = bool(channel_keys & no_thread_channels) or is_free_channel+ # free_response_auto_thread: free-response channels reply inline unless the operator+ # opts in; then each top-level message also gets its own thread. The voice-linked and+ # reply exclusions live in the auto-thread gate below, not here.+ free_response_auto_thread = self._extra_or_env_flag(+ "free_response_auto_thread", "DISCORD_FREE_RESPONSE_AUTO_THREAD", "false", truthy=True,+ )+ skip_thread = bool(channel_keys & no_thread_channels) or (+ is_free_channel and not free_response_auto_thread+ )auto_thread = self._extra_or_env_flag("auto_thread", "DISCORD_AUTO_THREAD", "true", truthy=True)is_reply_message = getattr(message, "type", None) == discord.MessageType.replyif auto_thread and not skip_thread and not is_voice_linked_channel and not is_reply_message:@@ -7228,7 +7236,11 @@ def _apply_yaml_config(yaml_cfg: dict, discord_cfg: dict) -> dict | None:seeded_extra["approval_mentions"] = approval_mentions_cfg_env_default("DISCORD_APPROVAL_MENTIONS", str(approval_mentions_cfg).lower())_gate("free_response_channels", "DISCORD_FREE_RESPONSE_CHANNELS", from_platform_extra=False)- for key, env_key in (("auto_thread", "DISCORD_AUTO_THREAD"), ("reactions", "DISCORD_REACTIONS")):+ for key, env_key in (+ ("auto_thread", "DISCORD_AUTO_THREAD"),+ ("free_response_auto_thread", "DISCORD_FREE_RESPONSE_AUTO_THREAD"),+ ("reactions", "DISCORD_REACTIONS"),+ ):if key in discord_cfg:seeded_extra[key] = discord_cfg[key]_env_default(env_key, str(discord_cfg[key]).lower())diff --git a/tests/gateway/test_discord_free_response.py b/tests/gateway/test_discord_free_response.pyindex 1ed2dd3658f..ce4cc6ded2b 100644--- a/tests/gateway/test_discord_free_response.py+++ b/tests/gateway/test_discord_free_response.py@@ -375,6 +375,53 @@ async def test_discord_free_response_channel_skips_auto_thread(adapter, monkeypaassert event.source.chat_type == "group"+async def test_discord_free_response_auto_thread_opt_in(adapter, monkeypatch):+ """``free_response_auto_thread`` gives each top-level free-channel message its own thread."""+ monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "true")+ monkeypatch.setenv("DISCORD_FREE_RESPONSE_CHANNELS", "789")+ monkeypatch.setenv("DISCORD_FREE_RESPONSE_AUTO_THREAD", "true")+ monkeypatch.delenv("DISCORD_AUTO_THREAD", raising=False) # default true++ created_thread = FakeThread(channel_id=456, name="auto-thread")+ adapter._auto_create_thread = AsyncMock(return_value=created_thread)++ message = make_message(+ channel=FakeTextChannel(channel_id=789),+ content="thread this one please",+ )++ await adapter._handle_message(message)++ adapter._auto_create_thread.assert_awaited_once_with(message)+ event = adapter.handle_message.await_args.args[0]+ assert event.source.chat_type == "thread"+ assert event.source.chat_id == "456"+++async def test_discord_no_thread_channels_wins_over_free_response_auto_thread(adapter, monkeypatch):+ """An explicit ``no_thread_channels`` listing still forces inline replies."""+ monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "true")+ monkeypatch.setenv("DISCORD_FREE_RESPONSE_CHANNELS", "789")+ monkeypatch.setenv("DISCORD_FREE_RESPONSE_AUTO_THREAD", "true")+ monkeypatch.setenv("DISCORD_NO_THREAD_CHANNELS", "789")+ monkeypatch.delenv("DISCORD_AUTO_THREAD", raising=False) # default true++ adapter._auto_create_thread = AsyncMock()++ message = make_message(+ channel=FakeTextChannel(channel_id=789),+ content="explicitly inline",+ )++ await adapter._handle_message(message)++ adapter._auto_create_thread.assert_not_awaited()+ event = adapter.handle_message.await_args.args[0]+ assert event.source.chat_type == "group"++@pytest.mark.asyncioasync def test_fetch_channel_context_stops_at_self_message_and_reverses_to_chronological_order(adapter, monkeypatch):monkeypatch.setenv("DISCORD_ALLOW_BOTS", "all")diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.mdindex af7b87610e0..6246443f067 100644--- a/website/docs/reference/environment-variables.md+++ b/website/docs/reference/environment-variables.md@@ -348,6 +348,7 @@ These are set automatically by the Docker terminal backend when `proxy.enabled:| `DISCORD_AUTO_THREAD` | Auto-thread long replies when supported || `DISCORD_ALLOW_ANY_ATTACHMENT` | When `true`, accept attachments of any file type (not just the built-in PDF/text/zip/office allowlist). Unknown types are cached and surfaced to the agent as a local path so it can inspect them via `terminal` / `read_file` / `ffprobe`. Default `false`. || `DISCORD_MAX_ATTACHMENT_BYTES` | Maximum bytes per attachment the gateway will cache. Default `33554432` (32 MiB). Set to `0` for no cap (attachments are held in memory while being written). |+| `DISCORD_FREE_RESPONSE_AUTO_THREAD` | When `true`, free-response channels (listed in `DISCORD_FREE_RESPONSE_CHANNELS`) also auto-create a thread per message. Default `false` — free-response channels reply inline. Requires `DISCORD_AUTO_THREAD=true`; `DISCORD_NO_THREAD_CHANNELS` still wins. || `DISCORD_REACTIONS` | Enable emoji reactions on messages during processing (default: `true`) || `DISCORD_IGNORED_CHANNELS` | Comma-separated channel IDs where the bot never responds || `DISCORD_NO_THREAD_CHANNELS` | Comma-separated channel IDs where bot responds without auto-threading |diff --git a/website/docs/user-guide/messaging/discord.md b/website/docs/user-guide/messaging/discord.mdindex 03033a526a0..80462526e30 100644--- a/website/docs/user-guide/messaging/discord.md+++ b/website/docs/user-guide/messaging/discord.md@@ -306,6 +306,7 @@ Discord behavior is controlled through two files: **`~/.hermes/.env`** for crede| `DISCORD_FREE_RESPONSE_CHANNELS` | No | — | Comma-separated channel IDs where the bot responds without requiring an `@mention`, even when `DISCORD_REQUIRE_MENTION` is `true`. || `DISCORD_IGNORE_NO_MENTION` | No | `true` | When `true`, the bot stays silent if a message `@mentions` other users but does **not** mention the bot. Prevents the bot from jumping into conversations directed at other people. Only applies in server channels, not DMs. || `DISCORD_AUTO_THREAD` | No | `true` | When `true`, automatically creates a new thread for every `@mention` in a text channel, so each conversation is isolated (similar to Slack behavior). Messages already inside threads or DMs are unaffected. |+| `DISCORD_FREE_RESPONSE_AUTO_THREAD` | No | `false` | When `true`, free-response channels (listed in `DISCORD_FREE_RESPONSE_CHANNELS`) also auto-create a thread for each top-level message, while staying mention-free. Default `false` preserves the lightweight inline-chat behavior. Requires `DISCORD_AUTO_THREAD=true`; `DISCORD_NO_THREAD_CHANNELS` still wins, and voice-linked channels always ignore it. || `DISCORD_ALLOW_BOTS` | No | `"none"` | Controls how the bot handles messages from other Discord bots. `"none"` — ignore all other bots. `"mentions"` — only accept bot messages that `@mention` Hermes. `"all"` — accept all bot messages. By default, either enabled mode still requires a literal inline mention; see the next setting. || `DISCORD_BOTS_REQUIRE_INLINE_MENTION` | No | `true` | Require a literal `<@BOT_ID>` / `<@!BOT_ID>` token to start a bot handoff. Reply metadata alone does not start one. Brief same-sender/channel continuations are admitted as described below. Set to `false` only for trusted relays needing legacy admission. Human messages are unaffected. || `DISCORD_REACTIONS` | No | `true` | When `true`, the bot adds emoji reactions to messages during processing (👀 when starting, ✅ on success, ❌ on error). Set to `false` to disable reactions entirely. |@@ -362,6 +363,7 @@ discord:bots_require_inline_mention: true # Bot authors must type a literal @mention (default: true)free_response_channels: "" # Comma-separated channel IDs (or YAML list)auto_thread: true # Auto-create threads on @mention+ free_response_auto_thread: false # If true, free_response_channels also auto-thread (default: inline)reactions: true # Add emoji reactions during processingignored_channels: [] # Channel IDs where bot never respondsno_thread_channels: [] # Channel IDs where bot responds without threading@@ -427,7 +429,9 @@ discord:If a thread's parent channel is in this list, the thread also becomes mention-free.-Free-response channels also **skip auto-threading** — the bot replies inline rather than spinning off a new thread per message. This keeps the channel usable as a lightweight chat surface. If you want threading behavior, don't list the channel as free-response (use normal `@mention` flow instead).+Free-response channels also **skip auto-threading** by default — the bot replies inline rather than spinning off a new thread per message. This keeps the channel usable as a lightweight chat surface.++To opt in to threading for free-response channels, set `discord.free_response_auto_thread: true` (or `DISCORD_FREE_RESPONSE_AUTO_THREAD=true`). In that mode each new top-level message in a free channel still gets its own thread, but the channel remains @mention-free. Requires `discord.auto_thread: true`.#### `discord.auto_thread`