diff --git a/docs/docs/core/actions.md b/docs/docs/core/actions.md index 163a1b2a80..529ff18ea3 100644 --- a/docs/docs/core/actions.md +++ b/docs/docs/core/actions.md @@ -31,6 +31,7 @@ interface Action { examples: ActionExample[][]; handler: Handler; validate: Validator; + suppressInitialMessage?: boolean; } ``` @@ -151,6 +152,7 @@ interface Action { state?: State, ) => Promise; examples: ActionExample[][]; + suppressInitialMessage?: boolean; } ``` @@ -162,6 +164,7 @@ interface Action { - **validate**: Determines if the action can be executed - **handler**: Implements the action's behavior - **examples**: Demonstrates proper usage patterns +- **suppressInitialMessage**: When true, suppresses the initial response message before processing the action. Useful for actions that generate their own responses (like image generation) --- diff --git a/packages/client-direct/src/index.ts b/packages/client-direct/src/index.ts index 11ee361568..e8496517b7 100644 --- a/packages/client-direct/src/index.ts +++ b/packages/client-direct/src/index.ts @@ -222,6 +222,13 @@ export class DirectClient { await runtime.evaluate(memory, state); + // Check if we should suppress the initial message + const action = runtime.actions.find( + (a) => a.name === response.action + ); + const shouldSuppressInitialMessage = + action?.suppressInitialMessage; + const _result = await runtime.processActions( memory, [responseMessage], @@ -232,10 +239,18 @@ export class DirectClient { } ); - if (message) { - res.json([response, message]); + if (!shouldSuppressInitialMessage) { + if (message) { + res.json([response, message]); + } else { + res.json([response]); + } } else { - res.json([response]); + if (message) { + res.json([message]); + } else { + res.json([]); + } } } ); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 5f83e29c66..8e98a8e93e 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -417,6 +417,9 @@ export interface Action { /** Validation function */ validate: Validator; + + /** Whether to suppress the initial message when this action is used */ + suppressInitialMessage?: boolean; } /** diff --git a/packages/plugin-image-generation/src/index.ts b/packages/plugin-image-generation/src/index.ts index 1be67fca92..bf65aacc66 100644 --- a/packages/plugin-image-generation/src/index.ts +++ b/packages/plugin-image-generation/src/index.ts @@ -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);