diff --git a/packages/plugin-save-this/src/index.ts b/packages/plugin-save-this/src/index.ts index 8502321b..f4833441 100644 --- a/packages/plugin-save-this/src/index.ts +++ b/packages/plugin-save-this/src/index.ts @@ -1,4 +1,4 @@ -import { Plugin, AgentRuntime, knowledge, stringToUuid, generateText, settings, Action, elizaLogger, MemoryManager, EvaluationExample } from "@ai16z/eliza"; +import { Plugin, AgentRuntime, knowledge, stringToUuid, generateText, settings, Action, elizaLogger, MemoryManager, EvaluationExample, Content } from "@ai16z/eliza"; import type { KnowledgeItem } from "@ai16z/eliza"; import { @@ -27,7 +27,10 @@ const saveThisAction: Action = { ) => { try { - elizaLogger.info(state.recentMessages); + if (!state) { + elizaLogger.error("[SaveThisAction] handler.start - no state"); + return state; + } // Only proceed if explicitly requested via state if (!state?.shouldSave) { @@ -47,17 +50,6 @@ const saveThisAction: Action = { .map(msg => msg.content.text) .join("\n\n"); - if (callback) { - await callback({ - text: "Summary in progress...", - content: { - text: "Summary in progress..." - } - }, []); - } else { - elizaLogger.error('[SaveThisAction] No callback'); - } - elizaLogger.info("Recent messages:", recentMessagesText); const saveKnowledge = await generateText({ @@ -65,13 +57,14 @@ const saveThisAction: Action = { context: `\ The following messages are from a conversation between an ai agent and a user. The most recent 7 messages are sent to this query, ordered from oldest to newest. Some messages from -the user may be included. The last message is the "save this" request from the user, which is then triggers this query. Realize that conversation history may include agent responses \ -from previous user queries. You should determine by the flow of conversation what -information the user is wanting to save. Prioritize saving the most recent agent response. +the user may be included. The last message is the "save this" request from the user, which is then triggers this query. +Realize that conversation history may include agent responses from previous user queries. +You should determine by the flow of conversation what information the user is wanting to save. +Prioritize saving the most recent agent response. -The user my also append additional words to the "save this" request, which may be relevant in +The user may also append additional words to the "save this" request, which may be relevant in deciding what information for you to save. For example, he/she could say "save this information about cars". -By those words, you can determine what information the wants to focus on. +By those words, you can determine what information the user wants to focus on. Save instructions: Do not store information about the user. Focus on saving knowledge, not conversation history. Don't save what the conversation is about, but rather the facts and details contained in the @@ -96,12 +89,12 @@ ${recentMessagesText}`, await knowledge.set(runtime as AgentRuntime, memoryToSave); + // TODO: callback is undefined. Need to receive callback from Provider. if (callback) { - callback({ -// text: `I've stored this information: "${saveKnowledge}"`, + await callback({ text: `I've stored the information for you`, - }); - return; + type: "text" + }, } } catch (error) { @@ -122,20 +115,29 @@ ${recentMessagesText}`, }; export const saveThisProvider: Provider = { - get: async (runtime: IAgentRuntime, message: Memory, state?: State) => { + get: async (runtime: IAgentRuntime, message: Memory, + state?: State, callback?: HandlerCallback ) => { const text = message.content?.text?.toLowerCase() || ''; // Trigger if message starts with "save this" if (text.trim().startsWith('save this')) { // Modify state in place first -/* if (state) { + if (state) { state.shouldSave = true; } if(!state.shouldSave) { elizaLogger.error('saveThisProvider: state.shouldSave is faised'); } - */ + + //elizaLogger.info(state.recentMessages); + elizaLogger.info("saveThisProvider: state.shouldSave", state.shouldSave); + + // need to figure out how to pass a callback into runtime.processActions + //const mycallback = async (response: Content, files?: Memory[]): Promise => { + // to be implemented + //}; + // Then trigger the SAVE_THIS action await runtime.processActions(message, [{ id: stringToUuid(`save_this_response_${Date.now()}`), @@ -145,8 +147,11 @@ export const saveThisProvider: Provider = { content: { action: 'SAVE_THIS', text: 'Saving previous message...' - } - }]); + }, + + }], state=state, + //callback=mycallback figure out what this should be + ); } return;