Skip to content

Commit f602053

Browse files
committed
Add Discord context fetch diagnostics.
Logs context retrieval counts and message summaries plus prompt-agent input stats so we can verify recent thread history is included during responses.
1 parent c9ca807 commit f602053

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

app/src/lib/discord/prompt-agent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ export async function runDiscordPromptAgent(input: {
215215
})
216216
.join("\n")}\n\nLatest user prompt:\n${prompt}`
217217
: prompt;
218+
console.info(
219+
`[discord-context] prompt_agent receivedMessages=${input.recentMessages?.length ?? 0} finalPromptChars=${contextText.length}`,
220+
);
218221

219222
const { text } = await generateText({
220223
model: getGatewayModel(),

app/src/lib/discord/review-bot.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type RecentMessageContext = {
3232
text: string;
3333
isBot: boolean;
3434
};
35+
const CONTEXT_MESSAGE_LIMIT = 30;
36+
const LOG_MESSAGE_PREVIEW_LENGTH = 80;
3537

3638
let reviewBot: Chat<{
3739
discord: ReturnType<typeof createDiscordAdapter>;
@@ -67,6 +69,19 @@ function toReviewChannelId(guildId: string, reviewChannelId: string): string {
6769
return `discord:${guildId}:${reviewChannelId}`;
6870
}
6971

72+
function buildContextLog(messages: RecentMessageContext[]): string {
73+
return messages
74+
.map((message, index) => {
75+
const role = message.isBot ? "bot" : "user";
76+
const preview = message.text.replace(/\s+/g, " ").slice(
77+
0,
78+
LOG_MESSAGE_PREVIEW_LENGTH,
79+
);
80+
return `${index + 1}/${messages.length} role=${role} author="${message.author}" chars=${message.text.length} preview="${preview}"`;
81+
})
82+
.join(" | ");
83+
}
84+
7085
function registerHandlers(
7186
bot: Chat<{ discord: ReturnType<typeof createDiscordAdapter> }>,
7287
): void {
@@ -134,11 +149,23 @@ function registerHandlers(
134149
text,
135150
isBot: recentMessage.author.isBot === true,
136151
});
137-
if (recentMessages.length >= 30) {
152+
if (recentMessages.length >= CONTEXT_MESSAGE_LIMIT) {
138153
break;
139154
}
140155
}
141156
recentMessages.reverse();
157+
console.info(
158+
`[discord-context] thread=${thread.id} fetched=${recentMessages.length} limit=${CONTEXT_MESSAGE_LIMIT} promptChars=${userPrompt.length}`,
159+
);
160+
if (recentMessages.length > 0) {
161+
console.info(
162+
`[discord-context] thread=${thread.id} messages=${buildContextLog(recentMessages)}`,
163+
);
164+
} else {
165+
console.info(
166+
`[discord-context] thread=${thread.id} no prior text messages found`,
167+
);
168+
}
142169

143170
const response = await runDiscordPromptAgent({
144171
prompt: userPrompt.slice(0, 4000),
@@ -148,6 +175,9 @@ function registerHandlers(
148175
} catch (error) {
149176
const errorMessage =
150177
error instanceof Error ? error.message : "Unknown error";
178+
console.error(
179+
`[discord-context] thread=${thread.id} prompt_failed=${errorMessage}`,
180+
);
151181
await thread.post(
152182
`I hit an error while processing that request: ${errorMessage}`,
153183
);

0 commit comments

Comments
 (0)