From 2e4791158b5edbb4c8a411fc47b201ea7c11f0ca Mon Sep 17 00:00:00 2001 From: dal Date: Mon, 7 Jul 2025 10:40:11 -0600 Subject: [PATCH] Enhance analyst agent task by integrating message post-processing functionality. Updated logging configuration in integration tests to use environment variable for project name. --- .../analyst-agent-task/analyst-agent-task.ts | 19 +++++++++++++++++-- .../analyst-agent-task.int.test.ts | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/trigger/src/tasks/analyst-agent-task/analyst-agent-task.ts b/apps/trigger/src/tasks/analyst-agent-task/analyst-agent-task.ts index 0c9a796d9..60b89b010 100644 --- a/apps/trigger/src/tasks/analyst-agent-task/analyst-agent-task.ts +++ b/apps/trigger/src/tasks/analyst-agent-task/analyst-agent-task.ts @@ -1,4 +1,4 @@ -import { logger, schemaTask } from '@trigger.dev/sdk'; +import { logger, schemaTask, tasks } from '@trigger.dev/sdk/v3'; import { initLogger, wrapTraced } from 'braintrust'; import { AnalystAgentTaskInputSchema, type AnalystAgentTaskOutput } from './types'; @@ -19,6 +19,8 @@ import { RuntimeContext } from '@mastra/core/runtime-context'; // Database helper output types import type { MessageContextOutput, OrganizationDataSourceOutput } from '@buster/database'; +import type { messagePostProcessingTask } from '../message-post-processing/message-post-processing'; + /** * Task 3: Setup runtime context from Task 2 database helper outputs * Uses individual helper results to populate Mastra RuntimeContext @@ -351,7 +353,7 @@ export const analystAgentTask: ReturnType< dataSourceId: dataSource.dataSourceId, dataSourceSyntax: dataSource.dataSourceSyntax, dashboardFilesCount: dashboardFiles.length, - dashboardFiles: dashboardFiles.map(d => ({ + dashboardFiles: dashboardFiles.map((d) => ({ id: d.id, name: d.name, versionNumber: d.versionNumber, @@ -476,6 +478,19 @@ export const analystAgentTask: ReturnType< }, }); + // Fire off message post-processing task (fire-and-forget) + tasks + .trigger('message-post-processing', { + messageId: payload.message_id, + }) + .catch((error) => { + // Log error but don't fail the current task + logger.error('Failed to trigger message post-processing task', { + messageId: payload.message_id, + error: error instanceof Error ? error.message : 'Unknown error', + }); + }); + // Allow Braintrust a brief moment to clean up its trace, but don't block unnecessarily // Use a much shorter timeout with a race condition to avoid excessive delays await Promise.race([ diff --git a/apps/trigger/tests/integration/analyst-agent-task.int.test.ts b/apps/trigger/tests/integration/analyst-agent-task.int.test.ts index 7a1c2bce7..2a5dbacdf 100644 --- a/apps/trigger/tests/integration/analyst-agent-task.int.test.ts +++ b/apps/trigger/tests/integration/analyst-agent-task.int.test.ts @@ -41,7 +41,7 @@ describe('Analyst Agent Task Integration Tests', () => { // Initialize Braintrust logging for observability initLogger({ apiKey: process.env.BRAINTRUST_KEY, - projectName: 'ANALYST-AGENT-TASK-INTEGRATION', + projectName: process.env.ENVIRONMENT || 'development', }); // Verify required environment variables