From 971c4de33e1a3f117eafe9d64bf175c0d2a849ef Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 23 May 2025 11:27:15 +0530 Subject: [PATCH 1/4] feat: add agentinteraction dev data --- gui/src/redux/thunks/streamNormalInput.ts | 2 +- packages/config-yaml/src/schemas/data/index.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 43e431271..a4ce0007d 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -75,7 +75,7 @@ export const streamNormalInput = createAsyncThunk< try { if (state.session.mode === "chat" || state.session.mode === "agent") { extra.ideMessenger.post("devdata/log", { - name: "chatInteraction", + name: state.session.mode === 'chat' ? "chatInteraction" : "agentInteraction", data: { prompt: next.value.prompt, completion: next.value.completion, diff --git a/packages/config-yaml/src/schemas/data/index.ts b/packages/config-yaml/src/schemas/data/index.ts index 7251e12a7..1d8b59547 100644 --- a/packages/config-yaml/src/schemas/data/index.ts +++ b/packages/config-yaml/src/schemas/data/index.ts @@ -72,6 +72,7 @@ const devEventAllVersionDataSchemas = z.object({ tokensGenerated: tokensGeneratedEventAllSchema, chatInteraction: chatInteractionEventAllSchema, editInteraction: editInteractionEventAllSchema, + agentInteraction: chatInteractionEventAllSchema }); // Version and level specific schemas are organized here @@ -97,6 +98,7 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0, chatInteraction: chatInteractionEventSchema_0_2_0, editInteraction: editInteractionEventSchema_0_2_0, + agentInteraction: chatInteractionEventSchema_0_2_0, }, noCode: { autocomplete: autocompleteEventSchema_0_2_0_noCode, @@ -104,6 +106,7 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode, chatInteraction: chatInteractionEventSchema_0_2_0_noCode, editInteraction: editInteractionEventSchema_0_2_0_noCode, + agentInteraction: chatInteractionEventSchema_0_2_0_noCode, }, }, }; From f09ada8d897b201baed917a048a1b2af9d5850b1 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 23 May 2025 11:40:09 +0530 Subject: [PATCH 2/4] added tests --- core/data/log.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/data/log.test.ts b/core/data/log.test.ts index e2471b6bd..5e9bcce5f 100644 --- a/core/data/log.test.ts +++ b/core/data/log.test.ts @@ -18,6 +18,18 @@ const TEST_EVENT: DevDataLogEvent = { provider: "openai", }, }; + +const TEST_AGENT_INTERACTION_EVENT: DevDataLogEvent = { + name: 'agentInteraction', + data: { + prompt: "Hello, world!", + completion: "Hello, world!", + modelProvider: "openai", + modelTitle: "gpt-4", + sessionId: "1234", + }, +} + const SCHEMA = "0.2.0"; describe("DataLogger", () => { @@ -157,6 +169,21 @@ 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"); + expect(fileContent).toContain('"eventName":"agentInteraction"'); + expect(fileContent).toContain('"prompt":"Hello, world!"'); + expect(fileContent).toContain('"completion":"Hello, world!"'); + }) }); describe("logDevData", () => { From cdfc1ff54211a2eeb872a1a09fc98de2a40a4043 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Mon, 26 May 2025 18:33:14 +0530 Subject: [PATCH 3/4] add `tools` key in chatInteraction --- core/data/log.test.ts | 7 +++++-- gui/src/redux/thunks/streamNormalInput.ts | 6 +++++- .../config-yaml/src/schemas/data/chatInteraction/index.ts | 1 + .../config-yaml/src/schemas/data/chatInteraction/v0.2.0.ts | 1 + packages/config-yaml/src/schemas/data/index.ts | 3 --- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/data/log.test.ts b/core/data/log.test.ts index 5e9bcce5f..a7d664518 100644 --- a/core/data/log.test.ts +++ b/core/data/log.test.ts @@ -20,13 +20,14 @@ const TEST_EVENT: DevDataLogEvent = { }; const TEST_AGENT_INTERACTION_EVENT: DevDataLogEvent = { - name: 'agentInteraction', + name: 'chatInteraction', data: { prompt: "Hello, world!", completion: "Hello, world!", modelProvider: "openai", modelTitle: "gpt-4", sessionId: "1234", + tools: ['test-tool1'] }, } @@ -180,9 +181,11 @@ describe("DataLogger", () => { // Read file contents and verify const fileContent = fs.readFileSync(filepath, "utf8"); - expect(fileContent).toContain('"eventName":"agentInteraction"'); + 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"]'); }) }); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index ec12627c0..b7e39490e 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -36,6 +36,7 @@ export const streamNormalInput = createAsyncThunk< throw new Error("Default model not defined"); } + const isInEdit = state.session.isInEdit; let completionOptions: LLMFullCompletionOptions = {}; const activeTools = selectActiveTools(state); const toolsSupported = modelSupportsTools(selectedChatModel); @@ -75,13 +76,16 @@ export const streamNormalInput = createAsyncThunk< try { if (state.session.mode === "chat" || state.session.mode === "agent") { extra.ideMessenger.post("devdata/log", { - name: state.session.mode === 'chat' ? "chatInteraction" : "agentInteraction", + name: "chatInteraction", data: { prompt: next.value.prompt, completion: next.value.completion, modelProvider: selectedChatModel.underlyingProviderName, modelTitle: selectedChatModel.title, sessionId: state.session.id, + ...(isInEdit && { + 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 = diff --git a/packages/config-yaml/src/schemas/data/index.ts b/packages/config-yaml/src/schemas/data/index.ts index 1d8b59547..7251e12a7 100644 --- a/packages/config-yaml/src/schemas/data/index.ts +++ b/packages/config-yaml/src/schemas/data/index.ts @@ -72,7 +72,6 @@ const devEventAllVersionDataSchemas = z.object({ tokensGenerated: tokensGeneratedEventAllSchema, chatInteraction: chatInteractionEventAllSchema, editInteraction: editInteractionEventAllSchema, - agentInteraction: chatInteractionEventAllSchema }); // Version and level specific schemas are organized here @@ -98,7 +97,6 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0, chatInteraction: chatInteractionEventSchema_0_2_0, editInteraction: editInteractionEventSchema_0_2_0, - agentInteraction: chatInteractionEventSchema_0_2_0, }, noCode: { autocomplete: autocompleteEventSchema_0_2_0_noCode, @@ -106,7 +104,6 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode, chatInteraction: chatInteractionEventSchema_0_2_0_noCode, editInteraction: editInteractionEventSchema_0_2_0_noCode, - agentInteraction: chatInteractionEventSchema_0_2_0_noCode, }, }, }; From 04109e62d144b80d7b0b719c48e83445787b4b7a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Mon, 26 May 2025 18:42:36 +0530 Subject: [PATCH 4/4] correction --- gui/src/redux/thunks/streamNormalInput.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index b7e39490e..6be602ca0 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -36,7 +36,6 @@ export const streamNormalInput = createAsyncThunk< throw new Error("Default model not defined"); } - const isInEdit = state.session.isInEdit; let completionOptions: LLMFullCompletionOptions = {}; const activeTools = selectActiveTools(state); const toolsSupported = modelSupportsTools(selectedChatModel); @@ -83,7 +82,7 @@ export const streamNormalInput = createAsyncThunk< modelProvider: selectedChatModel.underlyingProviderName, modelTitle: selectedChatModel.title, sessionId: state.session.id, - ...(isInEdit && { + ...(state.session.mode === 'agent' && { tools: activeTools.map((tool) => tool.function.name), }), },