mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-27 04:07:05 +00:00
🪢 fix(langfuse): mark provider-backed agent traces (#14833)
* fix(langfuse): mark provider-backed agent traces * fix(langfuse): mark stored response traces * test(langfuse): isolate provider marker setup
This commit is contained in:
parent
d170ecf481
commit
bc6392d05b
5 changed files with 88 additions and 15 deletions
|
|
@ -152,6 +152,10 @@ jest.mock('@librechat/api', () => ({
|
|||
getTransactionsConfig: mockGetTransactionsConfig,
|
||||
recordCollectedUsage: mockRecordCollectedUsage,
|
||||
createSubagentUsageSink: jest.fn().mockReturnValue(jest.fn()),
|
||||
getLangfuseTraceMessageFields: jest.fn().mockResolvedValue({
|
||||
langfuseSampled: true,
|
||||
langfuseDestinationIds: ['destination-1'],
|
||||
}),
|
||||
extractManualSkills: jest.fn().mockReturnValue(undefined),
|
||||
injectSkillPrimes: jest.fn().mockReturnValue({
|
||||
initialMessages: [],
|
||||
|
|
@ -407,6 +411,28 @@ describe('createResponse controller', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('stores Langfuse trace markers with a persisted response', async () => {
|
||||
const api = require('@librechat/api');
|
||||
const { saveMessage } = require('~/models');
|
||||
api.validateResponseRequest.mockReturnValueOnce({
|
||||
request: { ...req.body, store: true },
|
||||
});
|
||||
|
||||
await createResponse(req, res);
|
||||
|
||||
expect(api.getLangfuseTraceMessageFields).toHaveBeenCalledWith(req.config, 'resp_mock-123');
|
||||
expect(saveMessage).toHaveBeenCalledWith(
|
||||
req,
|
||||
expect.objectContaining({
|
||||
messageId: 'resp_mock-123',
|
||||
isCreatedByUser: false,
|
||||
langfuseSampled: true,
|
||||
langfuseDestinationIds: ['destination-1'],
|
||||
}),
|
||||
{ context: 'Responses API - save assistant response' },
|
||||
);
|
||||
});
|
||||
|
||||
describe('execution envelope', () => {
|
||||
it('creates the portable run input before agent initialization', async () => {
|
||||
req.user = {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ const {
|
|||
sendResponsesErrorResponse,
|
||||
createResponsesEventHandlers,
|
||||
createAggregatorEventHandlers,
|
||||
getLangfuseTraceMessageFields,
|
||||
stripActivityLabelParts,
|
||||
} = require('@librechat/api');
|
||||
const {
|
||||
|
|
@ -223,6 +224,8 @@ async function saveResponseOutput(req, conversationId, responseId, response, age
|
|||
}
|
||||
}
|
||||
|
||||
const langfuseTraceFields = await getLangfuseTraceMessageFields(req.config, responseId);
|
||||
|
||||
// Save the assistant message
|
||||
await db.saveMessage(
|
||||
req,
|
||||
|
|
@ -231,6 +234,7 @@ async function saveResponseOutput(req, conversationId, responseId, response, age
|
|||
conversationId,
|
||||
parentMessageId: null,
|
||||
isCreatedByUser: false,
|
||||
...langfuseTraceFields,
|
||||
text: responseText,
|
||||
sender: 'Agent',
|
||||
endpoint: EModelEndpoint.agents,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue