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: suppress initial message from action #1444

Merged
merged 6 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
48 changes: 37 additions & 11 deletions packages/client-direct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,46 @@ export class DirectClient {

await runtime.evaluate(memory, state);

const _result = await runtime.processActions(
memory,
[responseMessage],
state,
async (newMessages) => {
message = newMessages;
return [memory];
}
// Check if we should suppress the initial message
const action = runtime.actions.find(
(a) => a.name === response.action
);
const shouldSuppressInitialMessage =
action?.suppressInitialMessage;

if (!shouldSuppressInitialMessage) {
const _result = await runtime.processActions(
0xPBIT marked this conversation as resolved.
Show resolved Hide resolved
memory,
[responseMessage],
state,
async (newMessages) => {
message = newMessages;
return [memory];
}
);

if (message) {
res.json([response, message]);
if (message) {
res.json([response, message]);
} else {
res.json([response]);
}
} else {
res.json([response]);
// Only process the action without sending initial response
const _result = await runtime.processActions(
memory,
[responseMessage],
state,
async (newMessages) => {
message = newMessages;
return [memory];
}
);

if (message) {
res.json([message]);
} else {
res.json([]);
}
}
}
);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ export interface Action {

/** Validation function */
validate: Validator;

/** Whether to suppress the initial message when this action is used */
suppressInitialMessage?: boolean;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-image-generation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const imageGeneration: Action = {
"MAKE_A",
],
description: "Generate an image to go along with the message.",
suppressInitialMessage: true,
validate: async (runtime: IAgentRuntime, _message: Memory) => {
await validateImageGenConfig(runtime);

Expand Down
Loading