Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: process all responses actions #940

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading