mirror of https://github.com/buster-so/buster.git
Update reasoning messages to improve clarity and consistency across tools
- Changed the wording of elapsed time in reasoning messages from "min" to "minutes" for better readability. - Updated the final reasoning message format to specify "Reasoned for" instead of "Total workflow time," enhancing user understanding of the output. These changes contribute to a more user-friendly experience and maintain consistency in messaging across different tools.
This commit is contained in:
parent
24e91b2ac7
commit
82516e4fbb
|
@ -80,12 +80,12 @@ export function createDoneToolStart(doneToolState: DoneToolState, context: DoneT
|
||||||
timeString = `${elapsedSeconds} seconds`;
|
timeString = `${elapsedSeconds} seconds`;
|
||||||
} else {
|
} else {
|
||||||
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
||||||
timeString = `${elapsedMinutes} min`;
|
timeString = `${elapsedMinutes} minutes`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateMessage(context.messageId, {
|
await updateMessage(context.messageId, {
|
||||||
isCompleted: true,
|
isCompleted: true,
|
||||||
finalReasoningMessage: `Total workflow time: ${timeString}`,
|
finalReasoningMessage: `Reasoned for ${timeString}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -49,12 +49,12 @@ export function createMessageUserClarifyingQuestionStart(
|
||||||
timeString = `${elapsedSeconds} seconds`;
|
timeString = `${elapsedSeconds} seconds`;
|
||||||
} else {
|
} else {
|
||||||
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
||||||
timeString = `${elapsedMinutes} min`;
|
timeString = `${elapsedMinutes} minutes`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateMessage(messageId, {
|
await updateMessage(messageId, {
|
||||||
isCompleted: true,
|
isCompleted: true,
|
||||||
finalReasoningMessage: `Total workflow time: ${timeString}`,
|
finalReasoningMessage: `Reasoned for ${timeString}`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
|
@ -48,12 +48,12 @@ export function createRespondWithoutAssetCreationStart<
|
||||||
timeString = `${elapsedSeconds} seconds`;
|
timeString = `${elapsedSeconds} seconds`;
|
||||||
} else {
|
} else {
|
||||||
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
const elapsedMinutes = Math.floor(elapsedSeconds / 60);
|
||||||
timeString = `${elapsedMinutes} min`;
|
timeString = `${elapsedMinutes} minutes`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateMessage(context.messageId, {
|
await updateMessage(context.messageId, {
|
||||||
isCompleted: true,
|
isCompleted: true,
|
||||||
finalReasoningMessage: `Total workflow time: ${timeString}`,
|
finalReasoningMessage: `Reasoned for ${timeString}`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[respond-without-asset-creation] Failed to update initial entries:', error);
|
console.error('[respond-without-asset-creation] Failed to update initial entries:', error);
|
||||||
|
|
|
@ -30,23 +30,27 @@ export async function updateMessageEntries({
|
||||||
reasoningMessages,
|
reasoningMessages,
|
||||||
}: UpdateMessageEntriesParams): Promise<{ success: boolean }> {
|
}: UpdateMessageEntriesParams): Promise<{ success: boolean }> {
|
||||||
try {
|
try {
|
||||||
const updates: Record<string, SQL | Date> = { updatedAt: new Date() };
|
const updates: Record<string, SQL | string> = { updatedAt: new Date().toISOString() };
|
||||||
|
|
||||||
// Optimized merge for response messages - upsert by 'id'
|
// Optimized merge for response messages - upsert by 'id'
|
||||||
if (responseMessages?.length) {
|
if (responseMessages?.length) {
|
||||||
const newData = JSON.stringify(responseMessages);
|
const newData = JSON.stringify(responseMessages);
|
||||||
updates.responseMessages = sql`
|
updates.responseMessages = sql`
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT jsonb_agg(value)
|
(SELECT jsonb_agg(value ORDER BY ordinality)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT DISTINCT ON (value->>'id') value
|
-- Keep existing messages that aren't being updated
|
||||||
FROM (
|
SELECT value, ordinality
|
||||||
SELECT jsonb_array_elements(COALESCE(${messages.responseMessages}, '[]'::jsonb))
|
FROM jsonb_array_elements(COALESCE(${messages.responseMessages}, '[]'::jsonb)) WITH ORDINALITY AS t(value, ordinality)
|
||||||
UNION ALL
|
WHERE NOT EXISTS (
|
||||||
SELECT jsonb_array_elements(${newData}::jsonb)
|
SELECT 1 FROM jsonb_array_elements(${newData}::jsonb) AS new_msg
|
||||||
) combined(value)
|
WHERE new_msg->>'id' = t.value->>'id'
|
||||||
ORDER BY value->>'id', value DESC
|
)
|
||||||
) deduplicated),
|
UNION ALL
|
||||||
|
-- Add new/updated messages at the end
|
||||||
|
SELECT value, 1000000 + ordinality AS ordinality
|
||||||
|
FROM jsonb_array_elements(${newData}::jsonb) WITH ORDINALITY AS t(value, ordinality)
|
||||||
|
) combined),
|
||||||
'[]'::jsonb
|
'[]'::jsonb
|
||||||
)`;
|
)`;
|
||||||
}
|
}
|
||||||
|
@ -56,16 +60,20 @@ export async function updateMessageEntries({
|
||||||
const newData = JSON.stringify(reasoningMessages);
|
const newData = JSON.stringify(reasoningMessages);
|
||||||
updates.reasoning = sql`
|
updates.reasoning = sql`
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT jsonb_agg(value)
|
(SELECT jsonb_agg(value ORDER BY ordinality)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT DISTINCT ON (value->>'id') value
|
-- Keep existing messages that aren't being updated
|
||||||
FROM (
|
SELECT value, ordinality
|
||||||
SELECT jsonb_array_elements(COALESCE(${messages.reasoning}, '[]'::jsonb))
|
FROM jsonb_array_elements(COALESCE(${messages.reasoning}, '[]'::jsonb)) WITH ORDINALITY AS t(value, ordinality)
|
||||||
UNION ALL
|
WHERE NOT EXISTS (
|
||||||
SELECT jsonb_array_elements(${newData}::jsonb)
|
SELECT 1 FROM jsonb_array_elements(${newData}::jsonb) AS new_msg
|
||||||
) combined(value)
|
WHERE new_msg->>'id' = t.value->>'id'
|
||||||
ORDER BY value->>'id', value DESC
|
)
|
||||||
) deduplicated),
|
UNION ALL
|
||||||
|
-- Add new/updated messages at the end
|
||||||
|
SELECT value, 1000000 + ordinality AS ordinality
|
||||||
|
FROM jsonb_array_elements(${newData}::jsonb) WITH ORDINALITY AS t(value, ordinality)
|
||||||
|
) combined),
|
||||||
'[]'::jsonb
|
'[]'::jsonb
|
||||||
)`;
|
)`;
|
||||||
}
|
}
|
||||||
|
@ -75,26 +83,33 @@ export async function updateMessageEntries({
|
||||||
const newData = JSON.stringify(rawLlmMessages);
|
const newData = JSON.stringify(rawLlmMessages);
|
||||||
updates.rawLlmMessages = sql`
|
updates.rawLlmMessages = sql`
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT jsonb_agg(value)
|
(SELECT jsonb_agg(value ORDER BY ordinality)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT DISTINCT ON (
|
-- Keep existing messages that aren't being updated
|
||||||
value->>'role',
|
SELECT value, ordinality
|
||||||
(SELECT string_agg(content->>'toolCallId', ',' ORDER BY content->>'toolCallId')
|
FROM jsonb_array_elements(COALESCE(${messages.rawLlmMessages}, '[]'::jsonb)) WITH ORDINALITY AS t(value, ordinality)
|
||||||
FROM jsonb_array_elements(value->'content') content
|
WHERE NOT EXISTS (
|
||||||
WHERE content->>'toolCallId' IS NOT NULL)
|
SELECT 1 FROM jsonb_array_elements(${newData}::jsonb) AS new_msg
|
||||||
) value
|
WHERE new_msg->>'role' = t.value->>'role'
|
||||||
FROM (
|
AND (
|
||||||
SELECT jsonb_array_elements(COALESCE(${messages.rawLlmMessages}, '[]'::jsonb))
|
-- Compare toolCallIds if they exist
|
||||||
UNION ALL
|
(SELECT string_agg(content->>'toolCallId', ',' ORDER BY content->>'toolCallId')
|
||||||
SELECT jsonb_array_elements(${newData}::jsonb)
|
FROM jsonb_array_elements(new_msg->'content') content
|
||||||
) combined(value)
|
WHERE content->>'toolCallId' IS NOT NULL) =
|
||||||
ORDER BY
|
(SELECT string_agg(content->>'toolCallId', ',' ORDER BY content->>'toolCallId')
|
||||||
value->>'role',
|
FROM jsonb_array_elements(t.value->'content') content
|
||||||
(SELECT string_agg(content->>'toolCallId', ',' ORDER BY content->>'toolCallId')
|
WHERE content->>'toolCallId' IS NOT NULL)
|
||||||
FROM jsonb_array_elements(value->'content') content
|
OR
|
||||||
WHERE content->>'toolCallId' IS NOT NULL),
|
-- Both have no toolCallIds
|
||||||
value DESC
|
((SELECT COUNT(*) FROM jsonb_array_elements(new_msg->'content') content WHERE content->>'toolCallId' IS NOT NULL) = 0
|
||||||
) deduplicated),
|
AND (SELECT COUNT(*) FROM jsonb_array_elements(t.value->'content') content WHERE content->>'toolCallId' IS NOT NULL) = 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
UNION ALL
|
||||||
|
-- Add new/updated messages at the end
|
||||||
|
SELECT value, 1000000 + ordinality AS ordinality
|
||||||
|
FROM jsonb_array_elements(${newData}::jsonb) WITH ORDINALITY AS t(value, ordinality)
|
||||||
|
) combined),
|
||||||
'[]'::jsonb
|
'[]'::jsonb
|
||||||
)`;
|
)`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue