Skip to content

Commit

Permalink
Merge pull request #940 from bmgalego/process-all-actions
Browse files Browse the repository at this point in the history
feat: process all responses actions
  • Loading branch information
odilitime authored Dec 10, 2024
2 parents bfb471a + 292aba0 commit e8ec603
Showing 1 changed file with 59 additions and 53 deletions.
112 changes: 59 additions & 53 deletions packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,67 +498,73 @@ export class AgentRuntime implements IAgentRuntime {
state?: State,
callback?: HandlerCallback
): Promise<void> {
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);
}
}
}

Expand Down

0 comments on commit e8ec603

Please sign in to comment.