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

Conversation

0xPBIT
Copy link

@0xPBIT 0xPBIT commented Dec 25, 2024

Relates to:

feature: Suppressing initial response messages for specific actions in direct client

I would like to also extend the twitter client to include this kind of functionality. Right now there is a lot of assumptions about agent behavior such as sending an initial message before an action is processed. Ideally during the upgrade to v2 some of these hard coded behaviors can be addressed. The design should be more conducive to plugin-defined emergent behavior. Maybe there's a discussion to be had at how we can go about this at a lower level rather than going client-by-client to implement this behavior. I'm still relatively new to Eliza community if anyone has groups or public discussions on this.

Risks

Low - Changes only affect the direct client's message handling logic.

Background

What does this PR do?

Adds support for suppressing initial response messages in the direct client when actions have suppressInitialMessage flag set to true. Some actions might not want to send a message until after the action is completed. Now the action will have to manually send a follow up message with the callback.

What kind of change is this?

Improvements (changes to existing message handling features)

Documentation changes needed?

New property in the Action documentation.

Testing

Where should a reviewer start?

packages/client-direct/src/index.ts - Check the modified message handling logic. I've changed imageGeneration action to include suppressInitialMessage to true for testing.

Detailed testing steps

  1. Create an action with suppressInitialMessage: true
  2. Send a message to the direct client that triggers this action
  3. Verify only the callback message is sent, not the initial response

Key test cases:

  • Action with suppressInitialMessage: true should only send callback message
  • Action with suppressInitialMessage: false or undefined should send both initial and callback messages
  • Action callback functionality should work the same regardless of suppression setting

Code changes:

                // 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],
                    state,
                    async (newMessages) => {
                        message = newMessages;
                        return [memory];
                    }
                );

                if (!shouldSuppressInitialMessage) {
                    if (message) {
                        res.json([response, message]);
                    } else {
                        res.json([response]);
                    }
                } else {
                    if (message) {
                        res.json([message]);
                    } else {
                        res.json([]);
                    }
                }

The changes ensure that when an action has suppressInitialMessage set to true:

  1. The initial response message is not sent in the API response
  2. The action's callback message is still sent if present
  3. The response array only includes the callback message

Copy link
Member

@shakkernerd shakkernerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Much needed!

@shakkernerd shakkernerd merged commit 2e5b3d6 into elizaOS:develop Dec 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants