generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
57 lines (56 loc) • 2.13 kB
JavaScript
import { AgentOutputType, ChatMessageBuilder } from '../agent-core/index.js';
import { AgentFunctionBase } from './utils/index.js';
export class OnGoalFailedFunction extends AgentFunctionBase {
name = 'agent_onGoalFailed';
description = 'Informs the user that the agent could not achieve the goal. Returns an explanation of why the goal could not be achieved';
parameters = {
type: 'object',
properties: {
message: {
type: 'string',
description: 'Explanation of why the goal could not be achieved',
},
},
required: ['message'],
additionalProperties: false,
};
buildExecutor(agent) {
return async (params, rawParams) => {
return new Promise((resolve, reject) => {
try {
resolve(this.onFailure(agent, params, rawParams, params.message));
}
catch (error) {
reject(this.onFailure(agent, params, rawParams, error.toString()));
}
});
};
}
onSuccess(agent, params, rawParams, result) {
return {
outputs: [
{
type: AgentOutputType.Success,
title: `[${agent.config.prompts.name}] ${this.name}`,
content: params.message,
},
],
messages: [ChatMessageBuilder.functionCall(this.name, rawParams), ChatMessageBuilder.functionCallResult(this.name, result)],
};
}
onFailure(agent, params, rawParams, error) {
return {
outputs: [
{
type: AgentOutputType.Error,
title: `[${agent.config.prompts.name}] Error in ${this.name}: ${error}`,
content: params.message,
},
],
messages: [
ChatMessageBuilder.functionCall(this.name, rawParams),
ChatMessageBuilder.functionCallResult(this.name, `Failed calling ${this.name}:\n${error}`),
],
};
}
}