Skip to content

Commit 1a213b6

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
AI Assistance: remove emulated function calls
Fixed: 436128886 Change-Id: I5ccb6b6f2e506391c5beab4637fe0091038ebeed Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6845982 Reviewed-by: Ergün Erdoğmuş <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent faabead commit 1a213b6

File tree

7 files changed

+479
-1044
lines changed

7 files changed

+479
-1044
lines changed

front_end/models/ai_assistance/ConversationHandler.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ describeWithMockConnection('ConversationHandler', () => {
143143
const conversationHandler = AiAssistanceModel.ConversationHandler.instance({
144144
aidaClient: mockAidaClient([
145145
[{
146-
explanation: `ACTION
147-
$0.style.backgroundColor = 'red'
148-
STOP`,
146+
functionCalls: [{
147+
name: 'executeJavaScript',
148+
args: {code: '$0.style.backgroundColor = \'red\';'},
149+
}],
150+
explanation: '',
149151
}],
150152
]),
151153
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,

front_end/models/ai_assistance/ConversationHandler.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import {FileAgent} from './agents/FileAgent.js';
2424
import {NetworkAgent, RequestContext} from './agents/NetworkAgent.js';
2525
import {PerformanceAgent, PerformanceTraceContext} from './agents/PerformanceAgent.js';
26-
import {NodeContext, StylingAgent, StylingAgentWithFunctionCalling} from './agents/StylingAgent.js';
26+
import {NodeContext, StylingAgent} from './agents/StylingAgent.js';
2727
import {
2828
Conversation,
2929
ConversationType,
@@ -71,10 +71,6 @@ const str_ = i18n.i18n.registerUIStrings('models/ai_assistance/ConversationHandl
7171
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
7272
const lockedString = i18n.i18n.lockedString;
7373

74-
function isAiAssistanceStylingWithFunctionCallingEnabled(): boolean {
75-
return Boolean(Root.Runtime.hostConfig.devToolsFreestyler?.functionCalling);
76-
}
77-
7874
function isAiAssistanceServerSideLoggingEnabled(): boolean {
7975
return !Root.Runtime.hostConfig.aidaAvailability?.disallowLogging;
8076
}
@@ -337,13 +333,6 @@ export class ConversationHandler {
337333
...options,
338334
changeManager,
339335
});
340-
if (isAiAssistanceStylingWithFunctionCallingEnabled()) {
341-
agent = new StylingAgentWithFunctionCalling({
342-
...options,
343-
changeManager,
344-
});
345-
}
346-
347336
break;
348337
}
349338
case ConversationType.NETWORK: {

front_end/models/ai_assistance/agents/AiAgent.ts

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ export interface FunctionDeclaration<Args extends Record<string, unknown>, Retur
243243
}) => Promise<FunctionCallHandlerResult<ReturnType>>;
244244
}
245245

246-
const OBSERVATION_PREFIX = 'OBSERVATION: ';
247-
248246
interface AidaFetchResult {
249247
text?: string;
250248
functionCall?: Host.AidaClient.AidaFunctionCallResponse;
@@ -364,7 +362,7 @@ export abstract class AiAgent<T> {
364362
function validTemperature(temperature: number|undefined): number|undefined {
365363
return typeof temperature === 'number' && temperature >= 0 ? temperature : undefined;
366364
}
367-
const enableAidaFunctionCalling = declarations.length && !this.functionCallEmulationEnabled;
365+
const enableAidaFunctionCalling = declarations.length;
368366
const userTier = Host.AidaClient.convertToUserTierEnum(this.userTier);
369367
const preamble = userTier === Host.AidaClient.UserTier.TESTERS ? this.preamble : undefined;
370368
const facts = Array.from(this.#facts);
@@ -437,20 +435,6 @@ export abstract class AiAgent<T> {
437435
this.#functionDeclarations.clear();
438436
}
439437

440-
protected formatParsedAnswer({answer}: ParsedAnswer): string {
441-
return answer;
442-
}
443-
444-
/**
445-
* Special mode for StylingAgent that turns custom text output into a
446-
* function call.
447-
*/
448-
protected functionCallEmulationEnabled = false;
449-
protected emulateFunctionCall(_aidaResponse: Host.AidaClient.DoConversationResponse):
450-
Host.AidaClient.AidaFunctionCallResponse|'no-function-call'|'wait-for-completion' {
451-
throw new Error('Unexpected emulateFunctionCall. Only StylingAgent implements function call emulation');
452-
}
453-
454438
async *
455439
run(initialQuery: string, options: {
456440
selected: ConversationContext<T>|null,
@@ -537,7 +521,7 @@ export abstract class AiAgent<T> {
537521
}
538522
this.#history.push({
539523
parts: [{
540-
text: this.formatParsedAnswer(parsedResponse),
524+
text: parsedResponse.answer,
541525
}],
542526
role: Host.AidaClient.Role.MODEL,
543527
});
@@ -559,15 +543,13 @@ export abstract class AiAgent<T> {
559543
yield this.#createErrorResponse(ErrorType.ABORT);
560544
break;
561545
}
562-
query = this.functionCallEmulationEnabled ? {text: OBSERVATION_PREFIX + result.result} : {
546+
query = {
563547
functionResponse: {
564548
name: functionCall.name,
565549
response: result,
566550
},
567551
};
568-
request = this.buildRequest(
569-
query,
570-
this.functionCallEmulationEnabled ? Host.AidaClient.Role.USER : Host.AidaClient.Role.ROLE_UNSPECIFIED);
552+
request = this.buildRequest(query, Host.AidaClient.Role.ROLE_UNSPECIFIED);
571553
} catch {
572554
yield this.#createErrorResponse(ErrorType.UNKNOWN);
573555
break;
@@ -591,26 +573,15 @@ export abstract class AiAgent<T> {
591573
if (!call) {
592574
throw new Error(`Function ${name} is not found.`);
593575
}
594-
if (this.functionCallEmulationEnabled) {
595-
if (!call.displayInfoFromArgs) {
596-
throw new Error('functionCallEmulationEnabled requires all functions to provide displayInfoFromArgs');
597-
}
598-
// Emulated function calls are formatted as text.
599-
this.#history.push({
600-
parts: [{text: this.#formatParsedStep(call.displayInfoFromArgs(args))}],
601-
role: Host.AidaClient.Role.MODEL,
602-
});
603-
} else {
604-
this.#history.push({
605-
parts: [{
606-
functionCall: {
607-
name,
608-
args,
609-
},
610-
}],
611-
role: Host.AidaClient.Role.MODEL,
612-
});
613-
}
576+
this.#history.push({
577+
parts: [{
578+
functionCall: {
579+
name,
580+
args,
581+
},
582+
}],
583+
role: Host.AidaClient.Role.MODEL,
584+
});
614585

615586
let code;
616587
if (call.displayInfoFromArgs) {
@@ -723,21 +694,6 @@ export abstract class AiAgent<T> {
723694
break;
724695
}
725696

726-
if (this.functionCallEmulationEnabled) {
727-
const emulatedFunctionCall = this.emulateFunctionCall(aidaResponse);
728-
if (emulatedFunctionCall === 'wait-for-completion') {
729-
continue;
730-
}
731-
if (emulatedFunctionCall !== 'no-function-call') {
732-
yield {
733-
rpcId,
734-
functionCall: emulatedFunctionCall,
735-
completed: true,
736-
};
737-
break;
738-
}
739-
}
740-
741697
rpcId = aidaResponse.metadata.rpcGlobalId ?? rpcId;
742698
yield {
743699
rpcId,
@@ -759,23 +715,6 @@ export abstract class AiAgent<T> {
759715
}
760716
}
761717

762-
#formatParsedStep(step: ParsedStep): string {
763-
let text = '';
764-
if (step.thought) {
765-
text = `THOUGHT: ${step.thought}`;
766-
}
767-
if (step.title) {
768-
text += `\nTITLE: ${step.title}`;
769-
}
770-
if (step.action) {
771-
text += `\nACTION
772-
${step.action}
773-
STOP`;
774-
}
775-
776-
return text;
777-
}
778-
779718
#removeLastRunParts(): void {
780719
this.#history.splice(this.#history.findLastIndex(item => {
781720
return item.role === Host.AidaClient.Role.USER;

0 commit comments

Comments
 (0)