Enhance analyst agent task by integrating message post-processing functionality. Updated logging configuration in integration tests to use environment variable for project name.

This commit is contained in:
dal 2025-07-07 10:40:11 -06:00
parent 51c85c4384
commit 2e4791158b
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 18 additions and 3 deletions

View File

@ -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 { initLogger, wrapTraced } from 'braintrust';
import { AnalystAgentTaskInputSchema, type AnalystAgentTaskOutput } from './types'; import { AnalystAgentTaskInputSchema, type AnalystAgentTaskOutput } from './types';
@ -19,6 +19,8 @@ import { RuntimeContext } from '@mastra/core/runtime-context';
// Database helper output types // Database helper output types
import type { MessageContextOutput, OrganizationDataSourceOutput } from '@buster/database'; 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 * Task 3: Setup runtime context from Task 2 database helper outputs
* Uses individual helper results to populate Mastra RuntimeContext * Uses individual helper results to populate Mastra RuntimeContext
@ -351,7 +353,7 @@ export const analystAgentTask: ReturnType<
dataSourceId: dataSource.dataSourceId, dataSourceId: dataSource.dataSourceId,
dataSourceSyntax: dataSource.dataSourceSyntax, dataSourceSyntax: dataSource.dataSourceSyntax,
dashboardFilesCount: dashboardFiles.length, dashboardFilesCount: dashboardFiles.length,
dashboardFiles: dashboardFiles.map(d => ({ dashboardFiles: dashboardFiles.map((d) => ({
id: d.id, id: d.id,
name: d.name, name: d.name,
versionNumber: d.versionNumber, versionNumber: d.versionNumber,
@ -476,6 +478,19 @@ export const analystAgentTask: ReturnType<
}, },
}); });
// Fire off message post-processing task (fire-and-forget)
tasks
.trigger<typeof messagePostProcessingTask>('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 // 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 // Use a much shorter timeout with a race condition to avoid excessive delays
await Promise.race([ await Promise.race([

View File

@ -41,7 +41,7 @@ describe('Analyst Agent Task Integration Tests', () => {
// Initialize Braintrust logging for observability // Initialize Braintrust logging for observability
initLogger({ initLogger({
apiKey: process.env.BRAINTRUST_KEY, apiKey: process.env.BRAINTRUST_KEY,
projectName: 'ANALYST-AGENT-TASK-INTEGRATION', projectName: process.env.ENVIRONMENT || 'development',
}); });
// Verify required environment variables // Verify required environment variables