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

getRecentPostInteractions returning all memory #2253

Closed
rferrari opened this issue Jan 13, 2025 · 5 comments · Fixed by #2264
Closed

getRecentPostInteractions returning all memory #2253

rferrari opened this issue Jan 13, 2025 · 5 comments · Fixed by #2264
Labels
enhancement New feature or request

Comments

@rferrari
Copy link
Contributor

rferrari commented Jan 13, 2025

Is your feature request related to a problem? Please describe.

I`m not sure if this is a BUG or intent, but looks like runtime.ts getRecentPostInteractions return all memory. It was overloading my model with more than 20k tokens each time it try to create a new post.

So, it stopped creating new posts due Model Rate Limits per minute.

Describe the solution you'd like

A workarround i found so far, was to limit the getRecentPostInteractions with a setting like this:

const getRecentPostInteractions = async (
            recentInteractionsData: Memory[],
            actors: Actor[]
        ): Promise<string> => {
            const limit = this.character.settings?.recentInteractionsLimit ?? 20;  // Included limit here
            const limitedInteractions = recentInteractionsData.slice(-limit);
            const formattedInteractions = formatPosts({
                messages: recentInteractionsData,
                actors,
                conversationHeader: true,
            });

            return formattedInteractions;
        };

Describe alternatives you've considered

Im not sure if is the best solution as im still learning Eliza Framework. Maybe a more experience dev can check on that.

Additional context

@rferrari rferrari added the enhancement New feature or request label Jan 13, 2025
Copy link
Contributor

Hello @rferrari! Welcome to the elizaOS community. Thank you for opening your first issue; we appreciate your contribution. You are now an elizaOS contributor!

@augchan42
Copy link
Contributor

In theory the recent interactions should already be limited to the 20 latest here:

const getRecentInteractions = async (
            userA: UUID,
            userB: UUID
        ): Promise<Memory[]> => {
            // Find all rooms where userA and userB are participants
            const rooms = await this.databaseAdapter.getRoomsForParticipants([
                userA,
                userB,
            ]);

            // Check the existing memories in the database
            const existingMemories =
                await this.messageManager.getMemoriesByRoomIds({
                    // filter out the current room id from rooms
                    roomIds: rooms.filter((room) => room !== roomId),
                });

            // Sort messages by timestamp in descending order
            existingMemories.sort(
                (a, b) =>
                    (b?.createdAt ?? Date.now()) - (a?.createdAt ?? Date.now())
            );

            // Take the most recent messages
            const recentInteractionsData = existingMemories.slice(0, 20);
            return recentInteractionsData;
        };

This is whats passed to getRecentPostInteractions. So not sure why everything is getting passed. I do remember seeing rate limits as well, but I also had other code changes so not sure if it's the same underlying issue.

@augchan42
Copy link
Contributor

there's an inefficiency in memory retrieval, so will fix this issue at the same time

@augchan42
Copy link
Contributor

@rferrari what database are you using? it seems the limit parameter is being lost between layers, as the type definition has it, but the underlying database adapter doesn't. At least for sqlite and likely many others.

@shakkernerd
Copy link
Member

shakkernerd commented Jan 14, 2025

@rferrari Yes, the limit implementation was missing in the sqlite adapter and some other db adapters, #2264 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants