diff --git a/core/data/log.test.ts b/core/data/log.test.ts index e2471b6bd..a7d664518 100644 --- a/core/data/log.test.ts +++ b/core/data/log.test.ts @@ -18,6 +18,19 @@ const TEST_EVENT: DevDataLogEvent = { provider: "openai", }, }; + +const TEST_AGENT_INTERACTION_EVENT: DevDataLogEvent = { + name: 'chatInteraction', + data: { + prompt: "Hello, world!", + completion: "Hello, world!", + modelProvider: "openai", + modelTitle: "gpt-4", + sessionId: "1234", + tools: ['test-tool1'] + }, +} + const SCHEMA = "0.2.0"; describe("DataLogger", () => { @@ -157,6 +170,23 @@ describe("DataLogger", () => { expect(fileContent).toContain('"model":"gpt-4"'); expect(fileContent).toContain('"eventName":"tokensGenerated"'); }); + + it('should write agent interaction data to local file', async () => { + // Call the method to log data locally + await dataLogger.logLocalData(TEST_AGENT_INTERACTION_EVENT); + + // Verify the file was created + const filepath = getDevDataFilePath(TEST_AGENT_INTERACTION_EVENT.name, SCHEMA); + expect(fs.existsSync(filepath)).toBe(true); + + // Read file contents and verify + const fileContent = fs.readFileSync(filepath, "utf8"); + console.log('debug1 filecontent', fileContent) + expect(fileContent).toContain('"eventName":"chatInteraction"'); + expect(fileContent).toContain('"prompt":"Hello, world!"'); + expect(fileContent).toContain('"completion":"Hello, world!"'); + expect(fileContent).toContain('"tools":["test-tool1"]'); + }) }); describe("logDevData", () => { diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 8776aa1a6..6be602ca0 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -82,6 +82,9 @@ export const streamNormalInput = createAsyncThunk< modelProvider: selectedChatModel.underlyingProviderName, modelTitle: selectedChatModel.title, sessionId: state.session.id, + ...(state.session.mode === 'agent' && { + tools: activeTools.map((tool) => tool.function.name), + }), }, }); } diff --git a/packages/config-yaml/src/schemas/data/chatInteraction/index.ts b/packages/config-yaml/src/schemas/data/chatInteraction/index.ts index fd10fa72c..1afb558b0 100644 --- a/packages/config-yaml/src/schemas/data/chatInteraction/index.ts +++ b/packages/config-yaml/src/schemas/data/chatInteraction/index.ts @@ -7,4 +7,5 @@ export const chatInteractionEventAllSchema = baseDevDataAllSchema.extend({ prompt: z.string(), completion: z.string(), sessionId: z.string(), + tools: z.array(z.string()).optional() }); diff --git a/packages/config-yaml/src/schemas/data/chatInteraction/v0.2.0.ts b/packages/config-yaml/src/schemas/data/chatInteraction/v0.2.0.ts index 206791c22..cb424c9b2 100644 --- a/packages/config-yaml/src/schemas/data/chatInteraction/v0.2.0.ts +++ b/packages/config-yaml/src/schemas/data/chatInteraction/v0.2.0.ts @@ -16,6 +16,7 @@ export const chatInteractionEventSchema_0_2_0 = modelTitle: true, modelProvider: true, sessionId: true, + tools: true }); export const chatInteractionEventSchema_0_2_0_noCode =