Build a Solana Agent with persistent memory using PostgreSQL
Create a Solana Agent with persistent memory across sessions using PostgreSQL. This implementation enables the agent to maintain context and remember past interactions, providing a more personalized user experience.
-- schema.sqlCREATE TABLE IF NOT EXISTS memory ( id SERIAL PRIMARY KEY, session_id TEXT NOT NULL, content JSONB NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
// Regular chat without memoryconst agent = new SolanaAgentKit();// First sessionawait agent.chat("I am Arpit");// Response: "Hello Arpit! How can I assist you today?"// New session (no memory)await agent.chat("Do you know my name?");// Response: "I don't know your name yet. If you'd like, you can share it."
// Chat with persistent memoryconst agent = new SolanaAgentKit({ memory: memorySaver});// First sessionawait agent.chat("I am Arpit");// Response: "Hello Arpit! How can I assist you today?"// New session (with memory)await agent.chat("Do you know my name?");// Response: "Yes, you mentioned that your name is Arpit. How can I help you today?"