Skip to content

Commit 6fc5141

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
[DrJones/Perf] Omit the call tree on followup questions
The model doesn't need it repeated. And we can use the context window space. Bug: 370436840 Change-Id: I4699807fb0877f4cbfd689434d1533ec19fd4cb0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5976667 Commit-Queue: Jack Franklin <[email protected]> Auto-Submit: Paul Irish <[email protected]> Reviewed-by: Jack Franklin <[email protected]>
1 parent fba6c9a commit 6fc5141

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

front_end/panels/freestyler/DrJonesPerformanceAgent.test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ self: 3
165165
},
166166
{
167167
type: ResponseType.QUERYING,
168-
query: `\n${expectedData}\n\n# User request\n\ntest`,
168+
query: `${expectedData}\n\n# User request\n\ntest`,
169169
},
170170
{
171171
type: ResponseType.ANSWER,
@@ -178,7 +178,7 @@ self: 3
178178
assert.deepStrictEqual(agent.chatHistoryForTesting, [
179179
{
180180
entity: 1,
181-
text: `\n${aiCallTree.serialize()}\n\n# User request\n\ntest`,
181+
text: `${aiCallTree.serialize()}\n\n# User request\n\ntest`,
182182
},
183183
{
184184
entity: 2,
@@ -187,4 +187,55 @@ self: 3
187187
]);
188188
});
189189
});
190+
191+
describe('enhanceQuery', () => {
192+
it('does not send the serialized calltree again if it is a followup chat about the same calltree', async () => {
193+
const agent = new DrJonesPerformanceAgent({
194+
aidaClient: {} as Host.AidaClient.AidaClient,
195+
});
196+
197+
const mockAiCallTree = {
198+
serialize: () => 'Mock call tree',
199+
} as unknown as TimelineUtils.AICallTree.AICallTree;
200+
201+
const enhancedQuery1 = await agent.enhanceQuery('What is this?', mockAiCallTree);
202+
assert.strictEqual(enhancedQuery1, 'Mock call tree\n\n# User request\n\nWhat is this?');
203+
204+
// Create history state of the above query
205+
agent.chatNewHistoryForTesting = new Map([[
206+
0,
207+
[
208+
{
209+
type: ResponseType.CONTEXT,
210+
title: 'Analyzing call tree',
211+
details: [
212+
{
213+
title: 'Selected call tree',
214+
text: mockAiCallTree.serialize(),
215+
},
216+
],
217+
},
218+
{
219+
type: ResponseType.QUERYING,
220+
query: enhancedQuery1,
221+
},
222+
{
223+
type: ResponseType.ANSWER,
224+
text: 'test answer',
225+
},
226+
],
227+
]]);
228+
229+
const query2 = 'But what about this follow-up question?';
230+
const enhancedQuery2 = await agent.enhanceQuery(query2, mockAiCallTree);
231+
assert.strictEqual(enhancedQuery2, query2);
232+
assert.isFalse(enhancedQuery2.includes(mockAiCallTree.serialize()));
233+
234+
// Just making sure any subsequent chat doesnt include it either.
235+
const query3 = 'And this 3rd question?';
236+
const enhancedQuery3 = await agent.enhanceQuery(query3, mockAiCallTree);
237+
assert.strictEqual(enhancedQuery3, query3);
238+
assert.isFalse(enhancedQuery3.includes(mockAiCallTree.serialize()));
239+
});
240+
});
190241
});

front_end/panels/freestyler/DrJonesPerformanceAgent.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,20 @@ export class DrJonesPerformanceAgent extends AiAgent<TimelineUtils.AICallTree.AI
159159
override async enhanceQuery(query: string, aiCallTree: TimelineUtils.AICallTree.AICallTree|null): Promise<string> {
160160
const treeStr = aiCallTree?.serialize();
161161

162-
const perfEnhancementQuery = aiCallTree ? `\n${treeStr}\n\n# User request\n\n` : '';
162+
// Collect the queries from previous messages in this session
163+
const prevQueries: string[] = [];
164+
for await (const data of this.runFromHistory()) {
165+
if (data.type === ResponseType.QUERYING) {
166+
prevQueries.push(data.query);
167+
}
168+
}
169+
// If this is a followup chat about the same call tree, don't include the call tree serialization again.
170+
// We don't need to repeat it and we'd rather have more the context window space.
171+
if (prevQueries.length && treeStr && prevQueries.find(q => q.startsWith(treeStr))) {
172+
aiCallTree = null;
173+
}
174+
175+
const perfEnhancementQuery = aiCallTree ? `${treeStr}\n\n# User request\n\n` : '';
163176
return `${perfEnhancementQuery}${query}`;
164177
}
165178

0 commit comments

Comments
 (0)