Skip to content

Commit 8eaceae

Browse files
committed
feat: expose Discord channel topics to agent context
Discord channels have topic descriptions that carry meaningful context for the agent. Currently only server name and channel name are passed through — the topic is discarded. Add CHANNEL_TOPIC metadata key, extract guild_channel.topic in the Discord adapter, thread it through render_conversation_context(), and render it in the conversation context template when present. When no topic is set, nothing additional is rendered. Zero breaking changes — purely additive.
1 parent 955efd3 commit 8eaceae

6 files changed

Lines changed: 27 additions & 0 deletions

File tree

prompts/en/fragments/conversation_context.md.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ Channel: {{ channel_name }} ({{ platform }}{% if conversation_id %}, id: `{{ con
77
{%- elif conversation_id %}
88
Channel ID: `{{ conversation_id }}`
99
{%- endif %}
10+
{%- if channel_topic %}
11+
Topic: {{ channel_topic }}
12+
{%- endif %}
1013
Multiple users may be present. Each message is prefixed with [username].

src/agent/channel.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,11 +1297,16 @@ impl Channel {
12971297
.metadata
12981298
.get(crate::metadata_keys::CHANNEL_NAME)
12991299
.and_then(|v| v.as_str());
1300+
let channel_topic = first
1301+
.metadata
1302+
.get(crate::metadata_keys::CHANNEL_TOPIC)
1303+
.and_then(|v| v.as_str());
13001304
self.conversation_context = Some(prompt_engine.render_conversation_context(
13011305
&first.source,
13021306
server_name,
13031307
channel_name,
13041308
self.conversation_id.as_deref(),
1309+
channel_topic,
13051310
)?);
13061311
}
13071312

@@ -1800,11 +1805,16 @@ impl Channel {
18001805
.metadata
18011806
.get(crate::metadata_keys::CHANNEL_NAME)
18021807
.and_then(|v| v.as_str());
1808+
let channel_topic = message
1809+
.metadata
1810+
.get(crate::metadata_keys::CHANNEL_TOPIC)
1811+
.and_then(|v| v.as_str());
18031812
self.conversation_context = Some(prompt_engine.render_conversation_context(
18041813
&message.source,
18051814
server_name,
18061815
channel_name,
18071816
self.conversation_id.as_deref(),
1817+
channel_topic,
18081818
)?);
18091819
}
18101820

src/api/channels.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ pub(super) async fn inspect_prompt(
568568
server_name,
569569
info.display_name.as_deref(),
570570
Some(&info.id),
571+
None,
571572
)
572573
.ok()
573574
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ pub mod metadata_keys {
459459
pub const REPLY_TO_MESSAGE_ID: &str = "reply_to_message_id";
460460
/// Quoted reply text preview from the message being replied to.
461461
pub const REPLY_TO_TEXT: &str = "reply_to_text";
462+
/// Channel topic / description (e.g. Discord channel topic).
463+
pub const CHANNEL_TOPIC: &str = "channel_topic";
462464
}
463465

464466
/// Inbound message from any messaging platform.

src/messaging/discord.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,15 @@ async fn build_metadata(
936936
guild_channel.name.clone().into(),
937937
);
938938

939+
if let Some(ref topic) = guild_channel.topic {
940+
if !topic.is_empty() {
941+
metadata.insert(
942+
crate::metadata_keys::CHANNEL_TOPIC.into(),
943+
topic.clone().into(),
944+
);
945+
}
946+
}
947+
939948
// Threads have a parent_id pointing to the text channel they were created in
940949
if guild_channel.thread_metadata.is_some() {
941950
metadata.insert("discord_is_thread".into(), true.into());

src/prompts/engine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ impl PromptEngine {
274274
server_name: Option<&str>,
275275
channel_name: Option<&str>,
276276
conversation_id: Option<&str>,
277+
channel_topic: Option<&str>,
277278
) -> Result<String> {
278279
self.render(
279280
"fragments/conversation_context",
@@ -282,6 +283,7 @@ impl PromptEngine {
282283
server_name => server_name,
283284
channel_name => channel_name,
284285
conversation_id => conversation_id,
286+
channel_topic => channel_topic,
285287
},
286288
)
287289
}

0 commit comments

Comments
 (0)