mirror of https://github.com/buster-so/buster.git
Merge pull request #438 from buster-so/dal/retry-agent-logic
log braintrust
This commit is contained in:
commit
acbed87fc2
|
@ -1,5 +1,5 @@
|
||||||
import { logger, schemaTask, tasks } from '@trigger.dev/sdk';
|
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';
|
import { AnalystAgentTaskInputSchema, type AnalystAgentTaskOutput } from './types';
|
||||||
|
|
||||||
// Task 2 & 4: Database helpers (IMPLEMENTED)
|
// Task 2 & 4: Database helpers (IMPLEMENTED)
|
||||||
|
@ -441,6 +441,17 @@ export const analystAgentTask: ReturnType<
|
||||||
const workflowStartMethodStart = Date.now();
|
const workflowStartMethodStart = Date.now();
|
||||||
const tracedWorkflow = wrapTraced(
|
const tracedWorkflow = wrapTraced(
|
||||||
async () => {
|
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({
|
return await run.start({
|
||||||
inputData: workflowInput,
|
inputData: workflowInput,
|
||||||
runtimeContext,
|
runtimeContext,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import postProcessingWorkflow, {
|
import postProcessingWorkflow, {
|
||||||
type PostProcessingWorkflowOutput,
|
type PostProcessingWorkflowOutput,
|
||||||
} from '@buster/ai/workflows/post-processing-workflow';
|
} 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 { logger, schemaTask } from '@trigger.dev/sdk/v3';
|
||||||
import { initLogger, wrapTraced } from 'braintrust';
|
import { currentSpan, initLogger, wrapTraced } from 'braintrust';
|
||||||
import { z } from 'zod/v4';
|
import { z } from 'zod/v4';
|
||||||
import {
|
import {
|
||||||
buildWorkflowInput,
|
buildWorkflowInput,
|
||||||
|
@ -155,17 +155,20 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 2: Fetch all required data concurrently
|
// Step 2: Fetch all required data concurrently
|
||||||
const [conversationMessages, previousPostProcessingResults, datasets] = await Promise.all([
|
const [conversationMessages, previousPostProcessingResults, datasets, braintrustMetadata] =
|
||||||
fetchConversationHistory(messageContext.chatId),
|
await Promise.all([
|
||||||
fetchPreviousPostProcessingMessages(messageContext.chatId, messageContext.createdAt),
|
fetchConversationHistory(messageContext.chatId),
|
||||||
fetchUserDatasets(messageContext.createdBy),
|
fetchPreviousPostProcessingMessages(messageContext.chatId, messageContext.createdAt),
|
||||||
]);
|
fetchUserDatasets(messageContext.createdBy),
|
||||||
|
getBraintrustMetadata({ messageId: payload.messageId }),
|
||||||
|
]);
|
||||||
|
|
||||||
logger.log('Fetched required data', {
|
logger.log('Fetched required data', {
|
||||||
messageId: payload.messageId,
|
messageId: payload.messageId,
|
||||||
conversationMessagesCount: conversationMessages.length,
|
conversationMessagesCount: conversationMessages.length,
|
||||||
previousPostProcessingCount: previousPostProcessingResults.length,
|
previousPostProcessingCount: previousPostProcessingResults.length,
|
||||||
datasetsCount: datasets.length,
|
datasetsCount: datasets.length,
|
||||||
|
braintrustMetadata, // Log the metadata to verify it's working
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 3: Build workflow input
|
// Step 3: Build workflow input
|
||||||
|
@ -191,6 +194,17 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
|
|
||||||
const tracedWorkflow = wrapTraced(
|
const tracedWorkflow = wrapTraced(
|
||||||
async () => {
|
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();
|
const run = postProcessingWorkflow.createRun();
|
||||||
return await run.start({
|
return await run.start({
|
||||||
inputData: workflowInput,
|
inputData: workflowInput,
|
||||||
|
|
Loading…
Reference in New Issue