From 292aba007358b5ffadeee05f1cf2490c2ddd8e90 Mon Sep 17 00:00:00 2001 From: Galego Date: Mon, 9 Dec 2024 16:18:26 +0000 Subject: [PATCH] process all responses actions --- packages/core/src/runtime.ts | 112 ++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts index 36fde717ee..54d2d8f6b1 100644 --- a/packages/core/src/runtime.ts +++ b/packages/core/src/runtime.ts @@ -498,67 +498,73 @@ export class AgentRuntime implements IAgentRuntime { state?: State, callback?: HandlerCallback ): Promise { - if (!responses[0].content?.action) { - elizaLogger.warn("No action found in the response content."); - return; - } - - const normalizedAction = responses[0].content.action - .toLowerCase() - .replace("_", ""); - - elizaLogger.success(`Normalized action: ${normalizedAction}`); + for (const response of responses) { + if (!response.content?.action) { + elizaLogger.warn("No action found in the response content."); + continue; + } - let action = this.actions.find( - (a: { name: string }) => - a.name - .toLowerCase() - .replace("_", "") - .includes(normalizedAction) || - normalizedAction.includes(a.name.toLowerCase().replace("_", "")) - ); + const normalizedAction = response.content.action + .toLowerCase() + .replace("_", ""); + + elizaLogger.success(`Normalized action: ${normalizedAction}`); + + let action = this.actions.find( + (a: { name: string }) => + a.name + .toLowerCase() + .replace("_", "") + .includes(normalizedAction) || + normalizedAction.includes( + a.name.toLowerCase().replace("_", "") + ) + ); - if (!action) { - elizaLogger.info("Attempting to find action in similes."); - for (const _action of this.actions) { - const simileAction = _action.similes.find( - (simile) => - simile - .toLowerCase() - .replace("_", "") - .includes(normalizedAction) || - normalizedAction.includes( - simile.toLowerCase().replace("_", "") - ) - ); - if (simileAction) { - action = _action; - elizaLogger.success( - `Action found in similes: ${action.name}` + if (!action) { + elizaLogger.info("Attempting to find action in similes."); + for (const _action of this.actions) { + const simileAction = _action.similes.find( + (simile) => + simile + .toLowerCase() + .replace("_", "") + .includes(normalizedAction) || + normalizedAction.includes( + simile.toLowerCase().replace("_", "") + ) ); - break; + if (simileAction) { + action = _action; + elizaLogger.success( + `Action found in similes: ${action.name}` + ); + break; + } } } - } - if (!action) { - elizaLogger.error( - "No action found for", - responses[0].content.action - ); - return; - } + if (!action) { + elizaLogger.error( + "No action found for", + response.content.action + ); + continue; + } - if (!action.handler) { - elizaLogger.error(`Action ${action.name} has no handler.`); - return; - } + if (!action.handler) { + elizaLogger.error(`Action ${action.name} has no handler.`); + continue; + } - try { - elizaLogger.info(`Executing handler for action: ${action.name}`); - await action.handler(this, message, state, {}, callback); - } catch (error) { - elizaLogger.error(error); + try { + elizaLogger.info( + `Executing handler for action: ${action.name}` + ); + await action.handler(this, message, state, {}, callback); + } catch (error) { + elizaLogger.error(error); + } } }