Skip to content

Commit af08e46

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Combine insight and call tree Performance agents
Instead of having two agents for different Ask AI behaviors on a trace, there is now just one. Capabilities / constraints on the conversation are configured based on the agent's context: TimelineUtils.AIContext.AgentFocus. This should not change the behavior of any existing "Ask AI" feature in the Performance panel. Having a single agent lays the groundwork for supporting the MCP use- case, which needs access to the entire trace (unlike our existing Ask AI features) and requires much the same functionality. Bug: 425269729 Change-Id: I402f76b1f5c96817e0a708261650c19932c2e6bf Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6761976 Reviewed-by: Jack Franklin <[email protected]> Commit-Queue: Connor Clark <[email protected]>
1 parent 2652463 commit af08e46

25 files changed

+1295
-1246
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ grd_files_unbundled_sources = [
999999
"front_end/models/ai_assistance/agents/PatchAgent.js",
10001000
"front_end/models/ai_assistance/agents/PerformanceAgent.js",
10011001
"front_end/models/ai_assistance/agents/PerformanceAnnotationsAgent.js",
1002-
"front_end/models/ai_assistance/agents/PerformanceInsightsAgent.js",
10031002
"front_end/models/ai_assistance/agents/StylingAgent.js",
10041003
"front_end/models/ai_assistance/data_formatters/FileFormatter.js",
10051004
"front_end/models/ai_assistance/data_formatters/NetworkRequestFormatter.js",
@@ -1998,6 +1997,7 @@ grd_files_unbundled_sources = [
19981997
"front_end/panels/timeline/timelineStatusDialog.css.js",
19991998
"front_end/panels/timeline/timelineTreeView.css.js",
20001999
"front_end/panels/timeline/utils/AICallTree.js",
2000+
"front_end/panels/timeline/utils/AIContext.js",
20012001
"front_end/panels/timeline/utils/EntityMapper.js",
20022002
"front_end/panels/timeline/utils/EntryName.js",
20032003
"front_end/panels/timeline/utils/EntryNodes.js",

front_end/models/ai_assistance/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ devtools_module("ai_assistance") {
2121
"agents/PatchAgent.ts",
2222
"agents/PerformanceAgent.ts",
2323
"agents/PerformanceAnnotationsAgent.ts",
24-
"agents/PerformanceInsightsAgent.ts",
2524
"agents/StylingAgent.ts",
2625
"data_formatters/FileFormatter.ts",
2726
"data_formatters/NetworkRequestFormatter.ts",
@@ -81,7 +80,6 @@ ts_library("unittests") {
8180
"agents/PatchAgent.test.ts",
8281
"agents/PerformanceAgent.test.ts",
8382
"agents/PerformanceAnnotationsAgent.test.ts",
84-
"agents/PerformanceInsightsAgent.test.ts",
8583
"agents/StylingAgent.test.ts",
8684
"data_formatters/FileFormatter.test.ts",
8785
"data_formatters/NetworkRequestFormatter.test.ts",

front_end/models/ai_assistance/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When the user interacts with AI via the AI Assistance Panel, they are having a _
88

99
Each agent has a _context_ defined, which represents the selected data that forms the context of the conversation the user is having with that agent. For example:
1010

11-
- The `PerformanceInsightsAgent` has an individual performance insight as its context.
11+
- The `PerformanceAgent` has an individual performance trace and a specific focus (an insight, or a call tree) as its context.
1212
- The `StylingAgent` has a DOM Node as its context.
1313

1414
When defining a context, they must extend the `ConversationContext` interface, which defines a few methods which must be implemented, including:
@@ -24,6 +24,10 @@ To deal with the work to take an object that is the AI agent's context and turn
2424

2525
## Performance specific documentation
2626

27+
### `TimelineUtils.AIContext.AgentFocus`
28+
29+
The context for `PerformanceAgent` is `AgentFocus`, which supports different behavior for different entry-points of the "Ask AI" feature for a trace. The two entry-points now are "insight" and "call-tree". The agent modifies its capabilities based on this focus.
30+
2731
### Adding "Ask AI" to a new Insight
2832

2933
The process for adding "Ask AI" support to a new insight is mostly limited to updating the `PerformanceInsightFormatter` to support the new insight. There are a few methods with `switch` statements that will need updating:
@@ -34,19 +38,13 @@ The process for adding "Ask AI" support to a new insight is mostly limited to up
3438

3539
Once you've done that, you will need to update the UI component to tell it that it can render the "Ask AI" button. To do this, override the `hasAskAiSupport()` method in the component and return `true`.
3640

37-
### `InsightAIContext` and time bounds for insights
38-
39-
The `PerformanceInsightsAgent` has the ability to make function calls to be informed about network and main thread activity. When this happens we determine the time bounds that are relevant for the selected Insight. For example, for any LCP based Insights we limit the time frame to be:
40-
41-
- **Start time**: navigation start or trace start
42-
- **End time**: the LCP timestamp
41+
### Time bounds for insights
4342

44-
For all other Insights, we use:
43+
The `PerformanceAgent` has the ability to make function calls to be informed about network and main thread activity. When this happens we determine the time bounds that are relevant for the selected insight.
4544

46-
- **Start time**: navigation start or trace start
47-
- **End time**: the next navigation start or the trace end
45+
In general, the trace bounds are defined by the insight's overlays. If there are none, we use the insight set's navigation bounds.
4846

49-
You can override this if you need to; see the `insightBounds` function in `InsightAIContext.ts`.
47+
See the `insightBounds` function in `InsightAIContext.ts`.
5048

5149

5250
### Testing the new Insight

front_end/models/ai_assistance/agents/AiAgent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ export abstract class AiAgent<T> {
408408
this.#functionDeclarations.set(name, declaration as FunctionDeclaration<Record<string, unknown>, ReturnType>);
409409
}
410410

411+
protected clearDeclaredFunctions(): void {
412+
this.#functionDeclarations.clear();
413+
}
414+
411415
protected formatParsedAnswer({answer}: ParsedAnswer): string {
412416
return answer;
413417
}

0 commit comments

Comments
 (0)