Skip to content

Commit 2e5b3d6

Browse files
authored
Merge pull request elizaOS#1444 from 0xPBIT/supress-initial-message
feat: suppress initial message from action
2 parents 4b8746b + f38ac8e commit 2e5b3d6

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

docs/docs/core/actions.md

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface Action {
3131
examples: ActionExample[][];
3232
handler: Handler;
3333
validate: Validator;
34+
suppressInitialMessage?: boolean;
3435
}
3536
```
3637

@@ -151,6 +152,7 @@ interface Action {
151152
state?: State,
152153
) => Promise<void>;
153154
examples: ActionExample[][];
155+
suppressInitialMessage?: boolean;
154156
}
155157
```
156158

@@ -162,6 +164,7 @@ interface Action {
162164
- **validate**: Determines if the action can be executed
163165
- **handler**: Implements the action's behavior
164166
- **examples**: Demonstrates proper usage patterns
167+
- **suppressInitialMessage**: When true, suppresses the initial response message before processing the action. Useful for actions that generate their own responses (like image generation)
165168

166169
---
167170

packages/client-direct/src/index.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ export class DirectClient {
222222

223223
await runtime.evaluate(memory, state);
224224

225+
// Check if we should suppress the initial message
226+
const action = runtime.actions.find(
227+
(a) => a.name === response.action
228+
);
229+
const shouldSuppressInitialMessage =
230+
action?.suppressInitialMessage;
231+
225232
const _result = await runtime.processActions(
226233
memory,
227234
[responseMessage],
@@ -232,10 +239,18 @@ export class DirectClient {
232239
}
233240
);
234241

235-
if (message) {
236-
res.json([response, message]);
242+
if (!shouldSuppressInitialMessage) {
243+
if (message) {
244+
res.json([response, message]);
245+
} else {
246+
res.json([response]);
247+
}
237248
} else {
238-
res.json([response]);
249+
if (message) {
250+
res.json([message]);
251+
} else {
252+
res.json([]);
253+
}
239254
}
240255
}
241256
);

packages/core/src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ export interface Action {
417417

418418
/** Validation function */
419419
validate: Validator;
420+
421+
/** Whether to suppress the initial message when this action is used */
422+
suppressInitialMessage?: boolean;
420423
}
421424

422425
/**

packages/plugin-image-generation/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const imageGeneration: Action = {
7676
"MAKE_A",
7777
],
7878
description: "Generate an image to go along with the message.",
79+
suppressInitialMessage: true,
7980
validate: async (runtime: IAgentRuntime, _message: Memory) => {
8081
await validateImageGenConfig(runtime);
8182

0 commit comments

Comments
 (0)