fix: parse directives before checking no-reply marker (#338)
Fixes reaction-only responses triggering spurious error messages. The <no-reply/> check now runs after directive parsing in both finalizeMessage() and the post-stream handler. Fixes the case where <actions><react emoji="..." /></actions> as the full response would add the reaction but also send an error message. Written by Cameron and Letta Code "First, solve the problem. Then, write the code." -- John Johnson
This commit is contained in:
@@ -1021,14 +1021,6 @@ export class LettaBot implements AgentSession {
|
||||
const msgTypeCounts: Record<string, number> = {};
|
||||
|
||||
const finalizeMessage = async () => {
|
||||
if (response.trim() === '<no-reply/>') {
|
||||
console.log('[Bot] Agent chose not to reply (no-reply marker)');
|
||||
sentAnyMessage = true;
|
||||
response = '';
|
||||
messageId = null;
|
||||
lastUpdate = Date.now();
|
||||
return;
|
||||
}
|
||||
// Parse and execute XML directives before sending
|
||||
if (response.trim()) {
|
||||
const { cleanText, directives } = parseDirectives(response);
|
||||
@@ -1037,6 +1029,17 @@ export class LettaBot implements AgentSession {
|
||||
sentAnyMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for no-reply AFTER directive parsing
|
||||
if (response.trim() === '<no-reply/>') {
|
||||
console.log('[Bot] Agent chose not to reply (no-reply marker)');
|
||||
sentAnyMessage = true;
|
||||
response = '';
|
||||
messageId = null;
|
||||
lastUpdate = Date.now();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!suppressDelivery && response.trim()) {
|
||||
try {
|
||||
const prefixed = this.prefixResponse(response);
|
||||
@@ -1225,12 +1228,6 @@ export class LettaBot implements AgentSession {
|
||||
adapter.stopTypingIndicator?.(msg.chatId)?.catch(() => {});
|
||||
}
|
||||
lap('stream complete');
|
||||
|
||||
// Handle no-reply marker
|
||||
if (response.trim() === '<no-reply/>') {
|
||||
sentAnyMessage = true;
|
||||
response = '';
|
||||
}
|
||||
|
||||
// Parse and execute XML directives (e.g. <actions><react emoji="eyes" /></actions>)
|
||||
if (response.trim()) {
|
||||
@@ -1241,6 +1238,12 @@ export class LettaBot implements AgentSession {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle no-reply marker AFTER directive parsing
|
||||
if (response.trim() === '<no-reply/>') {
|
||||
sentAnyMessage = true;
|
||||
response = '';
|
||||
}
|
||||
|
||||
// Detect unsupported multimodal
|
||||
if (Array.isArray(messageToSend) && response.includes('[Image omitted]')) {
|
||||
console.warn('[Bot] Model does not support images -- consider a vision-capable model or features.inlineImages: false');
|
||||
|
||||
Reference in New Issue
Block a user