Skip to content

Commit aad3e2e

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
AI: improve document latency insight & reduce verboseness
Fixed: 401232558 Bug: 404834406 Change-Id: Ia49bef486d6486768693f84e3491ac889199664f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6373424 Auto-Submit: Jack Franklin <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Commit-Queue: Jack Franklin <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent 7b0df2e commit aad3e2e

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

front_end/models/ai_assistance/agents/PerformanceInsightsAgent.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const lockedString = i18n.i18n.lockedString;
4242
/* clang-format off */
4343
const preamble = `You are a performance expert deeply integrated within Chrome DevTools. You specialize in analyzing web application behaviour captured by Chrome DevTools Performance Panel.
4444
45-
You will be provided with an Insight from the Chrome Performance Panel. This Insight will contain information about part of the performance of the web site. It is your task to analyze the data available to you and suggest solutions to improve the performance of the page.
45+
You will be provided with an Insight from the Chrome Performance Panel. This Insight will contain information about the performance of the web site. It is your task to analyze the data available to you and suggest solutions to improve the performance of the page.
4646
4747
You will be told the following information about the Insight:
4848
- The 'Insight name' which is the title of the Insight
@@ -53,12 +53,17 @@ You will also be provided with external resources. Use the contents of these res
5353
5454
## Step-by-step instructions
5555
56-
- Think about what the user wants.
5756
- Call any of the available functions to help you gather more information to inform your suggestions.
5857
- Ensure that you call all relevant functions to receive full information about relevant network requests.
59-
- Make suggestions that you are confident will improve the performance of the page.
60-
61-
## General considerations
58+
- Your response should be concise and to the point. Avoid lengthy explanations or unnecessary details.
59+
- Prefer lists of bullet points over long paragraphs of text.
60+
- Your response should be formatted via markdown. If you want to add headings to your response, don’t just mark the text as bold, use markdown’s heading syntax instead.
61+
- Your answer should contain the following sections:
62+
1) Understanding the insight: explain the problems that the Insight is highlighting to the user and why they are important.
63+
2) Suggested fix: A suggestion describing how the user can fix the problem. Keep the suggestion specific to the problem at hand and make no more than 3 suggestions - you should prioritize and pick the top 3 most impactful suggestions.
64+
- Your response should immediately start with the "Understanding the insight" section.
65+
66+
## Critical requirements
6267
6368
- *CRITICAL* never make the same function call twice.
6469
- *CRITICAL* make sure you are thorough and call the functions you have access to to give yourself the most information possible to make accurate recommendations.

front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ The result of the checks for this insight are:
167167
const formatter = new PerformanceInsightFormatter(new ActiveInsight(insight, parsedTrace));
168168
const output = formatter.formatInsight();
169169

170+
const request = insight.data?.documentRequest;
171+
assert.isOk(request);
172+
170173
const expected = `*IMPORTANT*: all time units given to you are in milliseconds.
171174
## Insight title: Document request latency
172175
@@ -183,6 +186,11 @@ This insight checks that the first request is responded to promptly. We use the
183186
The Largest Contentful Paint (LCP) time for this navigation was 3,604.15 ms.
184187
The LCP is text based and was not fetched from the network.
185188
189+
${TraceEventFormatter.networkRequest(request, parsedTrace, {
190+
verbose: true,
191+
customTitle: 'Document network request'
192+
})}
193+
186194
The result of the checks for this insight are:
187195
- The request was not redirected: FAILED
188196
- Server responded quickly: FAILED

front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ ${requestSummary.join('\n\n')}`;
178178
if (!this.#insight.data) {
179179
return '';
180180
}
181-
const {checklist} = this.#insight.data;
181+
const {checklist, documentRequest} = this.#insight.data;
182+
if (!documentRequest) {
183+
return '';
184+
}
182185
const checklistBulletPoints: Array<{name: string, passed: boolean}> = [];
183186
checklistBulletPoints.push({
184187
name: 'The request was not redirected',
@@ -192,8 +195,14 @@ ${requestSummary.join('\n\n')}`;
192195
name: 'Compression was applied',
193196
passed: checklist.usesCompression.value,
194197
});
198+
195199
return `${this.#lcpMetricSharedContext()}
196200
201+
${TraceEventFormatter.networkRequest(documentRequest, this.#parsedTrace, {
202+
verbose: true,
203+
customTitle: 'Document network request'
204+
})}
205+
197206
The result of the checks for this insight are:
198207
${checklistBulletPoints.map(point => `- ${point.name}: ${point.passed ? 'PASSED' : 'FAILED'}`).join('\n')}`;
199208
}
@@ -289,6 +298,7 @@ It is important that all of these checks pass to minimize the delay between the
289298

290299
export interface NetworkRequestFormatOptions {
291300
verbose: boolean;
301+
customTitle?: string;
292302
}
293303

294304
export class TraceEventFormatter {
@@ -306,6 +316,8 @@ export class TraceEventFormatter {
306316
const {url, statusCode, initialPriority, priority, fromServiceWorker, mimeType, responseHeaders, syntheticData} =
307317
request.args.data;
308318

319+
const titlePrefix = `## ${options.customTitle ?? 'Network request'}`;
320+
309321
// Note: unlike other agents, we do have the ability to include
310322
// cross-origins, hence why we do not sanitize the URLs here.
311323
const navigationForEvent = Trace.Helpers.Trace.getNavigationForTraceEvent(
@@ -349,13 +361,13 @@ export class TraceEventFormatter {
349361
});
350362

351363
if (!options.verbose) {
352-
return `## Network request: ${url}
364+
return `${titlePrefix}: ${url}
353365
- Start time: ${formatMicro(startTimesForLifecycle.start)}
354366
- Duration: ${formatMicro(request.dur)}
355367
- MIME type: ${mimeType}${renderBlocking ? '\n- This request was render blocking' : ''}`;
356368
}
357369

358-
return `## Network request: ${url}
370+
return `${titlePrefix}: ${url}
359371
Timings:
360372
- Start time: ${formatMicro(startTimesForLifecycle.start)}
361373
- Queued at: ${formatMicro(startTimesForLifecycle.queueing)}

0 commit comments

Comments
 (0)