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 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
3 changes: 3 additions & 0 deletions docs/docs/core/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Action {
examples: ActionExample[][];
handler: Handler;
validate: Validator;
suppressInitialMessage?: boolean;
}
```

Expand Down Expand Up @@ -151,6 +152,7 @@ interface Action {
state?: State,
) => Promise<void>;
examples: ActionExample[][];
suppressInitialMessage?: boolean;
}
```

Expand All @@ -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)

---

Expand Down
21 changes: 18 additions & 3 deletions packages/client-direct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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([]);
}
}
}
);
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