From fc243538499a7e715996cfd504795b44a19d330a Mon Sep 17 00:00:00 2001 From: Galego Date: Mon, 9 Dec 2024 16:02:19 +0000 Subject: [PATCH 1/2] add missing callback handler to runtime evaluate method --- packages/core/src/runtime.ts | 35 ++++++++++++++++------------------- packages/core/src/types.ts | 3 ++- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts index 36fde717ee..242f5ad787 100644 --- a/packages/core/src/runtime.ts +++ b/packages/core/src/runtime.ts @@ -569,7 +569,12 @@ export class AgentRuntime implements IAgentRuntime { * @param didRespond Whether the agent responded to the message. * @returns The results of the evaluation. */ - async evaluate(message: Memory, state?: State, didRespond?: boolean) { + async evaluate( + message: Memory, + state?: State, + didRespond?: boolean, + callback?: HandlerCallback + ) { const evaluatorPromises = this.evaluators.map( async (evaluator: Evaluator) => { elizaLogger.log("Evaluating", evaluator.name); @@ -595,17 +600,12 @@ export class AgentRuntime implements IAgentRuntime { return []; } - const evaluators = formatEvaluators(evaluatorsData as Evaluator[]); - const evaluatorNames = formatEvaluatorNames( - evaluatorsData as Evaluator[] - ); - const context = composeContext({ state: { ...state, - evaluators, - evaluatorNames, - } as State, + evaluators: formatEvaluators(evaluatorsData), + evaluatorNames: formatEvaluatorNames(evaluatorsData), + }, template: this.character.templates?.evaluationTemplate || evaluationTemplate, @@ -617,21 +617,18 @@ export class AgentRuntime implements IAgentRuntime { modelClass: ModelClass.SMALL, }); - const parsedResult = parseJsonArrayFromText( + const evaluators = parseJsonArrayFromText( result ) as unknown as string[]; - this.evaluators - .filter((evaluator: Evaluator) => - parsedResult?.includes(evaluator.name) - ) - .forEach((evaluator: Evaluator) => { - if (!evaluator?.handler) return; + for (const evaluator of this.evaluators) { + if (!evaluators.includes(evaluator.name)) continue; - evaluator.handler(this, message); - }); + if (evaluator.handler) + await evaluator.handler(this, message, state, {}, callback); + } - return parsedResult; + return evaluators; } /** diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 9b33376c45..373892c561 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1023,7 +1023,8 @@ export interface IAgentRuntime { evaluate( message: Memory, state?: State, - didRespond?: boolean + didRespond?: boolean, + callback?: HandlerCallback ): Promise; ensureParticipantExists(userId: UUID, roomId: UUID): Promise; From f0f1f00bf4ef264b732acf4427d7d93a7eec0263 Mon Sep 17 00:00:00 2001 From: Galego Date: Tue, 10 Dec 2024 19:28:24 +0000 Subject: [PATCH 2/2] fix jsdoc --- packages/core/src/runtime.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts index 242f5ad787..0283c9a822 100644 --- a/packages/core/src/runtime.ts +++ b/packages/core/src/runtime.ts @@ -566,7 +566,8 @@ export class AgentRuntime implements IAgentRuntime { * Evaluate the message and state using the registered evaluators. * @param message The message to evaluate. * @param state The state of the agent. - * @param didRespond Whether the agent responded to the message. + * @param didRespond Whether the agent responded to the message.~ + * @param callback The handler callback * @returns The results of the evaluation. */ async evaluate(