Skip to content

Commit a606a77

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] limit the size of function responses in performance insights
Fixed: 418131186 Change-Id: I2f106a9cff940d8d38d2e024d75d5cc5e03d4b80 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6555742 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
1 parent f19d803 commit a606a77

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

front_end/models/ai_assistance/agents/PerformanceInsightsAgent.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ export class InsightContext extends ConversationContext<TimelineUtils.InsightAIC
203203
}
204204
}
205205

206+
// 16k Tokens * ~4 char per token.
207+
const MAX_FUNCTION_RESULT_BYTE_LENGTH = 16384 * 4;
208+
206209
export class PerformanceInsightsAgent extends AiAgent<TimelineUtils.InsightAIContext.ActiveInsight> {
207210
#insight: ConversationContext<TimelineUtils.InsightAIContext.ActiveInsight>|undefined;
208211

@@ -299,6 +302,12 @@ export class PerformanceInsightsAgent extends AiAgent<TimelineUtils.InsightAICon
299302
);
300303
const formatted =
301304
requests.map(r => TraceEventFormatter.networkRequest(r, activeInsight.parsedTrace, {verbose: false}));
305+
306+
if (this.#isFunctionResponseTooLarge(formatted.join('\n'))) {
307+
return {
308+
error: 'getNetworkActivitySummary response is too large. Try investigating using other functions',
309+
};
310+
}
302311
const summaryFact: Host.AidaClient.RequestFact = {
303312
text:
304313
`This is the network summary for this insight. You can use this and not call getNetworkActivitySummary again:\n${
@@ -346,6 +355,11 @@ export class PerformanceInsightsAgent extends AiAgent<TimelineUtils.InsightAICon
346355
return {error: 'Request not found'};
347356
}
348357
const formatted = TraceEventFormatter.networkRequest(request, activeInsight.parsedTrace, {verbose: true});
358+
if (this.#isFunctionResponseTooLarge(formatted)) {
359+
return {
360+
error: 'getNetworkRequestDetail response is too large. Try investigating using other functions',
361+
};
362+
}
349363
return {result: {request: formatted}};
350364
},
351365
});
@@ -396,6 +410,11 @@ The fields are:
396410
return {error: 'No main thread activity found'};
397411
}
398412
const activity = tree.serialize();
413+
if (this.#isFunctionResponseTooLarge(activity)) {
414+
return {
415+
error: 'getMainThreadActivity response is too large. Try investigating using other functions',
416+
};
417+
}
399418
const activityFact: Host.AidaClient.RequestFact = {
400419
text:
401420
`This is the main thread activity for this insight. You can use this and not call getMainThreadActivity again:\n${
@@ -412,6 +431,10 @@ The fields are:
412431
});
413432
}
414433

434+
#isFunctionResponseTooLarge(response: string): boolean {
435+
return response.length > MAX_FUNCTION_RESULT_BYTE_LENGTH;
436+
}
437+
415438
override parseTextResponse(response: string): ParsedResponse {
416439
/**
417440
* Sometimes the LLM responds with code chunks that wrap a text based markdown response.

0 commit comments

Comments
 (0)