Merge pull request #438 from buster-so/dal/retry-agent-logic

log braintrust
This commit is contained in:
dal 2025-07-08 11:03:27 -07:00 committed by GitHub
commit acbed87fc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import { logger, schemaTask, tasks } from '@trigger.dev/sdk';
import { initLogger, wrapTraced } from 'braintrust';
import { currentSpan, initLogger, wrapTraced } from 'braintrust';
import { AnalystAgentTaskInputSchema, type AnalystAgentTaskOutput } from './types';
// Task 2 & 4: Database helpers (IMPLEMENTED)
@ -441,6 +441,17 @@ export const analystAgentTask: ReturnType<
const workflowStartMethodStart = Date.now();
const tracedWorkflow = wrapTraced(
async () => {
currentSpan().log({
metadata: {
userName: braintrustMetadata.userName || 'Unknown',
userId: braintrustMetadata.userId,
organizationName: braintrustMetadata.organizationName || 'Unknown',
organizationId: braintrustMetadata.organizationId,
messageId: braintrustMetadata.messageId,
chatId: braintrustMetadata.chatId,
},
});
return await run.start({
inputData: workflowInput,
runtimeContext,

View File

@ -1,9 +1,9 @@
import postProcessingWorkflow, {
type PostProcessingWorkflowOutput,
} from '@buster/ai/workflows/post-processing-workflow';
import { eq, getDb, messages } from '@buster/database';
import { eq, getBraintrustMetadata, getDb, messages } from '@buster/database';
import { logger, schemaTask } from '@trigger.dev/sdk/v3';
import { initLogger, wrapTraced } from 'braintrust';
import { currentSpan, initLogger, wrapTraced } from 'braintrust';
import { z } from 'zod/v4';
import {
buildWorkflowInput,
@ -155,17 +155,20 @@ export const messagePostProcessingTask: ReturnType<
});
// Step 2: Fetch all required data concurrently
const [conversationMessages, previousPostProcessingResults, datasets] = await Promise.all([
fetchConversationHistory(messageContext.chatId),
fetchPreviousPostProcessingMessages(messageContext.chatId, messageContext.createdAt),
fetchUserDatasets(messageContext.createdBy),
]);
const [conversationMessages, previousPostProcessingResults, datasets, braintrustMetadata] =
await Promise.all([
fetchConversationHistory(messageContext.chatId),
fetchPreviousPostProcessingMessages(messageContext.chatId, messageContext.createdAt),
fetchUserDatasets(messageContext.createdBy),
getBraintrustMetadata({ messageId: payload.messageId }),
]);
logger.log('Fetched required data', {
messageId: payload.messageId,
conversationMessagesCount: conversationMessages.length,
previousPostProcessingCount: previousPostProcessingResults.length,
datasetsCount: datasets.length,
braintrustMetadata, // Log the metadata to verify it's working
});
// Step 3: Build workflow input
@ -191,6 +194,17 @@ export const messagePostProcessingTask: ReturnType<
const tracedWorkflow = wrapTraced(
async () => {
currentSpan().log({
metadata: {
userName: braintrustMetadata.userName || 'Unknown',
userId: braintrustMetadata.userId,
organizationName: braintrustMetadata.organizationName || 'Unknown',
organizationId: braintrustMetadata.organizationId,
messageId: braintrustMetadata.messageId,
chatId: braintrustMetadata.chatId,
},
});
const run = postProcessingWorkflow.createRun();
return await run.start({
inputData: workflowInput,