fix(chat): reduce system spam and cap history
This commit is contained in:
@@ -676,23 +676,24 @@ export async function getReplyFromConfig(
|
||||
}
|
||||
}
|
||||
|
||||
// Prepend queued system events and (for new main sessions) a provider snapshot.
|
||||
// For new main sessions, prepend a provider snapshot.
|
||||
// Note: We intentionally do NOT prepend queued system events to the user prompt,
|
||||
// since that bloats session logs (token cost) and clutters chat history.
|
||||
const isGroupSession =
|
||||
typeof ctx.From === "string" &&
|
||||
(ctx.From.includes("@g.us") || ctx.From.startsWith("group:"));
|
||||
const isMainSession =
|
||||
!isGroupSession && sessionKey === (sessionCfg?.mainKey ?? "main");
|
||||
if (isMainSession) {
|
||||
const systemLines: string[] = [];
|
||||
const queued = drainSystemEvents();
|
||||
systemLines.push(...queued);
|
||||
// Drain (discard) queued system events so they remain ephemeral.
|
||||
// They are still available via presence/health in the gateway UI.
|
||||
drainSystemEvents();
|
||||
if (isNewSession) {
|
||||
const summary = await buildProviderSummary(cfg);
|
||||
if (summary.length > 0) systemLines.unshift(...summary);
|
||||
}
|
||||
if (systemLines.length > 0) {
|
||||
const block = systemLines.map((l) => `System: ${l}`).join("\n");
|
||||
prefixedBodyBase = `${block}\n\n${prefixedBodyBase}`;
|
||||
if (summary.length > 0) {
|
||||
const block = summary.map((l) => `System: ${l}`).join("\n");
|
||||
prefixedBodyBase = `${block}\n\n${prefixedBodyBase}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user